diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-03-23 15:58:33 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-03-23 16:25:22 -0400 |
| commit | 2420f1e75d54a5f209b0267715f078a369d81eb1 (patch) | |
| tree | 20edd531a3f2f765a23fef8e7a508c91bc7dc294 /src/token | |
| parent | 7e15690d54ff849596401b43d163df9353062850 (diff) | |
Rename the `login` module to `user`.
Diffstat (limited to 'src/token')
| -rw-r--r-- | src/token/app.rs | 14 | ||||
| -rw-r--r-- | src/token/extract/identity.rs | 6 | ||||
| -rw-r--r-- | src/token/repo/auth.rs | 12 | ||||
| -rw-r--r-- | src/token/repo/token.rs | 10 |
4 files changed, 21 insertions, 21 deletions
diff --git a/src/token/app.rs b/src/token/app.rs index 3f054ff..211df81 100644 --- a/src/token/app.rs +++ b/src/token/app.rs @@ -12,8 +12,8 @@ use super::{ use crate::{ clock::DateTime, db::NotFound as _, - login::{Login, Password, repo::Provider as _}, name::{self, Name}, + user::{Password, User, repo::Provider as _}, }; pub struct Tokens<'a> { @@ -31,7 +31,7 @@ impl<'a> Tokens<'a> { name: &Name, password: &Password, login_at: &DateTime, - ) -> Result<(Login, Secret), LoginError> { + ) -> Result<(User, Secret), LoginError> { let mut tx = self.db.begin().await?; let (login, stored_hash) = tx .auth() @@ -62,11 +62,11 @@ impl<'a> Tokens<'a> { pub async fn change_password( &self, - login: &Login, + login: &User, password: &Password, to: &Password, changed_at: &DateTime, - ) -> Result<(Login, Secret), LoginError> { + ) -> Result<(User, Secret), LoginError> { let mut tx = self.db.begin().await?; let (login, stored_hash) = tx .auth() @@ -90,7 +90,7 @@ impl<'a> Tokens<'a> { let mut tx = self.db.begin().await?; let tokens = tx.tokens().revoke_all(&login).await?; - tx.logins().set_password(&login, &to_hash).await?; + tx.users().set_password(&login, &to_hash).await?; let secret = tx.tokens().issue(&login, changed_at).await?; tx.commit().await?; @@ -105,7 +105,7 @@ impl<'a> Tokens<'a> { &self, secret: &Secret, used_at: &DateTime, - ) -> Result<(Id, Login), ValidateError> { + ) -> Result<(Id, User), ValidateError> { let mut tx = self.db.begin().await?; let (token, login) = tx .tokens() @@ -226,7 +226,7 @@ impl From<repo::auth::LoadError> for LoginError { pub enum ValidateError { #[error("invalid token")] InvalidToken, - #[error("login deleted")] + #[error("user deleted")] LoginDeleted, #[error(transparent)] Database(#[from] sqlx::Error), diff --git a/src/token/extract/identity.rs b/src/token/extract/identity.rs index acfd7ae..d1c0334 100644 --- a/src/token/extract/identity.rs +++ b/src/token/extract/identity.rs @@ -10,14 +10,14 @@ use crate::{ app::App, clock::RequestedAt, error::{Internal, Unauthorized}, - login::Login, token::{self, app::ValidateError}, + user::User, }; #[derive(Clone, Debug)] pub struct Identity { pub token: token::Id, - pub login: Login, + pub user: User, } impl FromRequestParts<App> for Identity { @@ -31,7 +31,7 @@ impl FromRequestParts<App> for Identity { let app = State::<App>::from_request_parts(parts, state).await?; match app.tokens().validate(&secret, &used_at).await { - Ok((token, login)) => Ok(Identity { token, login }), + Ok((token, user)) => Ok(Identity { token, user }), Err(ValidateError::InvalidToken) => Err(LoginError::Unauthorized), Err(other) => Err(other.into()), } diff --git a/src/token/repo/auth.rs b/src/token/repo/auth.rs index 8900704..a1f4aad 100644 --- a/src/token/repo/auth.rs +++ b/src/token/repo/auth.rs @@ -4,8 +4,8 @@ use crate::{ clock::DateTime, db::NotFound, event::{Instant, Sequence}, - login::{self, History, Login, password::StoredHash}, name::{self, Name}, + user::{self, History, User, password::StoredHash}, }; pub trait Provider { @@ -26,7 +26,7 @@ impl Auth<'_> { let row = sqlx::query!( r#" select - id as "id: login::Id", + id as "id: user::Id", display_name as "display_name: String", canonical_name as "canonical_name: String", created_sequence as "created_sequence: Sequence", @@ -41,7 +41,7 @@ impl Auth<'_> { .await?; let login = History { - login: Login { + user: User { id: row.id, name: Name::new(row.display_name, row.canonical_name)?, }, @@ -51,11 +51,11 @@ impl Auth<'_> { Ok((login, row.password_hash)) } - pub async fn for_login(&mut self, login: &Login) -> Result<(History, StoredHash), LoadError> { + pub async fn for_login(&mut self, login: &User) -> Result<(History, StoredHash), LoadError> { let row = sqlx::query!( r#" select - id as "id: login::Id", + id as "id: user::Id", display_name as "display_name: String", canonical_name as "canonical_name: String", created_sequence as "created_sequence: Sequence", @@ -70,7 +70,7 @@ impl Auth<'_> { .await?; let login = History { - login: Login { + user: User { id: row.id, name: Name::new(row.display_name, row.canonical_name)?, }, diff --git a/src/token/repo/token.rs b/src/token/repo/token.rs index 3428030..145ba2d 100644 --- a/src/token/repo/token.rs +++ b/src/token/repo/token.rs @@ -5,9 +5,9 @@ use crate::{ clock::DateTime, db::NotFound, event::{Instant, Sequence}, - login::{self, History, Login}, name::{self, Name}, token::{Id, Secret}, + user::{self, History, User}, }; pub trait Provider { @@ -85,7 +85,7 @@ impl Tokens<'_> { } // Revoke tokens for a login - pub async fn revoke_all(&mut self, login: &login::History) -> Result<Vec<Id>, sqlx::Error> { + pub async fn revoke_all(&mut self, login: &user::History) -> Result<Vec<Id>, sqlx::Error> { let login = login.id(); let tokens = sqlx::query_scalar!( r#" @@ -139,7 +139,7 @@ impl Tokens<'_> { where secret = $2 returning id as "token: Id", - user as "user: login::Id" + user as "user: user::Id" "#, used_at, secret, @@ -151,7 +151,7 @@ impl Tokens<'_> { let login = sqlx::query!( r#" select - id as "id: login::Id", + id as "id: user::Id", display_name as "display_name: String", canonical_name as "canonical_name: String", created_sequence as "created_sequence: Sequence", @@ -163,7 +163,7 @@ impl Tokens<'_> { ) .map(|row| { Ok::<_, name::Error>(History { - login: Login { + user: User { id: row.id, name: Name::new(row.display_name, row.canonical_name)?, }, |
