1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

mas-cli manage set-password subcommand

This commit is contained in:
Quentin Gliech
2022-12-02 16:25:36 +01:00
parent 2e7112ef13
commit df83cdc9a1

View File

@ -21,6 +21,7 @@ use mas_storage::{
oauth2::client::{insert_client_from_config, lookup_client, truncate_clients},
user::{
lookup_user_by_username, lookup_user_email, mark_user_email_as_verified, register_user,
set_password,
},
Clock, LookupError,
};
@ -143,9 +144,6 @@ enum Subcommand {
/// Register a new user
Register { username: String, password: String },
/// List active users
Users,
/// Mark email address as verified
VerifyEmail { username: String, email: String },
@ -156,6 +154,9 @@ enum Subcommand {
truncate: bool,
},
/// Set a user password
SetPassword { username: String, password: String },
/// Add an OAuth 2.0 upstream
#[command(name = "add-oauth-upstream")]
AddOAuthUpstream {
@ -203,13 +204,21 @@ impl Options {
let user =
register_user(&mut txn, &mut rng, &clock, hasher, username, password).await?;
txn.commit().await?;
info!(?user, "User registered");
info!(user.id = %user.data, %user.username, "User registered");
Ok(())
}
SC::Users => {
warn!("Not implemented yet");
SC::SetPassword { username, password } => {
let config: DatabaseConfig = root.load_config()?;
let pool = config.connect().await?;
let mut txn = pool.begin().await?;
let hasher = Argon2::default();
let user = lookup_user_by_username(&mut txn, username).await?;
set_password(&mut txn, &mut rng, &clock, hasher, &user, password).await?;
info!(user.id = %user.data, %user.username, "Password changed");
txn.commit().await?;
Ok(())
}