This commit is contained in:
@ -1,11 +1,13 @@
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
|
||||
use axum::{
|
||||
extract::Query,
|
||||
http::StatusCode,
|
||||
routing::{get, post},
|
||||
Extension, Json,
|
||||
};
|
||||
use rand_core::OsRng;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::responses::registration::RegistrationResponse;
|
||||
@ -17,7 +19,7 @@ use crate::{
|
||||
models::users::User,
|
||||
requests::registration::RegistrationRequest,
|
||||
responses::username_available::UsernameAvailable,
|
||||
types::{authentication_data::AuthenticationData, matrix_user_id::UserId},
|
||||
types::{authentication_data::AuthenticationData, user_id::UserId},
|
||||
Config,
|
||||
};
|
||||
|
||||
@ -79,14 +81,18 @@ async fn post_register(
|
||||
.then(|| ())
|
||||
.ok_or(RegistrationError::UserIdTaken)?;
|
||||
|
||||
let password = auth_data.password();
|
||||
let salt = SaltString::generate(OsRng);
|
||||
let argon2 = Argon2::default();
|
||||
let pw_hash = argon2
|
||||
.hash_password(auth_data.password().as_bytes(), &salt)?
|
||||
.to_string();
|
||||
|
||||
let display_name = match body.initial_device_display_name() {
|
||||
Some(display_name) => display_name.as_ref(),
|
||||
None => "Random displayname",
|
||||
};
|
||||
|
||||
let user = User::create(&db, &user_id, &user_id.to_string(), password).await?;
|
||||
let user = User::create(&db, &user_id, &user_id.to_string(), &pw_hash).await?;
|
||||
let device = Device::create(&db, &user, "test", display_name).await?;
|
||||
|
||||
(user, device)
|
||||
|
@ -96,7 +96,7 @@ impl IntoResponse for ApiError {
|
||||
)),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
},
|
||||
ApiError::Generic(err) => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(ErrorResponse::new(
|
||||
|
@ -7,5 +7,5 @@ pub enum RegistrationError {
|
||||
#[error("The desired user ID is not a valid user name")]
|
||||
InvalidUserId,
|
||||
#[error("The desired user ID is already taken")]
|
||||
UserIdTaken,
|
||||
UserIdTaken
|
||||
}
|
||||
|
Reference in New Issue
Block a user