Added login/logout.. except for the authentication part... that's to be done later.

This commit is contained in:
didier amyot committed 2023-02-25 22:08:13 -05:00
1 parent 801abed9a4
commit 0c171171c2
5 files changed
+67 -20

No files matched your search

+24 -1
View File
@@ -26,7 +26,7 @@ pub async fn actions(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Resp
pub async fn overview(tmpl_env: MiniJinjaRenderer,
connFactory: web::Data<SQLiteConnectionFactory>) -> actix_web::Result<impl Responder> {
let conn = connFactory.readonly().unwrap(); // todo; to proper 500
let service_factory = ServiceFactory::new(& conn);
let service_factory = ServiceFactory::new(&conn);
let user_service = service_factory.get_user_service();
let users = user_service.list_users().unwrap();
let ctx = context! {
@@ -35,6 +35,29 @@ pub async fn overview(tmpl_env: MiniJinjaRenderer,
tmpl_env.render("overview.html", ctx)
}
#[derive(Deserialize, Debug)]
struct LoginPayload {
username: String,
password: String,
}
#[actix_web::post("/login")]
pub async fn login(tmpl_env: MiniJinjaRenderer,
web::Json(form): web::Json<LoginPayload>) -> actix_web::Result<impl Responder> {
let ctx = context! {
name => form.username,
};
tmpl_env.render("partials/index/success.html", ctx)
}
#[actix_web::post("/logout")]
pub async fn logout(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Responder> {
let ctx = context! {};
let res = tmpl_env.render("partials/index/form.html", ctx)?;
Ok(res.customize().insert_header(("Set-Cookie", "username=nobody")))
}
#[actix_web::get("/partials/overview/submit_button")]
pub async fn overview_submit_button(
_req: HttpRequest,