pub struct Users<M>(/* private fields */);Expand description
The UserProvider for a model that derives Authenticatable.
The session guard uses the model’s queries to find users. Register the provider in
with_auth:
use laravel::auth::{Authenticatable, RememberToken};
use laravel::hash::PasswordHash;
use laravel::model::{self, model};
#[model]
#[derive(Authenticatable)]
pub struct User {
pub id: i64,
pub email: String,
#[serde(skip)]
pub password: PasswordHash,
#[serde(skip)]
pub remember_token: Option<RememberToken>,
}
laravel::Application::configure().with_auth(|auth, _| {
auth.session::<model::Users<User>>();
});The provider finds a logged-in user by the model’s key. It finds a user who is logging in by
the email field, or by the field marked #[auth(username)]. A model with neither field
doesn’t compile:
#[model]
#[derive(Authenticatable)]
pub struct User {
pub id: i64,
pub username: String,
#[serde(skip)]
pub password: PasswordHash,
#[serde(skip)]
pub remember_token: Option<RememberToken>,
}
laravel::Application::configure().with_auth(|auth, _| {
auth.session::<model::Users<User>>();
});When the provider saves a new password or an email verification, it updates the model the same
way update! does. It runs the updating hook, sets updated_at, and dispatches
Updated. When it saves a new remember token, it writes only the token’s
column. It runs no hook, dispatches no event, and leaves updated_at unchanged.
The provider doesn’t restrict which users may log in. To keep some users out, such as
suspended accounts, implement UserProvider for your own service using the model’s queries.
Trait Implementations§
Source§impl<M> UserProvider for Users<M>
impl<M> UserProvider for Users<M>
Source§async fn find(&self, id: &M::Key) -> Result<Option<M>>
async fn find(&self, id: &M::Key) -> Result<Option<M>>
find on every request that asks for the user. Read moreSource§async fn find_for_login(&self, login: &str) -> Result<Option<M>>
async fn find_for_login(&self, login: &str) -> Result<Option<M>>
login, such as by their email address. Read moreSource§async fn update_password(&self, user: &M, password: &PasswordHash) -> Result<()>
async fn update_password(&self, user: &M, password: &PasswordHash) -> Result<()>
Source§async fn update_remember_token(&self, user: &M, token: &str) -> Result<()>
async fn update_remember_token(&self, user: &M, token: &str) -> Result<()>
Source§async fn mark_email_as_verified(&self, user: &M) -> Result<()>
async fn mark_email_as_verified(&self, user: &M) -> Result<()>
email_verified_at to the current time. [EmailVerification::verify] calls it for a user
type that derives MustVerifyEmail. Read moreAuto Trait Implementations§
impl<M> Forget for Users<M>
impl<M> Freeze for Users<M>
impl<M> Move for Users<M>
impl<M> RefUnwindSafe for Users<M>
impl<M> Send for Users<M>
impl<M> Sync for Users<M>
impl<M> Unpin for Users<M>
impl<M> UnsafeUnpin for Users<M>
impl<M> UnwindSafe for Users<M>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<K> ForeignKey<K> for K
impl<K> ForeignKey<K> for K
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> ⓘ
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> ⓘ
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