Skip to content

Commit 73f2840

Browse files
committed
Data model and storage layer for storing user registrations
1 parent e49d5a3 commit 73f2840

21 files changed

+1489
-11
lines changed

crates/data-model/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ pub use self::{
4848
users::{
4949
Authentication, AuthenticationMethod, BrowserSession, Password, User, UserEmail,
5050
UserEmailAuthentication, UserEmailAuthenticationCode, UserRecoverySession,
51-
UserRecoveryTicket,
51+
UserRecoveryTicket, UserRegistration, UserRegistrationPassword,
5252
},
5353
};

crates/data-model/src/users.rs

+22
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use chrono::{DateTime, Utc};
1010
use rand::Rng;
1111
use serde::Serialize;
1212
use ulid::Ulid;
13+
use url::Url;
1314

1415
use crate::UserAgent;
1516

@@ -112,6 +113,7 @@ impl UserRecoveryTicket {
112113
pub struct UserEmailAuthentication {
113114
pub id: Ulid,
114115
pub user_session_id: Option<Ulid>,
116+
pub user_registration_id: Option<Ulid>,
115117
pub email: String,
116118
pub created_at: DateTime<Utc>,
117119
pub completed_at: Option<DateTime<Utc>>,
@@ -192,3 +194,23 @@ impl UserEmail {
192194
]
193195
}
194196
}
197+
198+
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
199+
pub struct UserRegistrationPassword {
200+
pub hashed_password: String,
201+
pub version: u16,
202+
}
203+
204+
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
205+
pub struct UserRegistration {
206+
pub id: Ulid,
207+
pub username: Option<String>,
208+
pub display_name: Option<String>,
209+
pub terms_url: Option<Url>,
210+
pub email_authentication_id: Option<Ulid>,
211+
pub password: Option<UserRegistrationPassword>,
212+
pub ip_address: Option<IpAddr>,
213+
pub user_agent: Option<UserAgent>,
214+
pub created_at: DateTime<Utc>,
215+
pub completed_at: Option<DateTime<Utc>>,
216+
}

crates/storage-pg/.sqlx/query-0e1bce56e15751d82a622d532b279bfc50e22cb12ddf7495c7b0fedca61f9421.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-188a4aeef5a8b4bf3230c7176ded64d52804848df378dc74f8f54ec4404e094e.json

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-4968c60adef69c7215a7efe2021baffb050b2f475ae106155c2e2f210a81191a.json

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-7246c8ce575b97b349f281457d83866362043a7740b09f3754fa8f583d93a819.json

+82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-7fd19dac2c15091e7f8bd85531d2b99d8a42cc89fe7bb6e9411a886f68e38628.json renamed to crates/storage-pg/.sqlx/query-7e367e416d18fcf9b227bf053421410b4b7b4af441f0a138c5421d1111cb9f79.json

+10-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-83d1b0720dfde3209d77f1142aa19359913b8a934ca8a642b7bb43c9a7a58a6d.json

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-86cef19d7fc2ca255f0e58d3f68ac3e7cc3ce1f676f7b744d4a187a935a459ab.json

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-8f5ce493e8b8473ba03d5263915a8b231f9e7c211ab83487536008e48316c269.json

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-b60d34f4d250c12f75dba10491c1337d69aebad12be6fbfbdde91e34083ba4ed.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-de6cb87ee8e603d485e13fbea453ef111ac9df726e305e88c87697b6062ed2df.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Copyright 2025 New Vector Ltd.
2+
--
3+
-- SPDX-License-Identifier: AGPL-3.0-only
4+
-- Please see LICENSE in the repository root for full details.
5+
6+
-- Add a table for storing user registrations
7+
CREATE TABLE "user_registrations" (
8+
"user_registration_id" UUID PRIMARY KEY,
9+
"ip_address" INET,
10+
"user_agent" TEXT,
11+
"username" TEXT,
12+
"display_name" TEXT,
13+
"terms_url" TEXT,
14+
"email_authentication_id" UUID
15+
REFERENCES "user_email_authentications" ("user_email_authentication_id")
16+
ON DELETE SET NULL,
17+
"hashed_password" TEXT,
18+
"hashed_password_version" INTEGER,
19+
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL,
20+
"completed_at" TIMESTAMP WITH TIME ZONE
21+
);
22+
23+
-- Allow using user email authentications for user registrations
24+
ALTER TABLE "user_email_authentications"
25+
ADD COLUMN "user_registration_id" UUID
26+
REFERENCES "user_registrations" ("user_registration_id")
27+
ON DELETE CASCADE;

crates/storage-pg/src/repository.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ use crate::{
4949
},
5050
user::{
5151
PgBrowserSessionRepository, PgUserEmailRepository, PgUserPasswordRepository,
52-
PgUserRecoveryRepository, PgUserRepository, PgUserTermsRepository,
52+
PgUserRecoveryRepository, PgUserRegistrationRepository, PgUserRepository,
53+
PgUserTermsRepository,
5354
},
5455
DatabaseError,
5556
};
@@ -191,6 +192,12 @@ where
191192
Box::new(PgUserTermsRepository::new(self.conn.as_mut()))
192193
}
193194

195+
fn user_registration<'c>(
196+
&'c mut self,
197+
) -> Box<dyn mas_storage::user::UserRegistrationRepository<Error = Self::Error> + 'c> {
198+
Box::new(PgUserRegistrationRepository::new(self.conn.as_mut()))
199+
}
200+
194201
fn browser_session<'c>(
195202
&'c mut self,
196203
) -> Box<dyn BrowserSessionRepository<Error = Self::Error> + 'c> {

0 commit comments

Comments
 (0)