Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 261136d

Browse files
author
bitfl0wer
committed
feat(squashme): Further work on register endpoint with TODOs
1 parent 9e56abd commit 261136d

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/api/auth/register.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
use argon2::{
2+
Argon2,
3+
password_hash::{PasswordHash, PasswordHasher, SaltString, rand_core::OsRng},
4+
};
15
use poem::{
26
IntoResponse, handler,
37
http::StatusCode,
48
web::{Data, Json},
59
};
610

711
use crate::{
8-
api::models::RegisterSchema,
9-
database::{Database, tokens::TokenStore},
10-
errors::SonataApiError,
12+
api::models::{NISTPasswordRequirements, PasswordRequirements, RegisterSchema},
13+
database::{Database, LocalActor, tokens::TokenStore},
14+
errors::{Context, Errcode, Error, SonataApiError},
1115
};
1216

1317
#[handler]
@@ -16,5 +20,21 @@ pub async fn register(
1620
Data(db): Data<&Database>,
1721
Data(token_store): Data<&TokenStore>,
1822
) -> Result<impl IntoResponse, SonataApiError> {
23+
// TODO: Check if registration is currently allowed
24+
// TODO: Check if registration is currently in invite-only mode
25+
if LocalActor::by_local_name(db, &payload.local_name).await?.is_some() {
26+
return Err(SonataApiError::Error(Error::new(
27+
Errcode::Duplicate,
28+
Some(Context::new(Some("local_name"), Some(&payload.local_name), None)),
29+
)));
30+
}
31+
let password = NISTPasswordRequirements::verify_requirements(&payload.password)?;
32+
let salt = SaltString::generate(&mut OsRng);
33+
let argon2 = Argon2::default();
34+
let password_hash = argon2
35+
.hash_password(password.as_bytes(), &salt)
36+
.map_err(|_| Error::new(Errcode::Internal, None).into_api_error())?;
37+
// TODO: Check if registration is currently in whitelist mode
38+
// TODO: Store user etc. in DB
1939
Ok(poem::error::Error::from_status(StatusCode::NOT_IMPLEMENTED).into_response())
2040
}

0 commit comments

Comments
 (0)