Skip to main content

record_failed_attempt

Function record_failed_attempt 

Source
pub async fn record_failed_attempt(
    conn: &mut PgConnection,
    user_id: Uuid,
    purpose: UserEmailCodePurpose,
    max_attempts: i32,
) -> ModelResult<bool>
Expand description

Counts a wrong guess against the user’s live code and retires it once max_attempts is reached.

Keyed on the user and purpose rather than on what was typed: there is only ever one live code, so any refused guess is a guess against it.

Returns whether this guess retired the code, which is a caller’s cue to send the user for a new one rather than another attempt. Also false when there was no live code to count against.