Automatically display first factor input form if there is only one
This commit is contained in:
parent
867021e01a
commit
68cb630339
@ -233,6 +233,8 @@ pub async fn reset_password_route(id: Identity, query: web::Query<PasswordResetQ
|
|||||||
pub struct ChooseSecondFactorQuery {
|
pub struct ChooseSecondFactorQuery {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
redirect: LoginRedirect,
|
redirect: LoginRedirect,
|
||||||
|
#[serde(default = "bool::default")]
|
||||||
|
force_display: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Let the user select the factor to use to authenticate
|
/// 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()))
|
let user: User = users.send(users_actor::GetUserRequest(SessionIdentity(&id).user_id()))
|
||||||
.await.unwrap().0.expect("Could not find user!");
|
.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(
|
HttpResponse::Ok().content_type("text/html").body(
|
||||||
ChooseSecondFactorTemplate {
|
ChooseSecondFactorTemplate {
|
||||||
_p: BaseLoginPage {
|
_p: BaseLoginPage {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
padding-left: 0px;
|
padding-left: 0px;
|
||||||
padding-right: 0px;
|
padding-right: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@ -27,7 +28,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<div style="margin-top: 10px;">
|
<div style="margin-top: 10px;">
|
||||||
<a href="/2fa_auth?redirect={{ _p.redirect_uri.get_encoded() }}">Sign in using another factor</a><br/>
|
<a href="/2fa_auth?force_display=true&redirect={{ _p.redirect_uri.get_encoded() }}">Sign in using another factor</a><br/>
|
||||||
<a href="/logout">Sign out</a>
|
<a href="/logout">Sign out</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user