diff --git a/README.md b/README.md index ef84d26..c836df7 100644 --- a/README.md +++ b/README.md @@ -49,17 +49,16 @@ Whenever user sends a message, client will send message & token and backend will ## To-Do: - [x] Basic auth API -- [ ] Return json instead of string +- [x] Return json instead of string - "status" shows wether request was succesful or not, either "ok" or "fail" - "reason" is for more details, mainly just for debugging? - [x] Basic messaging system - [x] Finish up `chat::create_message()` - [x] Create `chat::fetch_messages()` - [ ] Create `chat::delete_message()` -- [ ] Token generation & storage - - [ ] API to refresh token - - [ ] Store token in json - - [ ] API to check token? +- [x] Token generation & storage + - [x] Sets cookie + - [x] Store token in json - [x] Pronouns - [x] Set pronouns - [ ] Change pronouns diff --git a/src/auth.rs b/src/auth.rs index c5628d2..22086db 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -73,12 +73,13 @@ fn create_token(name: String, mut users: Vec) -> String { return token; }; }; + warn!("something bad happened while creating a token and idk what"); return "NULL".to_string(); } // Check if pin matches user #[get("/users//")] -pub fn check_pin(name: String, pin: i32) -> JsonValue { +pub fn check_pin(mut cookies: Cookies, name: String, pin: i32) -> JsonValue { let users: Vec = read_json(); let hashed_pin_input = sha1::Sha1::from(&pin.to_string()).digest().to_string(); for i in &users { @@ -87,6 +88,10 @@ pub fn check_pin(name: String, pin: i32) -> JsonValue { if i.pin_hashed == hashed_pin_input { info!("pin correct for user {}", i.name); // Create token for user & set a cookie + let token = create_token(i.name.clone(), users); + cookies.add(Cookie::new("token", token)); + info!("set the token cookie"); + return json!({ "status": "ok", "reason": "pin matches",