aboutsummaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorcurly <curly@infernal.garden>2024-07-17 16:28:00 -0600
committercurly <curly@infernal.garden>2024-07-17 16:28:00 -0600
commitd8f80c973159813a5937395a0f53c042b0c738c2 (patch)
tree80262321caf5df57445d57af4e664f9dbbe5c4d9 /src/db.rs
parent2d6f29228c3379debcc9f6395a50e2f2f6a1910e (diff)
downloadpoko_server-d8f80c973159813a5937395a0f53c042b0c738c2.tar.gz
poko_server-d8f80c973159813a5937395a0f53c042b0c738c2.tar.bz2
poko_server-d8f80c973159813a5937395a0f53c042b0c738c2.zip
make new keys with admin user
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/db.rs b/src/db.rs
index 0c245cc..b173f2d 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -66,6 +66,10 @@ impl User {
User { name, is_admin: admin, hashed_password, id, tokovec: base_tokens, sessions: HashMap::new() }
}
+ pub fn is_admin(&self) -> bool {
+ self.is_admin
+ }
+
fn update_name(&mut self, new_name: String) {
self.name = new_name;
}
@@ -298,6 +302,16 @@ impl DB {
self.registration_keys.push(key.clone())
}
+ pub async fn new_registration_key(&mut self, id: UID, session: &String, key: &String) -> Result<(), String> {
+ let u = self.get_user_authenticated(id, session).await?;
+ if u.is_admin {
+ self.add_key(key);
+ self.save().await
+ } else {
+ Err("Not an admin".into())
+ }
+ }
+
pub async fn new_user(&mut self, name: String, password: String, id: UID, key: &String) -> Result<User, String> {
if self.use_key(key).await.is_ok() {
let mut is_admin = false;