From 37765c755a609f56506bd9323fd665e5184cfce2 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 9 Jul 2019 13:40:33 +0200 Subject: [PATCH 1/4] Rename profile to account and enable password change. --- app/auth/views.py | 14 ++++++++------ .../auth/{profile.html.j2 => account.html.j2} | 3 ++- app/templates/base.html.j2 | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) rename app/templates/auth/{profile.html.j2 => account.html.j2} (88%) diff --git a/app/auth/views.py b/app/auth/views.py index b09c1f5d..48b861b6 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -125,9 +125,9 @@ def password_reset(token): title='Password Reset') -@auth.route('/profile', methods=['GET', 'POST']) +@auth.route('/account', methods=['GET', 'POST']) @login_required -def profile(): +def account(): form = ChangeProfileForm() if form.validate_on_submit(): flash('It is just a test, nothing changed.') @@ -138,8 +138,10 @@ def profile(): current_user.email = form.email.data current_user.confirmed = False db.session.add(current_user) + resend_confirmation() + if form.password.data: + current_user.password = form.password.data db.session.commit() - resend_confirmation() - return redirect(url_for('auth.profile')) - return render_template('auth/profile.html.j2', form=form, - title='Profile') + return redirect(url_for('auth.account')) + return render_template('auth/account.html.j2', form=form, + title='Account') diff --git a/app/templates/auth/profile.html.j2 b/app/templates/auth/account.html.j2 similarity index 88% rename from app/templates/auth/profile.html.j2 rename to app/templates/auth/account.html.j2 index 5d81a6c3..0b5c33b7 100644 --- a/app/templates/auth/profile.html.j2 +++ b/app/templates/auth/account.html.j2 @@ -4,13 +4,14 @@
- Change profile + Change account information
{{ form.hidden_tag() }}
email {{ form.email(type='email', placeholder=current_user.email) }} {{ form.email.label }} + When changing your e-mail adress you will have to reconfirm it. {% for error in form.email.errors %} {{ error }} {% endfor %} diff --git a/app/templates/base.html.j2 b/app/templates/base.html.j2 index d34c0e25..735fa99c 100644 --- a/app/templates/base.html.j2 +++ b/app/templates/base.html.j2 @@ -20,7 +20,7 @@
-
- Log In -
+ +
+ Log In {{ form.hidden_tag() }}
person {{ form.login(class='validate') }} {{ form.login.label }} + {% for error in form.login.errors %} + {{ error }} + {% endfor %}
vpn_key {{ form.password(class='validate') }} {{ form.password.label }} + {% for error in form.password.errors %} + {{ error }} + {% endfor %}
Forgot Password? -
- {{ form.submit(class='btn right') }} -
- -
+
+
+ {{ form.submit(class='btn right') }} +
+
{% endblock %} diff --git a/app/templates/auth/register.html.j2 b/app/templates/auth/register.html.j2 index 52070a1a..ab72f1db 100644 --- a/app/templates/auth/register.html.j2 +++ b/app/templates/auth/register.html.j2 @@ -2,10 +2,10 @@ {% block page_content %}
-
-
- Register -
+
+ +
+ Register {{ form.hidden_tag() }}
account_circle @@ -39,11 +39,11 @@ {{ error }} {% endfor %}
-
- {{ form.submit(class='btn right') }} -
- -
+
+
+ {{ form.submit(class='btn') }} +
+
{% endblock %} diff --git a/app/templates/auth/reset_password.html.j2 b/app/templates/auth/reset_password.html.j2 index e545e464..d73b533e 100644 --- a/app/templates/auth/reset_password.html.j2 +++ b/app/templates/auth/reset_password.html.j2 @@ -2,18 +2,18 @@ {% block page_content %}
-
-
- Reset Your Password -
+
+ +
+ Reset Your Password {{ form.hidden_tag() }} - {% if form.email is defined %}
{{ form.email(class='validate', type='email') }} {{ form.email.label }} + {% for error in form.email.errors %} + {{ error }} + {% endfor %}
- {% endif %} - {% if form.password is defined %}
{{ form.password(class='validate', type='password') }} {{ form.password.label }} @@ -21,18 +21,18 @@ {{ error }} {% endfor %}
- {% endif %} - {% if form.password2 is defined %}
{{ form.password2(class='validate', type='password') }} {{ form.password2.label }} + {% for error in form.password2.errors %} + {{ error }} + {% endfor %}
- {% endif %} -
- {{ form.submit(class='btn right') }} -
- -
+
+
+ {{ form.submit(class='btn right') }} +
+
{% endblock %} From 7f76e7884f63eb2c0602a888d8389a2da91ca7a2 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 9 Jul 2019 14:53:17 +0200 Subject: [PATCH 4/4] Rename account form. --- app/auth/forms.py | 2 +- app/auth/views.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/auth/forms.py b/app/auth/forms.py index 3c92c7ed..0e54ebf7 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -47,7 +47,7 @@ class PasswordResetRequestForm(FlaskForm): submit = SubmitField('Reset Password') -class ChangeProfileForm(FlaskForm): +class ChangeAccountForm(FlaskForm): email = StringField('Email', validators=[Optional(), Length(1, 64), Email()]) username = StringField('Username', validators=[ diff --git a/app/auth/views.py b/app/auth/views.py index 48b861b6..5480753c 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -2,7 +2,7 @@ from flask import flash, redirect, render_template, request, url_for from flask_login import current_user, login_required, login_user, logout_user from . import auth from .. import db -from .forms import ChangeProfileForm, LoginForm, PasswordResetForm, PasswordResetRequestForm, RegistrationForm +from .forms import ChangeAccountForm, LoginForm, PasswordResetForm, PasswordResetRequestForm, RegistrationForm from ..email import send_email from ..models import User @@ -20,7 +20,7 @@ def login(): if next is None or not next.startswith('/'): next = url_for('main.index') return redirect(next) - flash('Invalid username or password.') + flash('Invalid username or password.') return render_template('auth/login.html.j2', form=form, title='Log in') @@ -128,7 +128,7 @@ def password_reset(token): @auth.route('/account', methods=['GET', 'POST']) @login_required def account(): - form = ChangeProfileForm() + form = ChangeAccountForm() if form.validate_on_submit(): flash('It is just a test, nothing changed.') if form.username.data: