summaryrefslogtreecommitdiff
path: root/src/persist.rs
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2022-11-11 09:56:48 -0500
committertylermurphy534 <tylermurphy534@gmail.com>2022-11-11 09:56:48 -0500
commitde24d5499ac83f426228b28b90bed8f26e68fb3b (patch)
tree7a37f98005e8337d078db9edf1fec89de4a98f04 /src/persist.rs
parentupdate config format (diff)
downloadcrab-de24d5499ac83f426228b28b90bed8f26e68fb3b.tar.gz
crab-de24d5499ac83f426228b28b90bed8f26e68fb3b.tar.bz2
crab-de24d5499ac83f426228b28b90bed8f26e68fb3b.zip
doc string, refactor, config token error
Diffstat (limited to 'src/persist.rs')
-rw-r--r--src/persist.rs28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/persist.rs b/src/persist.rs
index 762d8b1..2bca386 100644
--- a/src/persist.rs
+++ b/src/persist.rs
@@ -28,7 +28,7 @@ pub fn get_persist(user: &str) -> bool {
}
-/// Updates the current sessions persist file
+/// Updates a user in the current sessions persist file
/// #### Arguments
/// * `user` - The user to set persisted
pub fn set_persist(user: &str) {
@@ -43,8 +43,30 @@ pub fn set_persist(user: &str) {
};
match secure::write_file(PERSIST_PATH, &format!("{}", session), &json.to_string()) {
Ok(_) => {},
- Err(e) => {
- eprintln!("crab: An Internal Has Error: {}", e);
+ Err(_) => {
+ eprintln!("crab: An internal error has occured");
+ }
+ };
+}
+
+
+/// Removes a user from the current sessions persist file
+/// #### Arguments
+/// * `user` - The user to set non-persisted
+pub fn remove_persist(user: &str) {
+ let mut json = match get_persist_config() {
+ Some(data) => data,
+ None => return
+ };
+ json[user] = Value::from(0);
+ let session = match get_current_session() {
+ Some(data) => data,
+ None => return
+ };
+ match secure::write_file(PERSIST_PATH, &format!("{}", session), &json.to_string()) {
+ Ok(_) => {},
+ Err(_) => {
+ eprintln!("crab: An internal error has occured");
}
};
}