|
|
|
@ -251,23 +251,24 @@ pub async fn gh_auth(
|
|
|
|
|
|
|
|
|
|
//dbg!(&emails);
|
|
|
|
|
|
|
|
|
|
for email in emails { |
|
|
|
|
if let Some(name) = email |
|
|
|
|
.email |
|
|
|
|
.strip_suffix("@mails.tsinghua.edu.cn") |
|
|
|
|
.and_then(|name| email.verified.then_some(name)) |
|
|
|
|
{ |
|
|
|
|
let tk = User::find_or_create_token( |
|
|
|
|
&db, |
|
|
|
|
&rh.hash_with_salt(&format!("email_{}", name)), |
|
|
|
|
false, |
|
|
|
|
) |
|
|
|
|
.await |
|
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
return Ok(Redirect::to(format!("{}?token={}", &jump_to_url, &tk))); |
|
|
|
|
} |
|
|
|
|
let name = emails |
|
|
|
|
.iter() |
|
|
|
|
.filter(|email| email.verified) |
|
|
|
|
.find_map( |
|
|
|
|
|email| match email.email.split('@').collect::<Vec<&str>>()[..] { |
|
|
|
|
[name, "mails.tsinghua.edu.cn"] | [name, "tsinghua.org.cn"] => Some(name), |
|
|
|
|
_ => None, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if let Some(name) = name { |
|
|
|
|
let tk = |
|
|
|
|
User::find_or_create_token(&db, &rh.hash_with_salt(&format!("email_{}", name)), false) |
|
|
|
|
.await |
|
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
Ok(Redirect::to(format!("{}?token={}", &jump_to_url, &tk))) |
|
|
|
|
} else { |
|
|
|
|
Err("没有找到已验证的清华邮箱/校友邮箱") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Err("没有找到已验证的清华邮箱") |
|
|
|
|
} |
|
|
|
|