From 1a973bfbc68dfea26a8b5360074480641cb34f31 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch <p.jentsch@uni-bielefeld.de>
Date: Mon, 8 Jul 2019 13:56:09 +0200
Subject: [PATCH] Add page for password reset.

---
 app/auth/views.py                         | 12 ++++++++++--
 app/templates/auth/reset_password.html.j2 | 20 +++++++++++++-------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/app/auth/views.py b/app/auth/views.py
index 417aae50..b14e5fb9 100644
--- a/app/auth/views.py
+++ b/app/auth/views.py
@@ -1,5 +1,5 @@
 from flask import flash, redirect, render_template, request, url_for
-from flask_login import login_required, login_user, logout_user
+from flask_login import current_user, login_required, login_user, logout_user
 from . import auth
 from .. import db
 from .forms import LoginForm, PasswordResetRequestForm, RegistrationForm
@@ -45,6 +45,8 @@ def register():
 
 @auth.route('/reset', methods=['GET', 'POST'])
 def password_reset_request():
+    if not current_user.is_anonymous:
+        return redirect(url_for('main.index'))
     form = PasswordResetRequestForm()
     if form.validate_on_submit():
         user = User.query.filter_by(email=form.email.data.lower()).first()
@@ -56,4 +58,10 @@ def password_reset_request():
         flash('An email with instructions to reset your password has been '
               'sent to you.')
         return redirect(url_for('auth.login'))
-    return render_template('auth/reset_password.html.j2', form=form, title='Password Reset')
+    return render_template('auth/reset_password.html.j2', form=form,
+                           title='Password Reset')
+
+
+@auth.route('/reset/<token>')
+def password_reset(token):
+    return 'test'
diff --git a/app/templates/auth/reset_password.html.j2 b/app/templates/auth/reset_password.html.j2
index 782a1f77..bb9cfe74 100644
--- a/app/templates/auth/reset_password.html.j2
+++ b/app/templates/auth/reset_password.html.j2
@@ -1,14 +1,20 @@
 {% extends "base.html.j2" %}
 
 {% block page_content %}
-<div class="col s12 m6 offset-m3">
-  <div class="card medium">
+<div class="col s12 m8 offset-m2">
+  <div class="card small">
     <div class="card-content">
-      <p>Sign in into an exisiting account or register a new one!</p>
-      <br>
-    <div class="card-action">
-      <a class="btn" href="{{url_for('auth.register')}}">Register</a>
-    </div>
+      <span class="card-title">Reset Your Password</span>
+      <form method="POST">
+        {{ form.hidden_tag() }}
+        <div class="input-field">
+          {{ form.email(class='validate', type='email') }}
+          {{ form.email.label }}
+        </div>
+        <div class="card-action">
+          {{ form.submit(class='btn right') }}
+        </div>
+      </form>
     </div>
   </div>
 </div>
-- 
GitLab