Skip to main content

request_email_change

Function request_email_change 

Source
pub async fn request_email_change(
    cx: &Cx,
    ex: &mut dyn Executor,
    user: &(dyn PanelUser + 'static),
    email: &str,
) -> Result<EmailChange, Error>
Expand description

Asks the account user to confirm email as its new address before it changes, when the request’s panel installs Auth::email_verification; call it from ProfileEditor::save through the save’s transaction ex, in place of writing the address.

It answers EmailChange::Pending once it has recorded the change: the panel mails the new address a link that stores it, verified, and the old address a link that keeps it, both after the save commits. Confirming the first is a credential change. The second works for a week, before or after the change goes through: it restores the old address and ends every session the account holds. It answers EmailChange::Immediate on a panel that verifies no address, and writes nothing: store the address yourself.

The link proves only that whoever asked reads the new mailbox, and a stolen session can name one its thief reads: ask for the current password before calling it, as PasswordAuth’s profile does.

async fn save_email(
    cx: &Cx,
    staff: &Staff,
    email: String,
    ex: &mut dyn toasty::Executor,
) -> topcoat::Result<()> {
    if auth::request_email_change(cx, ex, staff, &email).await? == EmailChange::Immediate {
        Staff::filter_by_id(staff.id)
            .update()
            .email(email)
            .exec(ex)
            .await?;
    }
    Ok(())
}

§Errors

403 while the signed-in user is acted as through Auth::impersonation; the opaque outage when the database cannot answer.