minor tweaks

This commit is contained in:
Hamcha 2023-06-29 16:42:57 +02:00
parent afc3ffd89f
commit 4bdb810e19
Signed by: hamcha
GPG key ID: 1669C533B8CF6D89
3 changed files with 11 additions and 16 deletions

View file

@ -18,7 +18,7 @@ pub fn hash(plaintext: &String) -> Result<String> {
} }
pub fn verify(plaintext: &String, hash: &String) -> Result<bool> { pub fn verify(plaintext: &String, hash: &String) -> Result<bool> {
let parsed_hash = PasswordHash::new(&hash).map_err(|err| anyhow!(err))?; let parsed_hash = PasswordHash::new(hash).map_err(|err| anyhow!(err))?;
Ok(Argon2::default() Ok(Argon2::default()
.verify_password(plaintext.as_bytes(), &parsed_hash) .verify_password(plaintext.as_bytes(), &parsed_hash)
.is_ok()) .is_ok())

View file

@ -59,9 +59,6 @@ async fn main() -> Result<()> {
let addr: SocketAddr = config.bind.parse()?; let addr: SocketAddr = config.bind.parse()?;
tracing::debug!("listening on {}", addr); tracing::debug!("listening on {}", addr);
Server::bind(&addr) Server::bind(&addr).serve(app.into_make_service()).await?;
.serve(app.into_make_service())
.await
.unwrap();
Ok(()) Ok(())
} }

View file

@ -19,18 +19,18 @@ pub async fn bootstrap(State(state): State<Arc<AppState>>) -> Result<Json<Value>
.fetch_one(&state.database) .fetch_one(&state.database)
.await?; .await?;
match empty { if empty {
false => Err(AppError::ClientError { return Err(AppError::ClientError {
status: StatusCode::BAD_REQUEST, status: StatusCode::BAD_REQUEST,
code: "already-setup".to_string(), code: "already-setup".to_string(),
message: "The instance was already bootstrapped".to_string(), message: "The instance was already bootstrapped".to_string(),
}), });
true => { }
//todo add user
let username = "admin";
let password = random();
sqlx::query!( let username = "admin";
let password = random();
sqlx::query!(
r#"INSERT INTO users ( name, display_name, password, roles ) VALUES ( $1, $2, $3, $4 ) RETURNING id"#, r#"INSERT INTO users ( name, display_name, password, roles ) VALUES ( $1, $2, $3, $4 ) RETURNING id"#,
username, username,
"Administrator", "Administrator",
@ -40,7 +40,5 @@ pub async fn bootstrap(State(state): State<Arc<AppState>>) -> Result<Json<Value>
.fetch_one(&state.database) .fetch_one(&state.database)
.await?; .await?;
Ok(Json(json!({"username": username, "password": password}))) Ok(Json(json!({"username": username, "password": password})))
}
}
} }