This repository has been archived by the owner on Apr 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_session.rs
45 lines (44 loc) · 1.73 KB
/
delete_session.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use super::{
defaults,
structs::{Response, ResponseTypes},
};
use crate::library::security::{disconnect, get_token, mail_from_token, validate_token};
use actix_web::{HttpRequest, HttpResponse};
use actix_web_codegen::delete;
/**
* @todo Generate SA Certs
*/
#[delete("/session")]
pub fn sync_post_logout(req: HttpRequest) -> actix_web::Result<HttpResponse> {
Ok(match get_token(req.headers()) {
Ok(x) => match validate_token(x.clone().as_str()) {
Ok(v) => {
if v {
match mail_from_token(x.clone()) {
Ok(x) => match disconnect(x.as_str()) {
Ok(x) => {
if x {
response!(
Ok,
Response::ok(
200,
ResponseTypes::PlainText("disconnecting".to_owned())
)
)
} else {
response!(InternalServerError, defaults::ERROR_403)
}
}
Err(_) => response!(InternalServerError, defaults::ERROR_500),
},
Err(_) => response!(InternalServerError, defaults::ERROR_500),
}
} else {
response!(Unauthorized, defaults::ERROR_401)
}
}
Err(_) => response!(Unauthorized, defaults::ERROR_401),
},
Err(_) => response!(BadRequest, defaults::ERROR_400),
})
}