Set token as cookie

pull/5/head
~erin 2021-07-18 13:26:26 -04:00
parent d78871a4dd
commit de0d7c2b43
Signed by: erin
GPG Key ID: DA70E064A8C70F44
2 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -73,12 +73,13 @@ fn create_token(name: String, mut users: Vec<User>) -> 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/<name>/<pin>")]
pub fn check_pin(name: String, pin: i32) -> JsonValue {
pub fn check_pin(mut cookies: Cookies, name: String, pin: i32) -> JsonValue {
let users: Vec<User> = 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",