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
+65 -18

No files matched your search

+2 -18
View File
@@ -9,23 +9,7 @@
</div> </div>
</div> </div>
<form> <div id="home-page-main-block">
<div class="uk-margin"> {% include "partials/index/form.html" %}
<label>
Username
<input class="uk-input" type="text">
</label>
</div> </div>
<div class="uk-margin">
<label>
Password
<input class="uk-input" type="password">
</label>
</div>
<div class="uk-margin">
<button class="uk-button uk-button-default">Login</button>
</div>
</form>
{% endblock %} {% endblock %}
@@ -0,0 +1,21 @@
<form hx-post="/login"
hx-ext="json-enc"
hx-swap="innerHTML"
hx-target="#home-page-main-block">
<div class="uk-margin">
<label>
Username
<input class="uk-input" type="text" name="username" required>
</label>
</div>
<div class="uk-margin">
<label>
Password
<input class="uk-input" name="password" type="password">
</label>
</div>
<div class="uk-margin">
<button class="uk-button uk-button-default" type="submit">Login</button>
</div>
</form>
@@ -0,0 +1,17 @@
<div>
<p>
You are logged in as {{ name }}.
</p>
</div>
<form hx-post="/logout"
hx-ext="json-enc"
hx-swap="innerHTML"
hx-target="#home-page-main-block">
<div class="uk-margin">
<button class="uk-button uk-button-default" type="click">Logout</button>
</div>
</form>
+2
View File
@@ -103,6 +103,8 @@ pub async fn web_ui_main(connFact: SQLiteConnectionFactory,
actix_files::Files::new("/static", "./resources/static/").use_last_modified(true), actix_files::Files::new("/static", "./resources/static/").use_last_modified(true),
) )
.service(views::index) .service(views::index)
.service(views::login)
.service(views::logout)
.service(views::actions) .service(views::actions)
.service(views::overview) .service(views::overview)
.service(views::overview_submit_button) .service(views::overview_submit_button)
+23
View File
@@ -35,6 +35,29 @@ pub async fn overview(tmpl_env: MiniJinjaRenderer,
tmpl_env.render("overview.html", ctx) 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")] #[actix_web::get("/partials/overview/submit_button")]
pub async fn overview_submit_button( pub async fn overview_submit_button(
_req: HttpRequest, _req: HttpRequest,