pub struct AuthSession {
pub token_hash: String,
pub user_id: String,
pub panel: String,
pub tenant: Option<TenantId>,
pub expires_at: Timestamp,
pub created_at: Timestamp,
pub impersonating: Option<String>,
pub impersonating_until: Option<Timestamp>,
}Expand description
Shipped server-side session record: the SHA-256 hash of the client token, the user it authenticates, the panel that signed the user in, and its expiry. The raw token is never stored.
A session rides in its panel’s session_cookie, lasts as long as the panel’s
Sessions say, SESSION_LIFETIME from login by default, is replaced on each login and
deleted on logout; each successful login also deletes up to 500
expired sessions. It belongs to the panel
that signed the user in: another panel’s gate treats the request as anonymous, and
auth::user answers None there. A browser holds one session on each
panel, so signing in to a second panel leaves the first alone, and renaming a panel’s prefix
ends the sessions it issued. Sessions stay valid until they expire unless
revoke_sessions_for_user ends them.
The row records the panel’s prefix in a non-null panel column and the selected tenant in a
nullable tenant column, a TenantId Toasty stores as a Uuid on the database. A table
created without them gains them by migration: add panel with the panel’s prefix as its
default (ALTER TABLE auth_sessions ADD COLUMN panel TEXT NOT NULL DEFAULT '/admin'), then drop
the default once every row names its panel. Auth::impersonation
reads two more nullable columns, impersonating (TEXT) and impersonating_until, a
timestamp: a table created without them gains them by ALTER TABLE ... ADD COLUMN.
Fields§
§token_hash: StringHex-encoded SHA-256 of the session token.
user_id: StringPanelUser::user_id of the authenticated user.
panel: StringThe prefix of the panel that signed the user in (e.g. /admin): the
only panel the session authenticates.
tenant: Option<TenantId>The tenant the user selected; None acts for the first.
expires_at: TimestampIndexed for the login sweep’s range scan on this column.
created_at: Timestamp§impersonating: Option<String>PanelUser::user_id of the user the session’s user acts as, through
Auth::impersonation; None while they act as themselves.
impersonating_until: Option<Timestamp>When acting as impersonating ends on its own.
Implementations§
Source§impl AuthSession
impl AuthSession
Sourcepub fn fields() -> AuthSessionFields<AuthSession>
pub fn fields() -> AuthSessionFields<AuthSession>
Returns a handle used to reference AuthSession’s fields when building query expressions.
Sourcepub async fn get_by_token_hash(
executor: &mut dyn Executor,
token_hash: impl IntoExpr<<String as Field>::ExprTarget>,
) -> Result<AuthSession, Error>
pub async fn get_by_token_hash( executor: &mut dyn Executor, token_hash: impl IntoExpr<<String as Field>::ExprTarget>, ) -> Result<AuthSession, Error>
Fetches the single AuthSession where token_hash matches, erroring if none exists.
Sourcepub fn update_by_token_hash(
token_hash: impl IntoExpr<<String as Field>::ExprTarget>,
) -> AuthSessionUpdate
pub fn update_by_token_hash( token_hash: impl IntoExpr<<String as Field>::ExprTarget>, ) -> AuthSessionUpdate
Returns a builder that updates the AuthSession where token_hash matches.
Sourcepub async fn delete_by_token_hash(
executor: &mut dyn Executor,
token_hash: impl IntoExpr<<String as Field>::ExprTarget>,
) -> Result<(), Error>
pub async fn delete_by_token_hash( executor: &mut dyn Executor, token_hash: impl IntoExpr<<String as Field>::ExprTarget>, ) -> Result<(), Error>
Deletes the AuthSession where token_hash matches.
Sourcepub fn filter_by_token_hash(
token_hash: impl IntoExpr<<String as Field>::ExprTarget>,
) -> AuthSessionQuery
pub fn filter_by_token_hash( token_hash: impl IntoExpr<<String as Field>::ExprTarget>, ) -> AuthSessionQuery
Returns a query selecting the AuthSession records where token_hash matches.
Sourcepub async fn get_by_user_id(
executor: &mut dyn Executor,
user_id: impl IntoExpr<<String as Field>::ExprTarget>,
) -> Result<AuthSession, Error>
pub async fn get_by_user_id( executor: &mut dyn Executor, user_id: impl IntoExpr<<String as Field>::ExprTarget>, ) -> Result<AuthSession, Error>
Fetches the single AuthSession where user_id matches, erroring if none exists.
Sourcepub fn update_by_user_id(
user_id: impl IntoExpr<<String as Field>::ExprTarget>,
) -> AuthSessionUpdate
pub fn update_by_user_id( user_id: impl IntoExpr<<String as Field>::ExprTarget>, ) -> AuthSessionUpdate
Returns a builder that updates the AuthSession where user_id matches.
Sourcepub async fn delete_by_user_id(
executor: &mut dyn Executor,
user_id: impl IntoExpr<<String as Field>::ExprTarget>,
) -> Result<(), Error>
pub async fn delete_by_user_id( executor: &mut dyn Executor, user_id: impl IntoExpr<<String as Field>::ExprTarget>, ) -> Result<(), Error>
Deletes the AuthSession where user_id matches.
Sourcepub fn filter_by_user_id(
user_id: impl IntoExpr<<String as Field>::ExprTarget>,
) -> AuthSessionQuery
pub fn filter_by_user_id( user_id: impl IntoExpr<<String as Field>::ExprTarget>, ) -> AuthSessionQuery
Returns a query selecting the AuthSession records where user_id matches.
Sourcepub async fn get_by_expires_at(
executor: &mut dyn Executor,
expires_at: impl IntoExpr<<Timestamp as Field>::ExprTarget>,
) -> Result<AuthSession, Error>
pub async fn get_by_expires_at( executor: &mut dyn Executor, expires_at: impl IntoExpr<<Timestamp as Field>::ExprTarget>, ) -> Result<AuthSession, Error>
Fetches the single AuthSession where expires_at matches, erroring if none exists.
Sourcepub fn update_by_expires_at(
expires_at: impl IntoExpr<<Timestamp as Field>::ExprTarget>,
) -> AuthSessionUpdate
pub fn update_by_expires_at( expires_at: impl IntoExpr<<Timestamp as Field>::ExprTarget>, ) -> AuthSessionUpdate
Returns a builder that updates the AuthSession where expires_at matches.
Sourcepub async fn delete_by_expires_at(
executor: &mut dyn Executor,
expires_at: impl IntoExpr<<Timestamp as Field>::ExprTarget>,
) -> Result<(), Error>
pub async fn delete_by_expires_at( executor: &mut dyn Executor, expires_at: impl IntoExpr<<Timestamp as Field>::ExprTarget>, ) -> Result<(), Error>
Deletes the AuthSession where expires_at matches.
Sourcepub fn filter_by_expires_at(
expires_at: impl IntoExpr<<Timestamp as Field>::ExprTarget>,
) -> AuthSessionQuery
pub fn filter_by_expires_at( expires_at: impl IntoExpr<<Timestamp as Field>::ExprTarget>, ) -> AuthSessionQuery
Returns a query selecting the AuthSession records where expires_at matches.
Sourcepub fn create() -> AuthSessionCreate
pub fn create() -> AuthSessionCreate
Returns a builder that inserts a new AuthSession record.
Typically constructed through the toasty::create! macro.
Sourcepub fn create_many() -> CreateMany<AuthSession>
pub fn create_many() -> CreateMany<AuthSession>
Returns a builder that inserts multiple AuthSession records at once.
Sourcepub fn update(&mut self) -> AuthSessionUpdate<&mut AuthSession>
pub fn update(&mut self) -> AuthSessionUpdate<&mut AuthSession>
Returns a builder that updates this AuthSession record in place.
Source§impl AuthSession
impl AuthSession
Sourcepub fn upsert_by_token_hash(
token_hash: impl IntoExpr<<String as Field>::ExprTarget>,
) -> AuthSessionUpsertByTokenHash
pub fn upsert_by_token_hash( token_hash: impl IntoExpr<<String as Field>::ExprTarget>, ) -> AuthSessionUpsertByTokenHash
Returns a builder that creates AuthSession or updates the record whose token_hash constraint matches.
The target arguments initialize a new record and remain unchanged when an existing record is updated.
Trait Implementations§
Source§impl Assign<AuthSession> for AuthSession
impl Assign<AuthSession> for AuthSession
Source§fn into_assignment(self) -> Assignment<AuthSession>
fn into_assignment(self) -> Assignment<AuthSession>
Assignment<T>] value.Source§impl Clone for AuthSession
impl Clone for AuthSession
Source§fn clone(&self) -> AuthSession
fn clone(&self) -> AuthSession
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuthSession
impl Debug for AuthSession
Source§impl IntoExpr<AuthSession> for AuthSession
impl IntoExpr<AuthSession> for AuthSession
Source§fn into_expr(self) -> Expr<AuthSession>
fn into_expr(self) -> Expr<AuthSession>
Source§fn by_ref(&self) -> Expr<AuthSession>
fn by_ref(&self) -> Expr<AuthSession>
Source§impl IntoStatement for &AuthSession
impl IntoStatement for &AuthSession
Source§type Returning = AuthSession
type Returning = AuthSession
Source§fn into_statement(self) -> Statement<AuthSession>
fn into_statement(self) -> Statement<AuthSession>
self and produce the [Statement].Source§impl IntoStatement for &mut AuthSession
impl IntoStatement for &mut AuthSession
Source§type Returning = AuthSession
type Returning = AuthSession
Source§fn into_statement(self) -> Statement<AuthSession>
fn into_statement(self) -> Statement<AuthSession>
self and produce the [Statement].Source§impl IntoStatement for AuthSession
impl IntoStatement for AuthSession
Source§type Returning = AuthSession
type Returning = AuthSession
Source§fn into_statement(self) -> Statement<AuthSession>
fn into_statement(self) -> Statement<AuthSession>
self and produce the [Statement].Source§impl Load for AuthSession
impl Load for AuthSession
Source§fn load(value: Value) -> Result<AuthSession, Error>
fn load(value: Value) -> Result<AuthSession, Error>
Source§fn reload(target: &mut AuthSession, value: Value) -> Result<(), Error>
fn reload(target: &mut AuthSession, value: Value) -> Result<(), Error>
§fn ty_relation() -> Type
fn ty_relation() -> Type
stmt::Type] used when this type appears as a relation
target. The default delegates to ty().§fn load_relation(value: Value) -> Result<Self::Output, Error>
fn load_relation(value: Value) -> Result<Self::Output, Error>
Source§impl Model for AuthSession
impl Model for AuthSession
Source§type Query<__T> = AuthSessionQuery<__T>
type Query<__T> = AuthSessionQuery<__T>
Source§type Update<'a> = AuthSessionUpdate<&'a mut AuthSession>
type Update<'a> = AuthSessionUpdate<&'a mut AuthSession>
Source§type UpdateQuery = AuthSessionUpdate
type UpdateQuery = AuthSessionUpdate
Source§type PrimaryKey = String
type PrimaryKey = String
Source§type ManyField<__Origin> = AuthSessionListFields<__Origin>
type ManyField<__Origin> = AuthSessionListFields<__Origin>
Source§type OneField<__Origin, __Target> = AuthSessionFields<__Origin, __Target>
type OneField<__Origin, __Target> = AuthSessionFields<__Origin, __Target>
Source§fn register(model_set: &mut ModelSet)
fn register(model_set: &mut ModelSet)
ModelSet]. Read moreSource§fn new_path<__Origin>(
path: Path<__Origin, AuthSession>,
) -> <AuthSession as Model>::Path<__Origin>
fn new_path<__Origin>( path: Path<__Origin, AuthSession>, ) -> <AuthSession as Model>::Path<__Origin>
Path] targeting this model.Source§fn new_many_field<__Origin>(
path: Path<__Origin, List<AuthSession>>,
) -> AuthSessionListFields<__Origin>
fn new_many_field<__Origin>( path: Path<__Origin, List<AuthSession>>, ) -> AuthSessionListFields<__Origin>
ManyField from a path targeting a list
of this model.Source§fn find_by_primary_key(
id: Expr<<AuthSession as Model>::PrimaryKey>,
) -> <AuthSession as Model>::Query<List<AuthSession>>
fn find_by_primary_key( id: Expr<<AuthSession as Model>::PrimaryKey>, ) -> <AuthSession as Model>::Query<List<AuthSession>>
Source§fn wrap_query<__T>(stmt: Query<__T>) -> <AuthSession as Model>::Query<__T>
fn wrap_query<__T>(stmt: Query<__T>) -> <AuthSession as Model>::Query<__T>
Query in this model’s
query builder, preserving the result shape T. This is the single
constructor generic code uses to build any query shape; callers narrow
at the statement level (.one(), .first()) before wrapping.Source§fn query_one(
query: <AuthSession as Model>::Query<List<AuthSession>>,
) -> <AuthSession as Model>::Query<AuthSession>
fn query_one( query: <AuthSession as Model>::Query<List<AuthSession>>, ) -> <AuthSession as Model>::Query<AuthSession>
Source§fn query_first(
query: <AuthSession as Model>::Query<List<AuthSession>>,
) -> <AuthSession as Model>::Query<Option<AuthSession>>
fn query_first( query: <AuthSession as Model>::Query<List<AuthSession>>, ) -> <AuthSession as Model>::Query<Option<AuthSession>>
Source§fn field_name_to_id(name: &str) -> FieldId
fn field_name_to_id(name: &str) -> FieldId
FieldId]. Read more§fn new_root_path() -> Self::Path<Self>
fn new_root_path() -> Self::Path<Self>
§fn path_field<U>(index: usize) -> Path<Self, U>
fn path_field<U>(index: usize) -> Path<Self, U>
Path] from this model to the field at index.§fn path_model_list() -> Path<List<Self>, List<Self>>
fn path_model_list() -> Path<List<Self>, List<Self>>
Path] rooted at a list of this model, used as the root of
has-many relation scopes.§fn new_create() -> Self::Create
fn new_create() -> Self::Create
Source§impl UpdateTarget for &mut AuthSession
impl UpdateTarget for &mut AuthSession
Source§type Returning = AuthSession
type Returning = AuthSession
Update<R> statement.Source§fn to_update_stmt(&mut self, assignments: Assignments) -> Update<AuthSession>
fn to_update_stmt(&mut self, assignments: Assignments) -> Update<AuthSession>
Source§impl ViaTarget for AuthSession
impl ViaTarget for AuthSession
Source§type Query = AuthSessionQuery
type Query = AuthSessionQuery
Source§type Path<__Origin> = <AuthSession as Model>::ManyField<__Origin>
type Path<__Origin> = <AuthSession as Model>::ManyField<__Origin>
#[has_many(via = …)] field’s accessor returns,
parameterized by the origin model. Mirrors Model::Path for the
via-many case. Read moreSource§fn new_path<__Origin>(
path: Path<__Origin, List<AuthSession>>,
) -> <AuthSession as ViaTarget>::Path<__Origin>
fn new_path<__Origin>( path: Path<__Origin, List<AuthSession>>, ) -> <AuthSession as ViaTarget>::Path<__Origin>
Path handle from the typed path reaching this
terminal. A model terminal wraps the path in its chainable ManyField; a
scalar terminal is a leaf, so the path is the handle.Source§fn via_field_ty(singular: Name, path: Path) -> FieldTy
fn via_field_ty(singular: Name, path: Path) -> FieldTy
FieldTy::Via] for a #[has_many(via = …)] field whose
terminal element type is Self. Read moreSource§fn make_via_query(
assoc: Association<List<AuthSession>>,
) -> <AuthSession as ViaTarget>::Query
fn make_via_query( assoc: Association<List<AuthSession>>, ) -> <AuthSession as ViaTarget>::Query
Auto Trait Implementations§
impl Freeze for AuthSession
impl RefUnwindSafe for AuthSession
impl Send for AuthSession
impl Sync for AuthSession
impl Unpin for AuthSession
impl UnsafeUnpin for AuthSession
impl UnwindSafe for AuthSession
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
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> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<M> RelationOneField for Mwhere
M: Model,
impl<M> RelationOneField for Mwhere
M: Model,
§type One = <M as Model>::Query<M>
type One = <M as Model>::Query<M>
<Target as Model>::Query<Target>; for nullable impls it is
<Target as Model>::Query<Option<Target>>.§type Expr = M
type Expr = M
Self::Target for non-nullable impls and
Option<Self::Target> for nullable impls.§fn make_one(
query: <<M as RelationOneField>::Target as Model>::Query<List<<M as RelationOneField>::Target>>,
) -> <M as RelationOneField>::One
fn make_one( query: <<M as RelationOneField>::Target as Model>::Query<List<<M as RelationOneField>::Target>>, ) -> <M as RelationOneField>::One
Query<Model> for non-nullable impls and
Query<Option<Model>> for nullable impls. Read more§fn reload(target: &mut Self, value: Value) -> Result<(), Error>
fn reload(target: &mut Self, value: Value) -> Result<(), Error>
§fn has_one_relation_field_ty(
pair: Option<FieldId>,
via: Option<Path>,
) -> FieldTy
fn has_one_relation_field_ty( pair: Option<FieldId>, via: Option<Path>, ) -> FieldTy
FieldTy] for a HasOne relation field, given an
optional paired BelongsTo field on the target model resolved
from #[has_one(pair = <field>)]. When None, the linker selects
the pair by searching the target for a unique BelongsTo back to
the source. Read more§fn belongs_to_relation_field_ty(foreign_key: ForeignKey) -> FieldTy
fn belongs_to_relation_field_ty(foreign_key: ForeignKey) -> FieldTy
FieldTy] for a BelongsTo relation field, given the
foreign key resolved from the field’s #[belongs_to(...)] attribute.