Make usage of FatalErrorPage more convenient

This commit is contained in:
2022-04-23 20:31:09 +02:00
parent a516f173ad
commit 48112dfed7
5 changed files with 23 additions and 30 deletions

View File

@ -7,7 +7,7 @@ use crate::actors::{bruteforce_actor, users_actor};
use crate::actors::bruteforce_actor::BruteForceActor;
use crate::actors::users_actor::{ChangePasswordResult, LoginResult, UsersActor};
use crate::constants::{APP_NAME, MAX_FAILED_LOGIN_ATTEMPTS, MIN_PASS_LEN};
use crate::controllers::base_controller::{FatalErrorPage, redirect_user, redirect_user_for_login};
use crate::controllers::base_controller::{build_fatal_error_page, redirect_user, redirect_user_for_login};
use crate::data::login_redirect::LoginRedirect;
use crate::data::remote_ip::RemoteIP;
use crate::data::session_identity::{SessionIdentity, SessionStatus};
@ -91,9 +91,7 @@ pub async fn login_route(
if failed_attempts > MAX_FAILED_LOGIN_ATTEMPTS {
return HttpResponse::TooManyRequests().body(
FatalErrorPage {
message: "Too many failed login attempts, please try again later!"
}.render().unwrap()
build_fatal_error_page("Too many failed login attempts, please try again later!")
);
}
@ -306,15 +304,13 @@ pub async fn login_with_otp(id: Identity, query: web::Query<LoginWithOTPQuery>,
let factor = match user.find_factor(&query.id) {
Some(f) => f,
None => return HttpResponse::Ok()
.body(FatalErrorPage { message: "Factor not found!" }.render().unwrap())
None => return HttpResponse::Ok().body(build_fatal_error_page("Factor not found!"))
};
let key = match &factor.kind {
TwoFactorType::TOTP(key) => key,
_ => {
return HttpResponse::Ok()
.body(FatalErrorPage { message: "Factor is not a TOTP key!" }.render().unwrap());
return HttpResponse::Ok().body(build_fatal_error_page("Factor is not a TOTP key!"));
}
};
@ -360,15 +356,14 @@ pub async fn login_with_webauthn(id: Identity, query: web::Query<LoginWithWebaut
let factor = match user.find_factor(&query.id) {
Some(f) => f,
None => return HttpResponse::Ok()
.body(FatalErrorPage { message: "Factor not found!" }.render().unwrap())
None => return HttpResponse::Ok().body(build_fatal_error_page("Factor not found!"))
};
let key = match &factor.kind {
TwoFactorType::WEBAUTHN(key) => key,
_ => {
return HttpResponse::Ok()
.body(FatalErrorPage { message: "Factor is not a Webauthn key!" }.render().unwrap());
.body(build_fatal_error_page("Factor is not a Webauthn key!"));
}
};
@ -377,7 +372,7 @@ pub async fn login_with_webauthn(id: Identity, query: web::Query<LoginWithWebaut
Err(e) => {
log::error!("Failed to generate webauthn challenge! {:?}", e);
return HttpResponse::InternalServerError()
.body(FatalErrorPage { message: "Failed to generate webauthn challenge" }.render().unwrap());
.body(build_fatal_error_page("Failed to generate webauthn challenge"));
}
};