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
impl TwoFactor
Sourcepub fn required(self) -> Self
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.
Sourcepub fn required_for<U: PanelUser>(
self,
rule: impl Fn(&Cx, &U) -> bool + Send + Sync + 'static,
) -> Self
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")),
);Sourcepub fn email_codes(self) -> Self
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.
Sourcepub fn mail_throttle(self, throttle: LoginThrottle) -> Self
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.
Sourcepub fn throttle(self, throttle: LoginThrottle) -> Self
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.