diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-13 01:26:56 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-13 02:42:27 -0400 |
| commit | 3193a30ebcf6bafdeaf463eda0e7e82082dfe4b5 (patch) | |
| tree | 2fb3ea84923aecf0ec1f820408bdc670b1247c95 /src/login | |
| parent | 067e3da1900d052a416c56e1c047640aa23441ae (diff) | |
Embed the sender's whole login (id and name) in messages, drop the redundant channel ID.
Diffstat (limited to 'src/login')
| -rw-r--r-- | src/login/repo/logins.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/login/repo/logins.rs b/src/login/repo/logins.rs index 142d8fb..e1c5057 100644 --- a/src/login/repo/logins.rs +++ b/src/login/repo/logins.rs @@ -18,7 +18,7 @@ pub struct Logins<'t>(&'t mut SqliteConnection); // This also implements FromRequestParts (see `src/login/extract/login.rs`). As // a result, it can be used as an extractor. -#[derive(Debug)] +#[derive(Clone, Debug, serde::Serialize)] pub struct Login { pub id: Id, pub name: String, @@ -55,6 +55,24 @@ impl<'c> Logins<'c> { Ok(login) } + pub async fn by_id(&mut self, id: &Id) -> Result<Login, BoxedError> { + let login = sqlx::query_as!( + Login, + r#" + select + id as "id: Id", + name + from login + where id = $1 + "#, + id, + ) + .fetch_one(&mut *self.0) + .await?; + + Ok(login) + } + /// Retrieves a login by name, plus its stored password hash for /// verification. If there's no login with the requested name, this will /// return [None]. @@ -90,7 +108,7 @@ impl<'c> Logins<'c> { } /// Stable identifier for a [Login]. Prefixed with `L`. -#[derive(Clone, Debug, sqlx::Type, serde::Serialize)] +#[derive(Clone, Debug, Eq, PartialEq, sqlx::Type, serde::Serialize)] #[sqlx(transparent)] pub struct Id(BaseId); @@ -105,3 +123,9 @@ impl Id { BaseId::generate("L") } } + +impl std::fmt::Display for Id { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} |
