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§
Trait Implementations§
Source§impl<A: PasswordAccount> Authenticator for PasswordAuth<A>
impl<A: PasswordAccount> Authenticator for PasswordAuth<A>
Source§async fn confirm_password(
&self,
_cx: &Cx,
user: &A::User,
password: &str,
) -> Result<bool>
async fn confirm_password( &self, _cx: &Cx, user: &A::User, password: &str, ) -> Result<bool>
Checks password against the account’s own hash, whatever PanelUser::email answers.
Source§fn changed_credentials(
&self,
before: &dyn Any,
after: &dyn Any,
) -> Option<String>
fn changed_credentials( &self, before: &dyn Any, after: &dyn Any, ) -> 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 find_by_id(&self, cx: &Cx, id: &str) -> Result<Option<A::User>>
async fn find_by_id(&self, cx: &Cx, id: &str) -> Result<Option<A::User>>
PanelUser::user_id, with everything the request
reads from it — its tenants included. Read moreSource§async fn store_locale(
&self,
cx: &Cx,
user: &A::User,
locale: &Locale,
) -> Result<()>
async fn store_locale( &self, cx: &Cx, user: &A::User, locale: &Locale, ) -> Result<()>
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>
impl<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§impl<A: PasswordAccount> EmailVerifier for PasswordAuth<A>
impl<A: PasswordAccount> EmailVerifier for PasswordAuth<A>
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::User) -> bool
fn is_verified(&self, user: &A::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<()>
async fn store_verified_email( &self, _cx: &Cx, user_id: &str, email: &str, ex: &mut dyn Executor, ) -> Result<()>
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: PasswordAccount> PasswordResetter for PasswordAuth<A>
impl<A: PasswordAccount> PasswordResetter for PasswordAuth<A>
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::User>>
async fn find_by_email(&self, cx: &Cx, email: &str) -> Result<Option<A::User>>
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<()>
async fn reset_password( &self, _cx: &Cx, user_id: &str, password: &str, ex: &mut dyn Executor, ) -> Result<()>
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: PasswordAccount> ProfileEditor for PasswordAuth<A>
impl<A: PasswordAccount> ProfileEditor for PasswordAuth<A>
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::User) -> Profile
fn fill(&self, _cx: &Cx, user: &A::User) -> Profile
user. The page renders what
FormInput::write writes, so an input that never writes its passwords shows them
empty.