Replace type UserID with a structure

This commit is contained in:
2022-04-19 19:40:36 +02:00
parent feb6db09b9
commit 94aeefe450
8 changed files with 17 additions and 15 deletions

@ -20,7 +20,7 @@ impl Default for SessionStatus {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct SessionIdentityData {
pub id: UserID,
pub id: Option<UserID>,
pub is_admin: bool,
pub auth_time: u64,
pub status: SessionStatus,
@ -48,7 +48,7 @@ impl<'a> SessionIdentity<'a> {
// Check if session is valid
if let Some(sess) = &res {
if sess.id.is_empty() {
if sess.id.is_none() {
return None;
}
}
@ -64,7 +64,7 @@ impl<'a> SessionIdentity<'a> {
pub fn set_user(&self, user: &User) {
self.set_session_data(&SessionIdentityData {
id: user.uid.clone(),
id: Some(user.uid.clone()),
is_admin: user.admin,
auth_time: time(),
status: SessionStatus::SignedIn,
@ -101,6 +101,7 @@ impl<'a> SessionIdentity<'a> {
pub fn user_id(&self) -> UserID {
self.get_session_data().unwrap_or_default().id
.expect("UserID should never be null here!")
}
pub fn auth_time(&self) -> u64 {

@ -4,7 +4,8 @@ use crate::data::login_redirect::LoginRedirect;
use crate::data::totp_key::TotpKey;
use crate::utils::err::Res;
pub type UserID = String;
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct UserID(pub String);
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct FactorID(pub String);
@ -101,7 +102,7 @@ impl Eq for User {}
impl Default for User {
fn default() -> Self {
Self {
uid: uuid::Uuid::new_v4().to_string(),
uid: UserID(uuid::Uuid::new_v4().to_string()),
first_name: "".to_string(),
last_name: "".to_string(),
username: "".to_string(),