Added login/logout.. except for the authentication part... that's to be done later.
This commit is contained in:
1 parent
801abed9a4
commit
0c171171c2
5 files changed
+67
-20
No files matched your search
@@ -9,23 +9,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form>
|
||||
<div class="uk-margin">
|
||||
<label>
|
||||
Username
|
||||
<input class="uk-input" type="text">
|
||||
</label>
|
||||
</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>
|
||||
|
||||
<div id="home-page-main-block">
|
||||
{% include "partials/index/form.html" %}
|
||||
</div>
|
||||
{% 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>
|
||||
|
||||
@@ -103,6 +103,8 @@ pub async fn web_ui_main(connFact: SQLiteConnectionFactory,
|
||||
actix_files::Files::new("/static", "./resources/static/").use_last_modified(true),
|
||||
)
|
||||
.service(views::index)
|
||||
.service(views::login)
|
||||
.service(views::logout)
|
||||
.service(views::actions)
|
||||
.service(views::overview)
|
||||
.service(views::overview_submit_button)
|
||||
|
||||
+24
-1
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user