pub struct FormLoginHandler { /* private fields */ }Expand description
Form login handler for processing login/logout requests.
§Spring Security Equivalent
Similar to UsernamePasswordAuthenticationFilter in Spring Security.
§Example
ⓘ
use actix_security_core::http::security::form_login::{FormLoginHandler, FormLoginConfig, LoginForm};
use actix_security_core::http::security::session::SessionConfig;
let handler = FormLoginHandler::new(
FormLoginConfig::new(),
SessionConfig::new(),
);
// In your login route handler
async fn login(
session: Session,
form: Form<LoginForm>,
authenticator: Data<MemoryAuthenticator>,
handler: Data<FormLoginHandler>,
) -> impl Responder {
// Validate credentials
if let Some(user) = authenticator.verify_credentials(&form.username, &form.password) {
handler.on_authentication_success(&session, &user, None)
} else {
handler.on_authentication_failure()
}
}Implementations§
Source§impl FormLoginHandler
impl FormLoginHandler
Sourcepub fn new(
config: FormLoginConfig,
session_config: SessionConfig,
) -> FormLoginHandler
pub fn new( config: FormLoginConfig, session_config: SessionConfig, ) -> FormLoginHandler
Create a new form login handler.
Sourcepub fn on_authentication_success(
&self,
session: &Session,
user: &User,
saved_url: Option<String>,
) -> HttpResponse
pub fn on_authentication_success( &self, session: &Session, user: &User, saved_url: Option<String>, ) -> HttpResponse
Handle successful authentication.
This method:
- Stores user in session
- Redirects to saved request URL or default success URL
§Arguments
session- The actix sessionuser- The authenticated usersaved_url- Optional saved URL from before login redirect
Sourcepub fn on_authentication_failure(&self) -> HttpResponse
pub fn on_authentication_failure(&self) -> HttpResponse
Handle failed authentication.
Redirects to the failure URL.
Sourcepub fn on_logout(&self, session: &Session) -> HttpResponse
pub fn on_logout(&self, session: &Session) -> HttpResponse
Handle logout.
This method:
- Removes user from session
- Redirects to logout success URL
Sourcepub fn save_request(&self, session: &Session, url: &str)
pub fn save_request(&self, session: &Session, url: &str)
Save the current request URL for redirect after login.
Call this before redirecting to the login page.
Sourcepub fn login_page_url(&self) -> &str
pub fn login_page_url(&self) -> &str
Get the login page URL.
Sourcepub fn login_processing_url(&self) -> &str
pub fn login_processing_url(&self) -> &str
Get the login processing URL.
Sourcepub fn logout_url(&self) -> &str
pub fn logout_url(&self) -> &str
Get the logout URL.
Sourcepub fn is_login_page(&self, url: &str) -> bool
pub fn is_login_page(&self, url: &str) -> bool
Check if a URL is the login page.
Sourcepub fn is_login_processing_url(&self, url: &str) -> bool
pub fn is_login_processing_url(&self, url: &str) -> bool
Check if a URL is the login processing URL.
Sourcepub fn is_logout_url(&self, url: &str) -> bool
pub fn is_logout_url(&self, url: &str) -> bool
Check if a URL is the logout URL.
Sourcepub fn config(&self) -> &FormLoginConfig
pub fn config(&self) -> &FormLoginConfig
Get the form login configuration.
Sourcepub fn session_config(&self) -> &SessionConfig
pub fn session_config(&self) -> &SessionConfig
Get the session configuration.
Trait Implementations§
Source§impl Clone for FormLoginHandler
impl Clone for FormLoginHandler
Source§fn clone(&self) -> FormLoginHandler
fn clone(&self) -> FormLoginHandler
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FormLoginHandler
impl RefUnwindSafe for FormLoginHandler
impl Send for FormLoginHandler
impl Sync for FormLoginHandler
impl Unpin for FormLoginHandler
impl UnwindSafe for FormLoginHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more