Automatically display first factor input form if there is only one

This commit is contained in:
2022-04-20 12:06:56 +02:00
parent 867021e01a
commit 68cb630339
2 changed files with 10 additions and 2 deletions

View File

@ -233,6 +233,8 @@ pub async fn reset_password_route(id: Identity, query: web::Query<PasswordResetQ
pub struct ChooseSecondFactorQuery {
#[serde(default)]
redirect: LoginRedirect,
#[serde(default = "bool::default")]
force_display: bool,
}
/// Let the user select the factor to use to authenticate
@ -245,6 +247,11 @@ pub async fn choose_2fa_method(id: Identity, query: web::Query<ChooseSecondFacto
let user: User = users.send(users_actor::GetUserRequest(SessionIdentity(&id).user_id()))
.await.unwrap().0.expect("Could not find user!");
// Automatically choose factor if there is only one factor
if user.two_factor.len() == 1 && !query.force_display {
return redirect_user(&user.two_factor[0].login_url(&query.redirect));
}
HttpResponse::Ok().content_type("text/html").body(
ChooseSecondFactorTemplate {
_p: BaseLoginPage {