From a1d819552a7036dac89dbc16756de50adb44539c Mon Sep 17 00:00:00 2001 From: Yann Date: Fri, 5 May 2023 11:34:42 +0200 Subject: [PATCH] Version compilable --- .gitignore | 2 ++ Cargo.toml | 10 +++++++ src/lib.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fffb2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d567907 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "ProjectF" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +axum-login = "0.5.0" +serde = { version = "1.0.160", features = ["derive"] } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..4e09ec6 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,86 @@ +use serde::{Deserialize, Serialize}; +use axum_login::{ + AuthUser, + secrecy::SecretVec, +}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum LoginState { + Initial, + // Loading, + Success, + Error, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, PartialOrd)] +pub enum Role { + Unknown, + Candidate, + Admin, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Login { + pub email: String, + pub ine: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct User { + pub id: i64, + pub email: String, + pub email_validated: bool, + pub ine: String, + pub state: LoginState, + pub role: Role, + pub candidate_data: Option, +} + +impl User { + pub fn new() -> Self { + Self { + id: 0, + email: "".to_string(), + email_validated: false, + ine: "".to_string(), + state: LoginState::Initial, + role: Role::Unknown, + candidate_data: None, + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CandidateData { + pub firstname: String, +} + +impl CandidateData { + pub fn new() -> Self { + Self { + firstname: "".to_string(), + } + } +} + +impl Login { + pub fn new() -> Self { + Self { + email: "".to_string(), + ine: "".to_string(), + } + } +} + +impl AuthUser for User { + fn get_id(&self) -> i64 { + self.id + } + fn get_password_hash(&self) -> SecretVec { + SecretVec::new(self.ine.clone().into_bytes()) + } + fn get_role(&self) -> Option { + Some(self.role.clone()) + } +} +