pub struct PasswordAuth<A = AdminUser> { /* private fields */ }Expand description
The stock sign-in by email and password, over a PasswordAccount: the authenticator, and
the ProfileEditor, PasswordResetter and EmailVerifier for its users.
PasswordAuth reads the shipped AdminUser; PasswordAuth::<User>::default() reads
the app’s own User model.
use tablo_core::{Auth, PasswordAuth};
let auth = Auth::custom(PasswordAuth::new()).profile(PasswordAuth::new());An unknown email costs the same work as a wrong password, and every failure shows the same
message. It looks an email up trimmed and lowercased, so Ada@Example.com and
ada@example.com are one account. A row stored with capitals cannot sign in or reset its
password: list the accounts that differ only in case with SELECT LOWER(TRIM(email)) FROM users GROUP BY 1 HAVING COUNT(*) > 1, merge or delete them, then run UPDATE users SET email = LOWER(TRIM(email)). SQLite’s LOWER folds ASCII letters only, so lowercase any other
capital by hand.
As the profile editor it edits the name, the email and the password through a Profile.
Changing the email or the password asks for the current password, and refuses a new password
new_password_errors refuses and, once the current password
verifies, an email another account holds. A changed password is a
ProfileUpdate::Credentials. A new email goes through request_email_change: on a panel
with Auth::email_verification it waits for its link,
elsewhere it is stored at once, as a credential change.
Implementations§
Source§impl PasswordAuth
impl PasswordAuth
Sourcepub const fn new() -> PasswordAuth
pub const fn new() -> PasswordAuth
The stock sign-in over the shipped AdminUser.
Trait Implementations§
Source§impl<A> Authenticator for PasswordAuth<A>where
A: PasswordAccount,
impl<A> Authenticator for PasswordAuth<A>where
A: PasswordAccount,
Source§async fn confirm_password(
&self,
_cx: &Cx,
user: &<A as PasswordAccount>::User,
password: &str,
) -> Result<bool, Error>
async fn confirm_password( &self, _cx: &Cx, user: &<A as PasswordAccount>::User, password: &str, ) -> Result<bool, Error>
Checks password against the account’s own hash, whatever PanelUser::email answers.
Source§fn changed_credentials(
&self,
before: &(dyn Any + 'static),
after: &(dyn Any + 'static),
) -> Option<String>
fn changed_credentials( &self, before: &(dyn Any + 'static), after: &(dyn Any + 'static), ) -> Option<String>
The account’s key when an edit changed its email or its password hash.
Source§type User = <A as PasswordAccount>::User
type User = <A as PasswordAccount>::User
Source§async fn verify(
&self,
cx: &Cx,
login: &str,
password: &str,
) -> Result<Option<<A as PasswordAccount>::User>, Error>
async fn verify( &self, cx: &Cx, login: &str, password: &str, ) -> Result<Option<<A as PasswordAccount>::User>, Error>
Source§async fn find_by_id(
&self,
cx: &Cx,
id: &str,
) -> Result<Option<<A as PasswordAccount>::User>, Error>
async fn find_by_id( &self, cx: &Cx, id: &str, ) -> Result<Option<<A as PasswordAccount>::User>, Error>
PanelUser::user_id, with everything the request
reads from it — its tenants included. Read moreSource§async fn store_locale(
&self,
cx: &Cx,
user: &<A as PasswordAccount>::User,
locale: &Locale,
) -> Result<(), Error>
async fn store_locale( &self, cx: &Cx, user: &<A as PasswordAccount>::User, locale: &Locale, ) -> Result<(), Error>
locale as user’s after they pick it from the shell’s language menu, so their
locale reads it on the next request, in another browser, and in the
mail a job sends them. It runs only when the pick differs from that locale, and never
while someone impersonates the user. Read moreSource§impl<A> Clone for PasswordAuth<A>
impl<A> Clone for PasswordAuth<A>
Source§fn clone(&self) -> PasswordAuth<A>
fn clone(&self) -> PasswordAuth<A>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<A> Copy for PasswordAuth<A>
Source§impl<A> Debug for PasswordAuth<A>
impl<A> Debug for PasswordAuth<A>
Source§impl<A> Default for PasswordAuth<A>
impl<A> Default for PasswordAuth<A>
Source§fn default() -> PasswordAuth<A>
fn default() -> PasswordAuth<A>
Source§impl<A> EmailVerifier for PasswordAuth<A>where
A: PasswordAccount,
impl<A> EmailVerifier for PasswordAuth<A>where
A: PasswordAccount,
Source§type User = <A as PasswordAccount>::User
type User = <A as PasswordAccount>::User
Authenticator
loads, which mounting checks.Source§fn is_verified(&self, user: &<A as PasswordAccount>::User) -> bool
fn is_verified(&self, user: &<A as PasswordAccount>::User) -> bool
user proved it reads the address PanelUser::email answers. A user who has
not reaches only the page that asks for the proof.Source§async fn store_verified_email(
&self,
_cx: &Cx,
user_id: &str,
email: &str,
ex: &mut dyn Executor,
) -> Result<(), Error>
async fn store_verified_email( &self, _cx: &Cx, user_id: &str, email: &str, ex: &mut dyn Executor, ) -> Result<(), Error>
ex, which commits when it returns Ok, that the account
PanelUser::user_id user_id names proved it reads email: store email as the
address it signs in with, which an email change makes new, and mark it verified. An id
that names no account is an error, not a success: the link is spent either way. It may run
again for one link when the database aborts the transaction for a concurrent one, so it
writes only through ex.Source§impl<A> PasswordResetter for PasswordAuth<A>where
A: PasswordAccount,
impl<A> PasswordResetter for PasswordAuth<A>where
A: PasswordAccount,
Source§type User = <A as PasswordAccount>::User
type User = <A as PasswordAccount>::User
Authenticator
loads, which mounting checks.Source§async fn find_by_email(
&self,
cx: &Cx,
email: &str,
) -> Result<Option<<A as PasswordAccount>::User>, Error>
async fn find_by_email( &self, cx: &Cx, email: &str, ) -> Result<Option<<A as PasswordAccount>::User>, Error>
email signs in as, or None. The address arrives trimmed, as the visitor
typed it.Source§async fn reset_password(
&self,
_cx: &Cx,
user_id: &str,
password: &str,
ex: &mut dyn Executor,
) -> Result<(), Error>
async fn reset_password( &self, _cx: &Cx, user_id: &str, password: &str, ex: &mut dyn Executor, ) -> Result<(), Error>
PanelUser::user_id user_id names to password,
through the reset’s transaction ex, which commits when it returns Ok. The panel’s
authenticator still loads the account and it may enter the panel; the password is at
least MIN_PASSWORD_CHARS long and was typed twice. It may
run again for one reset when the database aborts the transaction for a concurrent one, so
it writes only through ex.Source§impl<A> ProfileEditor for PasswordAuth<A>where
A: PasswordAccount,
impl<A> ProfileEditor for PasswordAuth<A>where
A: PasswordAccount,
Source§type Input = Profile
type Input = Profile
Profile, or the app’s own
#[derive(FormInput)] struct.Source§type User = <A as PasswordAccount>::User
type User = <A as PasswordAccount>::User
Authenticator
loads, which mounting checks.Source§fn fill(&self, _cx: &Cx, user: &<A as PasswordAccount>::User) -> Profile
fn fill(&self, _cx: &Cx, user: &<A as PasswordAccount>::User) -> Profile
user. The page renders what
FormInput::write writes, so an input that never writes its passwords shows them
empty.Source§async fn validate(
&self,
_cx: &Cx,
user: &<A as PasswordAccount>::User,
profile: &Profile,
ex: &mut dyn Executor,
) -> Result<FieldErrors, Error>
async fn validate( &self, _cx: &Cx, user: &<A as PasswordAccount>::User, profile: &Profile, ex: &mut dyn Executor, ) -> Result<FieldErrors, Error>
Source§async fn save(
&self,
cx: &Cx,
user: &<A as PasswordAccount>::User,
profile: Profile,
ex: &mut dyn Executor,
) -> Result<ProfileUpdate, Error>
async fn save( &self, cx: &Cx, user: &<A as PasswordAccount>::User, profile: Profile, ex: &mut dyn Executor, ) -> Result<ProfileUpdate, Error>
input to user’s account through the transaction ex, which commits
when it returns Ok, and say whether a credential changed.