Skip to main content

PasswordAuth

Struct PasswordAuth 

Source
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

Source

pub const fn new() -> Self

The stock sign-in over the shipped AdminUser.

Trait Implementations§

Source§

impl<A: PasswordAccount> Authenticator for PasswordAuth<A>

Source§

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>

The account’s key when an edit changed its email or its password hash.

Source§

type User = <A as PasswordAccount>::User

The app’s user type.
Source§

async fn verify( &self, cx: &Cx, login: &str, password: &str, ) -> Result<Option<A::User>>

Verify login/password, returning the user on success. Read more
Source§

async fn find_by_id(&self, cx: &Cx, id: &str) -> Result<Option<A::User>>

Load the session’s user by PanelUser::user_id, with everything the request reads from it — its tenants included. Read more
Source§

async fn store_locale( &self, cx: &Cx, user: &A::User, locale: &Locale, ) -> Result<()>

Stores 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 more
Source§

impl<A> Clone for PasswordAuth<A>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A> Copy for PasswordAuth<A>

Source§

impl<A> Debug for PasswordAuth<A>

Source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A> Default for PasswordAuth<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A: PasswordAccount> EmailVerifier for PasswordAuth<A>

Source§

type User = <A as PasswordAccount>::User

The account a link verifies: the type the panel’s Authenticator loads, which mounting checks.
Source§

fn is_verified(&self, user: &A::User) -> bool

Whether 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<()>

Record, through the transaction 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>

Source§

type User = <A as PasswordAccount>::User

The account a reset names: the type the panel’s Authenticator loads, which mounting checks.
Source§

async fn find_by_email(&self, cx: &Cx, email: &str) -> Result<Option<A::User>>

The account 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<()>

Set the password of the account 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>

Source§

type Input = Profile

What the profile page asks for: Profile, or the app’s own #[derive(FormInput)] struct.
Source§

type User = <A as PasswordAccount>::User

The account the page edits: the type the panel’s Authenticator loads, which mounting checks.
Source§

fn fill(&self, _cx: &Cx, user: &A::User) -> Profile

The form as the page first shows it, from the signed-in 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::User, profile: &Profile, ex: &mut dyn Executor, ) -> Result<FieldErrors>

Refuse a submission save should not receive, such as a wrong current password: each error names an input field’s key and renders under its control. Defaults to none. A key no control renders is a declaration error: the page would show no message. Read more
Source§

async fn save( &self, cx: &Cx, user: &A::User, profile: Profile, ex: &mut dyn Executor, ) -> Result<ProfileUpdate>

Write a validated input to user’s account through the transaction ex, which commits when it returns Ok, and say whether a credential changed.

Auto Trait Implementations§

§

impl<A> Freeze for PasswordAuth<A>

§

impl<A> RefUnwindSafe for PasswordAuth<A>

§

impl<A> Send for PasswordAuth<A>

§

impl<A> Sync for PasswordAuth<A>

§

impl<A> Unpin for PasswordAuth<A>

§

impl<A> UnsafeUnpin for PasswordAuth<A>

§

impl<A> UnwindSafe for PasswordAuth<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more