Skip to main content

PasswordResetter

Trait PasswordResetter 

Source
pub trait PasswordResetter:
    Send
    + Sync
    + 'static {
    type User: PanelUser;

    // Required methods
    fn find_by_email(
        &self,
        cx: &Cx,
        email: &str,
    ) -> impl Future<Output = Result<Option<Self::User>, Error>> + Send;
    fn reset_password(
        &self,
        cx: &Cx,
        user_id: &str,
        password: &str,
        ex: &mut dyn Executor,
    ) -> impl Future<Output = Result<(), Error>> + Send;
}
Expand description

How a panel finds the account a password reset names and sets its new password, installed with Auth::password_reset through a PasswordReset.

PasswordAuth resets a PasswordAccount; an app whose user table is not one implements it beside its Authenticator, for the same user type. The link goes to the address PanelUser::email answers, the one the account stores, never the one the visitor typed: a lookup that matches loosely, such as a collation folding accents, would otherwise mail one account’s link to another address. An account without one gets no link.

struct StaffAuth;

impl PasswordResetter for StaffAuth {
    type User = Staff;

    async fn find_by_email(&self, cx: &Cx, email: &str) -> topcoat::Result<Option<Staff>> {
        let mut db = tablo_core::db::db(cx)?;
        Ok(Staff::filter_by_email(email).first().exec(&mut db).await?)
    }

    async fn reset_password(
        &self,
        _cx: &Cx,
        user_id: &str,
        password: &str,
        ex: &mut dyn toasty::Executor,
    ) -> topcoat::Result<()> {
        let Ok(id) = user_id.parse::<uuid::Uuid>() else {
            return Ok(());
        };
        Staff::filter_by_id(id)
            .update()
            .password_hash(hash_password(password).await?)
            .exec(ex)
            .await?;
        Ok(())
    }
}

Required Associated Types§

Source

type User: PanelUser

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

Required Methods§

Source

fn find_by_email( &self, cx: &Cx, email: &str, ) -> impl Future<Output = Result<Option<Self::User>, Error>> + Send

The account email signs in as, or None. The address arrives trimmed, as the visitor typed it.

Source

fn reset_password( &self, cx: &Cx, user_id: &str, password: &str, ex: &mut dyn Executor, ) -> impl Future<Output = Result<(), Error>> + Send

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§