aboutsummaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/db.rs b/src/db.rs
index 28b1ec7..43a9f9c 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -18,7 +18,7 @@ impl Config {
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
-enum Color {
+pub enum Color {
White,
Red,
Blue,
@@ -27,7 +27,7 @@ enum Color {
}
#[derive(Debug, Serialize, Deserialize, Clone)]
-struct Token {
+pub struct Token {
color: Color,
amount: usize,
}
@@ -130,6 +130,9 @@ impl User {
pub fn hex_id(&self) -> String {
self.id.to_hex()
}
+ pub fn get_tokovec(&self) -> Vec<Token> {
+ self.tokovec.clone()
+ }
}
#[derive(Serialize, Deserialize)]
@@ -190,6 +193,18 @@ impl DB {
Err("Not Found".into())
}
+ pub async fn get_user_authenticated(&self, id: &str, session: &String) -> Result<&User, String> {
+ match self.get_user(id).await {
+ Ok(u) => {
+ if u.authenticate(session) {
+ Ok(u)
+ } else {
+ Err("Not Authenticated".into())
+ }
+ },
+ Err(n) => Err(n)
+ }
+ }
pub async fn get_mut_user(&mut self, id: &str) -> Result<&mut User, String> {
match UID::from(id.to_string()) {
Ok(n) => {