Set token as cookie
parent
d78871a4dd
commit
de0d7c2b43
|
@ -49,17 +49,16 @@ Whenever user sends a message, client will send message & token and backend will
|
||||||
## To-Do:
|
## To-Do:
|
||||||
|
|
||||||
- [x] Basic auth API
|
- [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"
|
- "status" shows wether request was succesful or not, either "ok" or "fail"
|
||||||
- "reason" is for more details, mainly just for debugging?
|
- "reason" is for more details, mainly just for debugging?
|
||||||
- [x] Basic messaging system
|
- [x] Basic messaging system
|
||||||
- [x] Finish up `chat::create_message()`
|
- [x] Finish up `chat::create_message()`
|
||||||
- [x] Create `chat::fetch_messages()`
|
- [x] Create `chat::fetch_messages()`
|
||||||
- [ ] Create `chat::delete_message()`
|
- [ ] Create `chat::delete_message()`
|
||||||
- [ ] Token generation & storage
|
- [x] Token generation & storage
|
||||||
- [ ] API to refresh token
|
- [x] Sets cookie
|
||||||
- [ ] Store token in json
|
- [x] Store token in json
|
||||||
- [ ] API to check token?
|
|
||||||
- [x] Pronouns
|
- [x] Pronouns
|
||||||
- [x] Set pronouns
|
- [x] Set pronouns
|
||||||
- [ ] Change pronouns
|
- [ ] Change pronouns
|
||||||
|
|
|
@ -73,12 +73,13 @@ fn create_token(name: String, mut users: Vec<User>) -> String {
|
||||||
return token;
|
return token;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
warn!("something bad happened while creating a token and idk what");
|
||||||
return "NULL".to_string();
|
return "NULL".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if pin matches user
|
// Check if pin matches user
|
||||||
#[get("/users/<name>/<pin>")]
|
#[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 users: Vec<User> = read_json();
|
||||||
let hashed_pin_input = sha1::Sha1::from(&pin.to_string()).digest().to_string();
|
let hashed_pin_input = sha1::Sha1::from(&pin.to_string()).digest().to_string();
|
||||||
for i in &users {
|
for i in &users {
|
||||||
|
@ -87,6 +88,10 @@ pub fn check_pin(name: String, pin: i32) -> JsonValue {
|
||||||
if i.pin_hashed == hashed_pin_input {
|
if i.pin_hashed == hashed_pin_input {
|
||||||
info!("pin correct for user {}", i.name);
|
info!("pin correct for user {}", i.name);
|
||||||
// Create token for user & set a cookie
|
// 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!({
|
return json!({
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
"reason": "pin matches",
|
"reason": "pin matches",
|
||||||
|
|
Loading…
Reference in New Issue