aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/cli.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-08-09 23:27:22 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-08-09 23:27:22 +0200
commit406c7266019c0c36cfe5069bfe5cf293badd3a30 (patch)
tree1f5d054add282f45d9ff14de7a62160ff7ca31b2 /planetwars-server/src/cli.rs
parent58c1c5f9fb48040ad6b0891d586543c219de74d2 (diff)
downloadplanetwars.dev-406c7266019c0c36cfe5069bfe5cf293badd3a30.tar.xz
planetwars.dev-406c7266019c0c36cfe5069bfe5cf293badd3a30.zip
create password reset utility
Co-authored-by: Wout Schellaert <wout.schellaert@gmail.com>
Diffstat (limited to 'planetwars-server/src/cli.rs')
-rw-r--r--planetwars-server/src/cli.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/planetwars-server/src/cli.rs b/planetwars-server/src/cli.rs
new file mode 100644
index 0000000..f33506e
--- /dev/null
+++ b/planetwars-server/src/cli.rs
@@ -0,0 +1,54 @@
+extern crate planetwars_server;
+extern crate tokio;
+
+use clap::Parser;
+use planetwars_server::db;
+use planetwars_server::{create_db_pool, get_config};
+
+#[derive(clap::Parser)]
+struct Args {
+ #[clap(subcommand)]
+ action: Action,
+}
+
+#[derive(clap::Subcommand)]
+enum Action {
+ SetPassword(SetPassword),
+}
+
+impl Action {
+ async fn run(self) {
+ match self {
+ Action::SetPassword(set_password) => set_password.run().await,
+ }
+ }
+}
+
+#[derive(clap::Parser)]
+struct SetPassword {
+ #[clap(value_parser)]
+ username: String,
+
+ #[clap(value_parser)]
+ new_password: String,
+}
+
+impl SetPassword {
+ async fn run(self) {
+ let global_config = get_config().unwrap();
+ let pool = create_db_pool(&global_config).await;
+
+ let conn = pool.get().await.expect("could not get database connection");
+ let credentials = db::users::Credentials {
+ username: &self.username,
+ password: &self.new_password,
+ };
+ db::users::set_user_password(credentials, &conn).expect("could not set password");
+ }
+}
+
+#[tokio::main]
+pub async fn main() {
+ let args = Args::parse();
+ args.action.run().await;
+}