Compare commits
No commits in common. "9f5fdd65abe145e10b196ee5b6994c2d4be76988" and "9a4c725b4e6db48e17e8b65dc0a71a83a40ac019" have entirely different histories.
9f5fdd65ab
...
9a4c725b4e
@ -7,7 +7,6 @@ use crate::data::user::{User, UserID, verify_password};
|
||||
pub enum LoginResult {
|
||||
AccountNotFound,
|
||||
InvalidPassword,
|
||||
AccountDisabled,
|
||||
Success(User),
|
||||
}
|
||||
|
||||
@ -55,10 +54,6 @@ impl Handler<LoginRequest> for UsersActor {
|
||||
return MessageResult(LoginResult::InvalidPassword);
|
||||
}
|
||||
|
||||
if !user.enabled {
|
||||
return MessageResult(LoginResult::AccountDisabled);
|
||||
}
|
||||
|
||||
MessageResult(LoginResult::Success(user))
|
||||
}
|
||||
}
|
||||
|
@ -114,11 +114,6 @@ pub async fn login_route(users: web::Data<Addr<UsersActor>>,
|
||||
}
|
||||
}
|
||||
|
||||
LoginResult::AccountDisabled => {
|
||||
log::warn!("Failed login for username {} : account is disabled", login);
|
||||
danger = "Your account is disabled!".to_string();
|
||||
}
|
||||
|
||||
c => {
|
||||
// TODO : add bruteforce detection
|
||||
log::warn!("Failed login for username {} : {:?}", login, c);
|
||||
|
@ -11,7 +11,7 @@ use askama::Template;
|
||||
|
||||
use crate::constants::{ADMIN_ROUTES, AUTHENTICATED_ROUTES};
|
||||
use crate::controllers::base_controller::redirect_user_for_login;
|
||||
use crate::data::session_identity::{SessionIdentity, SessionIdentityData, SessionStatus};
|
||||
use crate::data::session_identity::{SessionIdentity, SessionIdentityData};
|
||||
|
||||
// There are two steps in middleware processing.
|
||||
// 1. Middleware initialization, middleware factory gets called with
|
||||
@ -40,19 +40,19 @@ impl<S, B> Transform<S, ServiceRequest> for AuthMiddleware
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ConnStatus {
|
||||
enum SessionStatus {
|
||||
SignedOut,
|
||||
RegularUser,
|
||||
Admin,
|
||||
}
|
||||
|
||||
impl ConnStatus {
|
||||
impl SessionStatus {
|
||||
pub fn is_auth(&self) -> bool {
|
||||
!matches!(self, ConnStatus::SignedOut)
|
||||
!matches!(self, SessionStatus::SignedOut)
|
||||
}
|
||||
|
||||
pub fn is_admin(&self) -> bool {
|
||||
matches!(self, ConnStatus::Admin)
|
||||
matches!(self, SessionStatus::Admin)
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,9 +92,9 @@ impl<S, B> Service<ServiceRequest> for AuthInnerMiddleware<S>
|
||||
}
|
||||
|
||||
let identity = match SessionIdentity::deserialize_session_data(req.get_identity()) {
|
||||
Some(SessionIdentityData { status: SessionStatus::SignedIn, is_admin: true, .. }) => ConnStatus::Admin,
|
||||
Some(SessionIdentityData { status: SessionStatus::SignedIn, .. }) => ConnStatus::RegularUser,
|
||||
_ => ConnStatus::SignedOut,
|
||||
None => SessionStatus::SignedOut,
|
||||
Some(SessionIdentityData { is_admin: true, .. }) => SessionStatus::Admin,
|
||||
_ => SessionStatus::RegularUser,
|
||||
};
|
||||
|
||||
// Redirect user to login page
|
||||
|
Loading…
x
Reference in New Issue
Block a user