Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCoduriV committed Jan 27, 2023
1 parent 2901771 commit d0b42b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.
Binary file modified db.json
Binary file not shown.
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ fn welcome() {
}

fn ask_creds() -> Result<AccountType, AuthError> {
println!("Are you a teacher or a student");
let choice = input().inside(['t', 's']).get();
let choice = input().inside(['t', 's']).msg("Are you a teacher or a student ? t/s: ").get();
let is_teacher = choice == 't';

println!("Enter your username:");
Expand Down
61 changes: 25 additions & 36 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,49 @@ use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
pub struct Teacher {
pub(crate) creds: Credentials,
pub creds: Credentials,
}

#[derive(Serialize, Deserialize)]
pub struct Student {
pub(crate) creds: Credentials,
pub creds: Credentials,
pub grades: Vec<f32>,
}

#[derive(Serialize, Deserialize)]
pub(crate) struct Credentials {
pub(crate) username: String,
pub(crate) password: String,
pub struct Credentials {
pub username: String,
pub password: String,
}

pub trait User {
fn get_username(&self) -> String;
fn get_password(&self) -> String;
fn set_username(&mut self, username:&str);
fn set_password(&mut self, password:&str);
fn set_username(&mut self, username: &str);
fn set_password(&mut self, password: &str);
}

impl User for Teacher {
fn get_username(&self) -> String {
self.creds.username.clone()
}
macro_rules! impl_user_trait {
($a:ty)=>{
impl User for $a {
fn get_username(&self) -> String {
self.creds.username.clone()
}

fn get_password(&self) -> String {
self.creds.password.clone()
}
fn get_password(&self) -> String {
self.creds.password.clone()
}

fn set_username(&mut self, username: &str) {
self.creds.username = String::from(username);
}
fn set_username(&mut self, username: &str) {
self.creds.username = String::from(username);
}

fn set_password(&mut self, password: &str) {
self.creds.password = String::from(password);
fn set_password(&mut self, password: &str) {
self.creds.password = String::from(password);
}
}
}
}

impl User for Student {
fn get_username(&self) -> String {
self.creds.username.clone()
}

fn get_password(&self) -> String {
self.creds.password.clone()
}

fn set_username(&mut self, username: &str) {
self.creds.username = String::from(username);
}

fn set_password(&mut self, password: &str) {
self.creds.password = String::from(password);
}
}
impl_user_trait!(Student);
impl_user_trait!(Teacher);

0 comments on commit d0b42b1

Please sign in to comment.