Skip to content

Commit

Permalink
Merge pull request #4 from Xila-Project/Feature/Users
Browse files Browse the repository at this point in the history
A beginning
  • Loading branch information
AlixANNERAUD authored Dec 25, 2023
2 parents f8a5ba9 + fd3f166 commit 8158a06
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Users/Manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use super::*;
use std::{
collections::HashMap,
sync::{Arc, RwLock},
};

struct Internal_user_type {
pub Name: String,
}

pub struct Manager_type {
Users: Arc<RwLock<HashMap<Identifier_type, Internal_user_type>>>,
}

impl Manager_type {
pub fn New() -> Self {
Self {
Users: Arc::new(RwLock::new(HashMap::new())),
}
}

pub fn Get_user_name(&self, Identifier: Identifier_type) -> Option<String> {
let Users = self.Users.read().unwrap();
Some(Users.get(&Identifier).unwrap().Name.clone())
}

pub fn Check_credentials(&self, User_name: &str, Password: &str) -> bool {
true
}
}
19 changes: 19 additions & 0 deletions src/Users/User.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use super::*;

pub struct User_type<'a> {
User_manager: &'a Manager_type,
Identifier: Identifier_type,
}

impl<'a> User_type<'a> {
pub fn New(User_manager: &'a Manager_type, Identifier: Identifier_type) -> Self {
User_type {
User_manager,
Identifier,
}
}

pub fn Get_name(&self) -> String {
self.User_manager.Get_user_name(self.Identifier).unwrap()
}
}
7 changes: 7 additions & 0 deletions src/Users/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Identifier_type = u8;

mod Manager;
pub use Manager::*;

mod User;
pub use User::*;
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, alway
mod Graphics;
mod Screen;
mod File_system;
mod Users;

fn main() {
// It is necessary to call this function once. Otherwise some patches to the runtime
Expand Down

0 comments on commit 8158a06

Please sign in to comment.