feat(admin): create and list users commands

This commit is contained in:
Matthieu Bessat 2024-12-03 13:20:33 +01:00
parent 8d20cab18f
commit a0de3b287b
19 changed files with 314 additions and 30 deletions

View file

@ -2,6 +2,8 @@ use fully_pub::fully_pub;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::types::Json;
use utils::get_random_human_token;
use uuid::Uuid;
#[derive(sqlx::Type, Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(strum_macros::Display)]
@ -30,3 +32,30 @@ struct User {
last_login_at: Option<DateTime<Utc>>,
created_at: DateTime<Utc>
}
impl User {
pub fn new(
handle: String
) -> User {
User {
id: Uuid::new_v4().to_string(),
handle,
full_name: None,
email: None,
website: None,
picture: None,
password_hash: None,
status: UserStatus::Disabled,
roles: Json(Vec::new()),
reset_password_token: None,
last_login_at: None,
created_at: Utc::now()
}
}
pub fn invite(self: &mut Self) {
self.reset_password_token = Some(get_random_human_token());
self.status = UserStatus::Invited;
}
}