Skip to main content

TwoFactor

Struct TwoFactor 

Source
pub struct TwoFactor { /* private fields */ }
Expand description

A panel’s two-factor sign-in, installed with Auth::two_factor: each signed-in user may add an authenticator app, or codes by email when the panel mails them, at {prefix}/two-factor, and an account that has one signs in with a code from it after its password.

use tablo_core::{Auth, TwoFactor};

let auth = Auth::password().two_factor(TwoFactor::new().required());

Implementations§

Source§

impl TwoFactor

Source

pub fn new() -> Self

Two-factor sign-in each user may turn on.

Source

pub fn required(self) -> Self

Sends a signed-in user without a second factor to {prefix}/two-factor before anything else: a page answers with a redirect to it and any other request with 403, after an unverified address.

Source

pub fn required_for<U: PanelUser>( self, rule: impl Fn(&Cx, &U) -> bool + Send + Sync + 'static, ) -> Self

Requires a second factor of the users rule answers true for, as required does of every user, and leaves it optional for the others: staff, say, or the members of a tenant that asks it of them.

The rule is asked on every request, so a user it starts to cover is sent to set up a factor at their next one. A user of another type than U is required one: the panel signs in no such user, so the rule cannot have meant to let them through.

use tablo_core::{Auth, TwoFactor, auth::AdminUser};

let auth = Auth::password().two_factor(
    TwoFactor::new()
        .required_for(|_cx, user: &AdminUser| user.email.ends_with("@staff.example")),
);
Source

pub fn email_codes(self) -> Self

Lets a user with an address choose codes mailed to it in place of an authenticator app: each sign-in mails one, through Auth::mail, which mounting then requires. A mailed code works once, for ten minutes.

Source

pub fn mail_throttle(self, throttle: LoginThrottle) -> Self

How many codes one account may have mailed in a window; defaults to three in fifteen minutes.

Source

pub fn throttle(self, throttle: LoginThrottle) -> Self

How many codes one account may try in a window, from any client, at sign-in and on the settings page together; defaults to five a minute.

Trait Implementations§

Source§

impl Debug for TwoFactor

Source§

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

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

impl Default for TwoFactor

Source§

fn default() -> Self

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

Auto Trait Implementations§

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

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

Source§

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

Source§

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.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

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, 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

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

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