UserAuthenticator: propagate token creation errors
This commit is contained in:
parent
51865c365c
commit
3657d83bd1
1 changed files with 9 additions and 5 deletions
14
src/auth.rs
14
src/auth.rs
|
@ -43,16 +43,20 @@ impl UserAuthenticator {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
pub async fn create_user_token(&mut self, username: &str, password: &Password) -> UserToken {
|
pub async fn create_user_token(
|
||||||
|
&mut self,
|
||||||
|
username: &str,
|
||||||
|
password: &Password,
|
||||||
|
) -> Result<UserToken, AuthenticationError> {
|
||||||
|
// TODO: validate password
|
||||||
|
|
||||||
let new_token =
|
let new_token =
|
||||||
UserToken::from(Alphanumeric.sample_string(&mut thread_rng(), Self::TOKEN_LEN));
|
UserToken::from(Alphanumeric.sample_string(&mut thread_rng(), Self::TOKEN_LEN));
|
||||||
|
|
||||||
let mut db = self.db.lock().await;
|
let mut db = self.db.lock().await;
|
||||||
if let Err(err) = db.save_token(username, &new_token).await {
|
db.save_token(username, &new_token).await?;
|
||||||
event!(Level::ERROR, %err, "Failed to save token in database");
|
|
||||||
}
|
|
||||||
|
|
||||||
new_token
|
Ok(new_token)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
|
|
Loading…
Reference in a new issue