Add page for password reset.

This commit is contained in:
Patrick Jentsch 2019-07-08 13:56:09 +02:00
parent 4ef5b480b1
commit 1a973bfbc6
2 changed files with 23 additions and 9 deletions

View File

@ -1,5 +1,5 @@
from flask import flash, redirect, render_template, request, url_for 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 auth
from .. import db from .. import db
from .forms import LoginForm, PasswordResetRequestForm, RegistrationForm from .forms import LoginForm, PasswordResetRequestForm, RegistrationForm
@ -45,6 +45,8 @@ def register():
@auth.route('/reset', methods=['GET', 'POST']) @auth.route('/reset', methods=['GET', 'POST'])
def password_reset_request(): def password_reset_request():
if not current_user.is_anonymous:
return redirect(url_for('main.index'))
form = PasswordResetRequestForm() form = PasswordResetRequestForm()
if form.validate_on_submit(): if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data.lower()).first() 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 ' flash('An email with instructions to reset your password has been '
'sent to you.') 'sent to you.')
return redirect(url_for('auth.login')) 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'

View File

@ -1,14 +1,20 @@
{% extends "base.html.j2" %} {% extends "base.html.j2" %}
{% block page_content %} {% block page_content %}
<div class="col s12 m6 offset-m3"> <div class="col s12 m8 offset-m2">
<div class="card medium"> <div class="card small">
<div class="card-content"> <div class="card-content">
<p>Sign in into an exisiting account or register a new one!</p> <span class="card-title">Reset Your Password</span>
<br> <form method="POST">
<div class="card-action"> {{ form.hidden_tag() }}
<a class="btn" href="{{url_for('auth.register')}}">Register</a> <div class="input-field">
</div> {{ form.email(class='validate', type='email') }}
{{ form.email.label }}
</div>
<div class="card-action">
{{ form.submit(class='btn right') }}
</div>
</form>
</div> </div>
</div> </div>
</div> </div>