users: add a route to fetch the user from cookie
Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
parent
beaca24246
commit
28fe55b8db
@ -4,6 +4,7 @@ use rocket::{
|
||||
response::status,
|
||||
Rocket,
|
||||
};
|
||||
use rocket::http::Cookies;
|
||||
use rocket::response::status::Custom;
|
||||
use rocket_contrib::json::Json;
|
||||
use serde_json::Value;
|
||||
@ -12,6 +13,7 @@ use crate::api::catchers::{internal_server_error, unprocessable_entity};
|
||||
use crate::api::guards::db::DbConn;
|
||||
use crate::core::users::entity::User;
|
||||
use crate::core::users::service::{activate_user, create_or_fetch_user, fetch_user};
|
||||
use crate::utils::users::get_session_id;
|
||||
|
||||
#[post("/", data = "<user>")]
|
||||
fn activate(mut user: Json<User>, conn: DbConn) -> Custom<Json<Value>> {
|
||||
@ -45,6 +47,12 @@ fn fetch(id: String, conn: DbConn) -> Result<Json<User>> {
|
||||
Ok(Json(fetch_user(id, &conn)?))
|
||||
}
|
||||
|
||||
pub fn fuel(rocket: Rocket) -> Rocket {
|
||||
rocket.mount("/api/user", routes![activate, fetch])
|
||||
#[get("/me")]
|
||||
fn fetch_me(conn: DbConn, mut ck: Cookies) -> Result<Json<User>> {
|
||||
let id = get_session_id(&mut ck);
|
||||
Ok(Json(fetch_user(id, &conn)?))
|
||||
}
|
||||
|
||||
pub fn fuel(rocket: Rocket) -> Rocket {
|
||||
rocket.mount("/api/user", routes![activate, fetch, fetch_me])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user