Refactor code
This commit is contained in:
@ -132,17 +132,16 @@ pub async fn login_route(
|
||||
|
||||
match response {
|
||||
LoginResult::Success(user) => {
|
||||
SessionIdentity(id.as_ref()).set_user(&http_req, &user);
|
||||
|
||||
return if user.need_reset_password {
|
||||
SessionIdentity(id.as_ref()).set_status(&http_req, SessionStatus::NeedNewPassword);
|
||||
redirect_user(&format!("/reset_password?redirect={}", query.redirect.get_encoded()))
|
||||
let status = if user.need_reset_password {
|
||||
SessionStatus::NeedNewPassword
|
||||
} else if user.has_two_factor() {
|
||||
SessionIdentity(id.as_ref()).set_status(&http_req, SessionStatus::Need2FA);
|
||||
redirect_user(&format!("/2fa_auth?redirect={}", query.redirect.get_encoded()))
|
||||
SessionStatus::Need2FA
|
||||
} else {
|
||||
redirect_user(query.redirect.get())
|
||||
SessionStatus::SignedIn
|
||||
};
|
||||
|
||||
SessionIdentity(id.as_ref()).set_user(&http_req, &user, status);
|
||||
redirect_user(query.redirect.get());
|
||||
}
|
||||
|
||||
LoginResult::AccountDisabled => {
|
||||
@ -262,6 +261,7 @@ pub async fn choose_2fa_method(id: Option<Identity>, query: web::Query<ChooseSec
|
||||
|
||||
// Automatically choose factor if there is only one factor
|
||||
if user.two_factor.len() == 1 && !query.force_display {
|
||||
log::trace!("User has only one factor, using it by default");
|
||||
return redirect_user(&user.two_factor[0].login_url(&query.redirect));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user