pub struct SessionLoginService<A>where
A: Authenticator,{ /* private fields */ }Expand description
Service for handling login/logout with sessions.
Combines authentication validation with session management.
§Example
ⓘ
let login_service = SessionLoginService::new(
memory_authenticator, // For validating credentials
session_config,
);
// In login handler
async fn login(
session: Session,
form: Form<LoginForm>,
login_service: Data<SessionLoginService<MemoryAuthenticator>>,
) -> impl Responder {
match login_service.login(&session, &form.username, &form.password) {
Ok(user) => HttpResponse::Ok().body(format!("Welcome, {}!", user.get_username())),
Err(_) => HttpResponse::Unauthorized().body("Invalid credentials"),
}
}Implementations§
Source§impl<A> SessionLoginService<A>where
A: Authenticator,
impl<A> SessionLoginService<A>where
A: Authenticator,
Sourcepub fn new(credential_authenticator: A, config: SessionConfig) -> Self
pub fn new(credential_authenticator: A, config: SessionConfig) -> Self
Create a new login service.
Sourcepub fn login_with_user(
&self,
session: &Session,
user: &User,
) -> Result<(), SessionError>
pub fn login_with_user( &self, session: &Session, user: &User, ) -> Result<(), SessionError>
Login with a validated user.
This method:
- Applies session fixation protection
- Stores user in session
Sourcepub fn config(&self) -> &SessionConfig
pub fn config(&self) -> &SessionConfig
Get the session configuration.
Sourcepub fn save_request(
&self,
session: &Session,
url: &str,
) -> Result<(), SessionError>
pub fn save_request( &self, session: &Session, url: &str, ) -> Result<(), SessionError>
Save the current request URL for redirect after login.
Sourcepub fn get_saved_request(&self, session: &Session, default_url: &str) -> String
pub fn get_saved_request(&self, session: &Session, default_url: &str) -> String
Get the saved request URL.
Trait Implementations§
Source§impl<A> Clone for SessionLoginService<A>where
A: Authenticator + Clone,
impl<A> Clone for SessionLoginService<A>where
A: Authenticator + Clone,
Source§fn clone(&self) -> SessionLoginService<A>
fn clone(&self) -> SessionLoginService<A>
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<A> Freeze for SessionLoginService<A>where
A: Freeze,
impl<A> RefUnwindSafe for SessionLoginService<A>where
A: RefUnwindSafe,
impl<A> Send for SessionLoginService<A>where
A: Send,
impl<A> Sync for SessionLoginService<A>where
A: Sync,
impl<A> Unpin for SessionLoginService<A>where
A: Unpin,
impl<A> UnwindSafe for SessionLoginService<A>where
A: UnwindSafe,
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