pub struct RegistrationEmailVerification<'a> { /* private fields */ }Expand description
一次性验证码引擎:配置经 Tools 的 config 槽注入,投递器经 extension 槽注入。
Implementations§
Source§impl<'a> RegistrationEmailVerification<'a>
impl<'a> RegistrationEmailVerification<'a>
Sourcepub fn from_context(ctx: &'a ActionContext) -> Result<Self, BaseError>
pub fn from_context(ctx: &'a ActionContext) -> Result<Self, BaseError>
从 Action 上下文的 Tools config 槽读取 EmailVerificationConfig 构建引擎。
Sourcepub fn from_config(
config: &'a EmailVerificationConfig,
) -> Result<Self, BaseError>
pub fn from_config( config: &'a EmailVerificationConfig, ) -> Result<Self, BaseError>
从显式配置构建引擎。
用于同一 Tools 中需要第二套验证码 key 域的场景(如邮箱换绑验证码,
与注册验证码的 Redis key 前缀和密钥隔离)。调用方保证该配置来自
独立注入的 config 槽,且与注册验证码的密钥不冲突。
Sourcepub async fn request(
&self,
ctx: &ActionContext,
email: &str,
deliver: bool,
) -> Result<RegistrationEmailCodeAccepted, BaseError>
pub async fn request( &self, ctx: &ActionContext, email: &str, deliver: bool, ) -> Result<RegistrationEmailCodeAccepted, BaseError>
请求签发一枚验证码。
deliver = false 时(如身份已存在的防枚举场景)只消耗限额、不真实投递,
仍返回通用接受响应。
Sourcepub async fn request_via(
&self,
ctx: &ActionContext,
email: &str,
deliver: bool,
sender: &VerificationCodeSenderHandle,
) -> Result<RegistrationEmailCodeAccepted, BaseError>
pub async fn request_via( &self, ctx: &ActionContext, email: &str, deliver: bool, sender: &VerificationCodeSenderHandle, ) -> Result<RegistrationEmailCodeAccepted, BaseError>
与 Self::request 相同,但验证码经显式传入的投递器发送。
用于注册之外的验证码场景(如登录 MFA 备用邮箱验证码):邮件文案由
业务侧 VerificationCodeSender 决定,与注册投递器解耦;存储、限流、
冷却与防枚举语义与 Self::request 完全一致。
Sourcepub async fn consume(
&self,
ctx: &ActionContext,
email: &str,
code: &str,
) -> Result<(), BaseError>
pub async fn consume( &self, ctx: &ActionContext, email: &str, code: &str, ) -> Result<(), BaseError>
校验并原子消费一枚验证码;任何失败都返回统一的无效验证码错误。
Sourcepub async fn verify_only(
&self,
ctx: &ActionContext,
email: &str,
code: &str,
) -> Result<(), BaseError>
pub async fn verify_only( &self, ctx: &ActionContext, email: &str, code: &str, ) -> Result<(), BaseError>
只校验不消费一枚验证码;任何失败都返回统一的无效验证码错误。
供两段式登录的第一段使用:先确认验证码有效但不销毁,待第二因子
(如 TOTP)也通过后再由 Self::consume 完成原子消费。失败路径与
Self::consume 共享错误计数与上限销毁语义——错误尝试照常计数、
达上限即销毁,不存在不计次的暴力枚举旁路。
本接口不构成最终持有证明:验证码在 TTL 内仍可被消费。调用方在签发
任何凭据前必须以 Self::consume 完成原子消费。
Auto Trait Implementations§
impl<'a> Forget for RegistrationEmailVerification<'a>
impl<'a> Freeze for RegistrationEmailVerification<'a>
impl<'a> Move for RegistrationEmailVerification<'a>
impl<'a> RefUnwindSafe for RegistrationEmailVerification<'a>
impl<'a> Send for RegistrationEmailVerification<'a>
impl<'a> Sync for RegistrationEmailVerification<'a>
impl<'a> Unpin for RegistrationEmailVerification<'a>
impl<'a> UnsafeUnpin for RegistrationEmailVerification<'a>
impl<'a> UnwindSafe for RegistrationEmailVerification<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more