Added logout feature
This commit is contained in:
16
src/main.rs
16
src/main.rs
@@ -3,7 +3,7 @@
|
||||
use futures_util::{SinkExt, StreamExt};
|
||||
use poem::{
|
||||
//get,
|
||||
handler, //Result,
|
||||
handler,
|
||||
listener::TcpListener,
|
||||
session::{CookieConfig, MemoryStorage, ServerSession, Session},
|
||||
web::{
|
||||
@@ -12,6 +12,7 @@ use poem::{
|
||||
},
|
||||
EndpointExt,
|
||||
IntoResponse,
|
||||
Result,
|
||||
Route,
|
||||
Server,
|
||||
};
|
||||
@@ -222,6 +223,12 @@ impl Api {
|
||||
UserResponse::AuthError
|
||||
}
|
||||
}
|
||||
#[oai(path = "/auth", method = "delete", tag = "ApiTags::User")]
|
||||
async fn deauth_user(&self, session: &Session) -> Result<()> {
|
||||
session.purge();
|
||||
Result::Ok(())
|
||||
}
|
||||
|
||||
#[oai(path = "/auth", method = "post", tag = "ApiTags::User")]
|
||||
async fn auth_user(&self, user: Json<UserLogin>, session: &Session) -> UserResponse {
|
||||
let password = user.password.as_str();
|
||||
@@ -249,10 +256,11 @@ impl Api {
|
||||
if let None = session.get::<String>("user") {
|
||||
return NumResponse::AuthError;
|
||||
}
|
||||
match session.get("num") {
|
||||
match session.get::<u32>("num") {
|
||||
Some(i) => {
|
||||
session.set("num", i + 1);
|
||||
NumResponse::Ok(Json(i))
|
||||
let new: u32 = i + 1;
|
||||
session.set("num", new);
|
||||
NumResponse::Ok(Json(new))
|
||||
}
|
||||
None => {
|
||||
session.set("num", 1_u32);
|
||||
|
||||
Reference in New Issue
Block a user