Skip to main content

EmailVerifier

Trait EmailVerifier 

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

    // Required methods
    fn is_verified(&self, user: &Self::User) -> bool;
    fn store_verified_email(
        &self,
        cx: &Cx,
        user_id: &str,
        email: &str,
        ex: &mut dyn Executor,
    ) -> impl Future<Output = Result<()>> + Send;
}
Expand description

How a panel records that an account reads the address it stores, installed with Auth::email_verification through an EmailVerification.

The link goes to the address PanelUser::email answers. The shipped PasswordAuth verifies a PasswordAccount; an app whose user table is not one implements it beside its Authenticator, for the same user type:

struct StaffAuth;

impl EmailVerifier for StaffAuth {
    type User = Staff;

    fn is_verified(&self, staff: &Staff) -> bool {
        staff.email_verified_at.is_some()
    }

    async fn store_verified_email(
        &self,
        _cx: &Cx,
        user_id: &str,
        email: &str,
        ex: &mut dyn toasty::Executor,
    ) -> topcoat::Result<()> {
        let id = user_id
            .parse::<uuid::Uuid>()
            .map_err(|_| topcoat::router::error::not_found())?;
        Staff::filter_by_id(id)
            .update()
            .email(email)
            .email_verified_at(Some(jiff::Timestamp::now()))
            .exec(ex)
            .await?;
        Ok(())
    }
}

Required Associated Types§

Source

type User: PanelUser

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

Required Methods§

Source

fn is_verified(&self, user: &Self::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

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

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.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§