feat: fix login redirection

This commit is contained in:
Max Hohlfeld 2024-02-04 23:30:05 +01:00
parent ba4e4af609
commit 066cc62262
3 changed files with 30 additions and 14 deletions

View File

@ -1,5 +1,5 @@
use actix_identity::Identity; use actix_identity::Identity;
use actix_web::{web, HttpMessage, HttpRequest, HttpResponse, Responder}; use actix_web::{http::header::LOCATION, web, HttpMessage, HttpRequest, HttpResponse, Responder};
use serde::Deserialize; use serde::Deserialize;
use sqlx::PgPool; use sqlx::PgPool;
@ -22,9 +22,9 @@ async fn route(
if let Some(user) = result { if let Some(user) = result {
let hash = hash_plain_password_with_salt(&form.password, &user.salt).unwrap(); let hash = hash_plain_password_with_salt(&form.password, &user.salt).unwrap();
if hash == user.password { if hash == user.password {
Identity::login(&request.extensions(), user.id.to_string()); Identity::login(&request.extensions(), user.id.to_string()).unwrap();
return HttpResponse::Ok().body("Angemeldet!"); return HttpResponse::Found().insert_header((LOCATION, "/")).finish();
} else { } else {
return HttpResponse::Unauthorized().body("Nutzername oder Passwort falsch."); return HttpResponse::Unauthorized().body("Nutzername oder Passwort falsch.");
} }

View File

@ -1,7 +1,12 @@
{% extends "nav.html" %} {% extends "nav.html" %}
{% block content %} {% block content %}
<p> <section class="section">
Content <div class="container">
</p> <h1 class="title">
Vefügbarkeit für |datum|
</h1>
</div>
</section>
{% endblock %} {% endblock %}

View File

@ -1,15 +1,26 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block body %} {% block body %}
<h1>Brass - Anmeldung</h1> <section class="section">
<p>Gib dein Nutzernamen und das Passwort ein:</p> <div class="container">
<form> <h1 class="title">Brass - Anmeldung</h1>
<label for="email">E-Mail:</label> <form class="box">
<input name="email" type="text"> <div class="field">
<label class="label" for="email">E-Mail:</label>
<div class="control">
<input class="input" placeholder="max.mustermann@example.com" name="email" type="text">
</div>
</div>
<label for="password">Passwort:</label> <div class="field">
<input name="password" type="password"> <label class="label" for="password">Passwort:</label>
<div class="control">
<input class="input" placeholder="**********" name="password" type="password">
</div>
</div>
<input type="submit" formmethod="post"> <input class="button is-primary" type="submit" value="Anmelden" formmethod="post">
</form> </form>
</div>
</section>
{% endblock %} {% endblock %}