fix errors, move password hashing into User add sqlx offline checks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-04-28 21:55:52 +02:00
parent 601b2d4f42
commit 304f82baa4
7 changed files with 219 additions and 13 deletions

View File

@ -33,8 +33,8 @@ pub fn routes() -> axum::Router {
}
#[tracing::instrument]
async fn get_login() -> Json<Flows> {
Json(Flows::new())
async fn get_login() -> Result<Json<Flows>, ApiError> {
Ok(Json(Flows::new()))
}
#[tracing::instrument(skip_all)]
@ -81,18 +81,12 @@ async fn post_register(
.then(|| ())
.ok_or(RegistrationError::UserIdTaken)?;
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(), &pw_hash).await?;
let user = User::create(&db, &user_id, &user_id.to_string(), auth_data.password()).await?;
let device = Device::create(&db, &user, "test", display_name).await?;
(user, device)

View File

@ -45,7 +45,7 @@ pub enum ApiError {
DBError(#[from] sqlx::Error),
#[error("Generic Error")]
Generic(anyhow::Error),
Generic(anyhow::Error)
}
impl From<anyhow::Error> for ApiError {