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