feat: option to add a corresponding owner when creating users in CLI
This commit is contained in:
parent
2cddc4e7a8
commit
af579811a9
1 changed files with 17 additions and 3 deletions
|
|
@ -1,11 +1,11 @@
|
|||
use std::{fmt::Display, sync::Arc};
|
||||
|
||||
use argon2::{password_hash::{SaltString}, Argon2, PasswordHasher};
|
||||
use inquire::{min_length, Confirm, Password, Select, Text};
|
||||
use inquire::{min_length, prompt_text, Confirm, Password, Select, Text};
|
||||
use password_hash::rand_core::OsRng;
|
||||
use sea_orm::{ActiveModelTrait, ActiveValue::{NotSet, Set}, ColumnTrait, DatabaseConnection, EntityTrait, ModelTrait, QueryFilter};
|
||||
|
||||
use crate::entities::{prelude::User, user::{self, ActiveModel}};
|
||||
use crate::entities::{owner, prelude::User, user::{self, ActiveModel}};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
enum Action {
|
||||
|
|
@ -66,7 +66,21 @@ pub async fn manage_users(db: Arc<DatabaseConnection>) {
|
|||
username: Set(username),
|
||||
hashed_password: Set(hash_password(password))
|
||||
};
|
||||
let _ = new_user.insert(db.as_ref()).await;
|
||||
let res = new_user.insert(db.as_ref()).await.unwrap();
|
||||
|
||||
if Confirm::new("Add an owner corresponding to this user ?").with_default(true).prompt().is_ok_and(|choice| choice==true) {
|
||||
let first_name = prompt_text("First Name: ").unwrap();
|
||||
let last_name = prompt_text("Last Name: ").unwrap();
|
||||
let contact = prompt_text("Contact: ").unwrap();
|
||||
let new_owner = owner::ActiveModel {
|
||||
id: NotSet,
|
||||
user_id: Set(res.id),
|
||||
first_name: Set(first_name),
|
||||
last_name: Set(last_name),
|
||||
contact: Set(contact)
|
||||
};
|
||||
let _ = new_owner.insert(db.as_ref()).await.unwrap();
|
||||
}
|
||||
}
|
||||
},
|
||||
Action::Delete => {
|
||||
|
|
|
|||
Reference in a new issue