pub struct MagicLink {
pub id: Uuid,
pub token_hash: String,
pub subject_user_id: Uuid,
pub scope_kind: MagicLinkScopeKind,
pub scope_id: Uuid,
pub issued_by: Uuid,
pub expires_at: DateTime<Utc>,
pub consumed_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Fields§
§id: Uuid§token_hash: StringSHA-256 hex of the clear token. The clear token is NEVER stored.
subject_user_id: UuidUser to whom the link grants access (e.g. external contractor user).
scope_kind: MagicLinkScopeKind§scope_id: Uuid§issued_by: UuidSyndic / superadmin user who issued the link (audit trail).
expires_at: DateTime<Utc>§consumed_at: Option<DateTime<Utc>>§created_at: DateTime<Utc>§updated_at: DateTime<Utc>Implementations§
Source§impl MagicLink
impl MagicLink
Sourcepub fn issue(
subject_user_id: Uuid,
scope_kind: MagicLinkScopeKind,
scope_id: Uuid,
issued_by: Uuid,
ttl: Duration,
) -> Result<(Self, String), AppError>
pub fn issue( subject_user_id: Uuid, scope_kind: MagicLinkScopeKind, scope_id: Uuid, issued_by: Uuid, ttl: Duration, ) -> Result<(Self, String), AppError>
Issue a new MagicLink. Returns the persisted entity AND the clear token that must be returned in the HTTP response (and never stored elsewhere).
§Errors
AppError::Validationifttl <= 0,scope_idis nil, orsubject_user_id == issued_by.
Sourcepub fn hash_token(clear_token: &str) -> String
pub fn hash_token(clear_token: &str) -> String
SHA-256 hex digest of a clear token. Public so the repository / handler can hash an incoming token and look it up.
pub fn is_expired(&self) -> bool
pub fn is_consumed(&self) -> bool
pub fn is_valid(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MagicLink
impl<'de> Deserialize<'de> for MagicLink
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for MagicLink
Auto Trait Implementations§
impl Freeze for MagicLink
impl RefUnwindSafe for MagicLink
impl Send for MagicLink
impl Sync for MagicLink
impl Unpin for MagicLink
impl UnsafeUnpin for MagicLink
impl UnwindSafe for MagicLink
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 moreCreates a shared type from an unshared type.