Version compilable
This commit is contained in:
commit
a1d819552a
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
/Cargo.lock
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -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"] }
|
86
src/lib.rs
Normal file
86
src/lib.rs
Normal file
@ -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<CandidateData>,
|
||||
}
|
||||
|
||||
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<i64, Role> for User {
|
||||
fn get_id(&self) -> i64 {
|
||||
self.id
|
||||
}
|
||||
fn get_password_hash(&self) -> SecretVec<u8> {
|
||||
SecretVec::new(self.ine.clone().into_bytes())
|
||||
}
|
||||
fn get_role(&self) -> Option<Role> {
|
||||
Some(self.role.clone())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user