summaryrefslogtreecommitdiff
path: root/src/user/create.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-08-26 00:44:29 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-08-26 01:38:21 -0400
commitd0d5fa20200a7ad70173ba87ae47c33b60f44a3b (patch)
tree39d5dbd0cae7df293a87bc9fcfc78f57e72d5204 /src/user/create.rs
parent0bbc83f09cc7517dddf16770a15f9e90815f48ba (diff)
Split `user` into a chat-facing entity and an authentication-facing entity.
The taxonomy is now as follows: * A _login_ is someone's identity for the purposes of authenticating to the service. Logins are not synchronized, and in fact are not published anywhere in the current API. They have a login ID, a name and a password. * A _user_ is someone's identity for the purpose of participating in conversations. Users _are_ synchronized, as before. They have a user ID, a name, and a creation instant for the purposes of synchronization. In practice, a user exists for every login - in fact, users' names are stored in the login table and are joined in, rather than being stored redundantly in the user table. A login ID and its corresponding user ID are always equal, and the user and login ID types support conversion and comparison to facilitate their use in this context. Tokens are now associated with logins, not users. The currently-acting identity is passed down into app types as a login, not a user, and then resolved to a user where appropriate within the app methods. As a side effect, the `GET /api/boot` method now returns a `login` key instead of a `user` key. The structure of the nested value is unchanged.
Diffstat (limited to 'src/user/create.rs')
-rw-r--r--src/user/create.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/user/create.rs b/src/user/create.rs
index 5d7bf65..5c060c9 100644
--- a/src/user/create.rs
+++ b/src/user/create.rs
@@ -4,6 +4,7 @@ use super::{History, repo::Provider as _, validate};
use crate::{
clock::DateTime,
event::{Broadcaster, Event, repo::Provider as _},
+ login::{self, Login, repo::Provider as _},
name::Name,
password::{Password, StoredHash},
};
@@ -39,7 +40,7 @@ impl<'a> Create<'a> {
Ok(Validated {
name,
- password_hash,
+ password: password_hash,
created_at,
})
}
@@ -48,7 +49,7 @@ impl<'a> Create<'a> {
#[must_use = "dropping a user creation attempt is likely a mistake"]
pub struct Validated<'a> {
name: &'a Name,
- password_hash: StoredHash,
+ password: StoredHash,
created_at: &'a DateTime,
}
@@ -56,31 +57,38 @@ impl Validated<'_> {
pub async fn store(self, tx: &mut Transaction<'_, Sqlite>) -> Result<Stored, sqlx::Error> {
let Self {
name,
- password_hash,
+ password,
created_at,
} = self;
+ let login = Login {
+ id: login::Id::generate(),
+ name: name.to_owned(),
+ };
+
let created = tx.sequence().next(created_at).await?;
- let user = tx.users().create(name, &password_hash, &created).await?;
+ tx.logins().create(&login, &password).await?;
+ let user = tx.users().create(&login, &created).await?;
- Ok(Stored { user })
+ Ok(Stored { user, login })
}
}
#[must_use = "dropping a user creation attempt is likely a mistake"]
pub struct Stored {
user: History,
+ login: Login,
}
impl Stored {
- pub fn publish(self, events: &Broadcaster) {
- let Self { user } = self;
+ pub fn publish(self, broadcaster: &Broadcaster) {
+ let Self { user, login: _ } = self;
- events.broadcast(user.events().map(Event::from).collect::<Vec<_>>());
+ broadcaster.broadcast(user.events().map(Event::from).collect::<Vec<_>>());
}
- pub fn user(&self) -> &History {
- &self.user
+ pub fn login(&self) -> &Login {
+ &self.login
}
}