frontend: logout and add sitekey

This commit is contained in:
realaravinth
2021-04-30 17:30:40 +05:30
parent a5cfa3b305
commit 6e63771868
17 changed files with 255 additions and 104 deletions

View File

@@ -17,6 +17,7 @@
use std::borrow::Cow;
use actix_identity::Identity;
use actix_web::http::header;
use actix_web::{get, post, web, HttpResponse, Responder};
use log::debug;
use serde::{Deserialize, Serialize};
@@ -246,12 +247,14 @@ pub async fn set_email(
Ok(HttpResponse::Ok())
}
#[post("/api/v1/signout")]
#[get("/logout")]
pub async fn signout(id: Identity) -> impl Responder {
if let Some(_) = id.identity() {
id.forget();
}
HttpResponse::Ok()
HttpResponse::TemporaryRedirect()
.set_header(header::LOCATION, "/login")
.body("")
}
/// Check if user is authenticated

View File

@@ -124,13 +124,13 @@ async fn auth_works() {
// 5. signout
let signout_resp = test::call_service(
&mut app,
test::TestRequest::post()
.uri("/api/v1/signout")
test::TestRequest::get()
.uri("/logout")
.cookie(cookies)
.to_request(),
)
.await;
assert_eq!(signout_resp.status(), StatusCode::OK);
assert_eq!(signout_resp.status(), StatusCode::TEMPORARY_REDIRECT);
}
#[actix_rt::test]