From ad6201b560d73dec57446470bd8957d2b13d4a8b Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 9 Jul 2019 11:00:25 +0200 Subject: [PATCH 1/3] confirm pjentsch account --- data_dev.sqlite | Bin 32768 -> 32768 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/data_dev.sqlite b/data_dev.sqlite index 78cdddd233acf07a4b2c9fae158d207d54f05fa3..42cd48d7f9b9b7a64ecfbde1a9e833fa7ab62ec0 100644 GIT binary patch delta 75 zcmZo@U}|V!njp<6HBrWyRf<8+z-nX4Tz^jfG6p`50tSwP&0GO#9Ndi@j2sM(vJ8!$ foRb^k8#e!rsAgkfU|{H)*w{A7fn_sG!XJ46+*cIu delta 64 zcmZo@U}|V!njp<6IZ?)$RgytZX2Zsmx&E9C3=Di6zZv+;Hgg4}aZH@hz4>=UH5*qW UJ0m-Tqbx(C=j7^$hD8Yq08LdA>Hq)$ From b311fcb9de5b5b81ab4fa6e26ed2acd36574c84e Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 9 Jul 2019 11:00:41 +0200 Subject: [PATCH 2/3] Enable login by username. --- app/auth/forms.py | 9 +++++++-- app/auth/views.py | 19 ++++++++++++++++--- app/templates/auth/login.html.j2 | 6 +++--- app/templates/auth/profile.html.j2 | 25 +++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 app/templates/auth/profile.html.j2 diff --git a/app/auth/forms.py b/app/auth/forms.py index d23e4e2d..23a1db39 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -6,8 +6,7 @@ from ..models import User class LoginForm(FlaskForm): - email = StringField('Email', validators=[DataRequired(), Length(1, 64), - Email()]) + login = StringField('Login', validators=[DataRequired(), Length(1, 64)]) password = PasswordField('Password', validators=[DataRequired()]) remember_me = BooleanField('Keep me logged in') submit = SubmitField('Log In') @@ -46,3 +45,9 @@ class PasswordResetRequestForm(FlaskForm): email = StringField('Email', validators=[DataRequired(), Length(1, 64), Email()]) submit = SubmitField('Reset Password') + + +class ChangeProfileForm(FlaskForm): + email = StringField('Email', validators=[DataRequired(), Length(1, 64), + Email()]) + submit = SubmitField('Submit') diff --git a/app/auth/views.py b/app/auth/views.py index 95dd2fd8..65ef647f 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 LoginForm, PasswordResetForm, PasswordResetRequestForm, RegistrationForm +from .forms import ChangeProfileForm, LoginForm, PasswordResetForm, PasswordResetRequestForm, RegistrationForm from ..email import send_email from ..models import User @@ -11,7 +11,9 @@ from ..models import User def login(): form = LoginForm() if form.validate_on_submit(): - user = User.query.filter_by(email=form.email.data).first() + user = User.query.filter_by(email=form.login.data).first() + if user is None: + user = User.query.filter_by(username=form.login.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) next = request.args.get('next') @@ -85,7 +87,7 @@ def resend_confirmation(): send_email(current_user.email, 'Confirm Your Account', 'auth/email/confirm', user=current_user, token=token) flash('A new confirmation email has benn sent to you by email.') - return redirect(url_for('main.index')) + return redirect(url_for('maind.index')) @auth.route('/reset', methods=['GET', 'POST']) @@ -121,3 +123,14 @@ def password_reset(token): return redirect(url_for('main.index')) return render_template('auth/reset_password.html.j2', form=form, title='Password Reset') + + +@auth.route('/profile', methods=['GET', 'POST']) +@login_required +def profile(): + form = ChangeProfileForm() + if form.validate_on_submit(): + flash('It\'s just a test, nothing changed.') + return redirect(url_for('auth.profile')) + return render_template('auth/profile.html.j2', form=form, + title='Profile') diff --git a/app/templates/auth/login.html.j2 b/app/templates/auth/login.html.j2 index 02ffb68a..68710ccd 100644 --- a/app/templates/auth/login.html.j2 +++ b/app/templates/auth/login.html.j2 @@ -24,9 +24,9 @@
{{ form.hidden_tag() }}
- email - {{ form.email(class='validate', type='email') }} - {{ form.email.label }} + person + {{ form.login(class='validate') }} + {{ form.login.label }}
vpn_key diff --git a/app/templates/auth/profile.html.j2 b/app/templates/auth/profile.html.j2 new file mode 100644 index 00000000..37942949 --- /dev/null +++ b/app/templates/auth/profile.html.j2 @@ -0,0 +1,25 @@ +{% extends "base.html.j2" %} + +{% block page_content %} +
+
+
+ Register + + {{ form.hidden_tag() }} +
+ email + {{ form.email(class='validate', type='email') }} + {{ form.email.label }} + {% for error in form.email.errors %} + {{ error }} + {% endfor %} +
+
+ {{ form.submit(class='btn right') }} +
+ +
+
+
+{% endblock %} From a3efdc87cc640f5cc4a0f06430b44797adf31aa6 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 9 Jul 2019 11:53:40 +0200 Subject: [PATCH 3/3] Add change profile page. --- app/auth/forms.py | 20 ++++++++++++++++++-- app/auth/views.py | 12 ++++++++++-- app/templates/auth/profile.html.j2 | 28 ++++++++++++++++++++++++++-- data_dev.sqlite | Bin 32768 -> 32768 bytes 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/app/auth/forms.py b/app/auth/forms.py index 23a1db39..3c92c7ed 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -1,6 +1,6 @@ from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, BooleanField, SubmitField -from wtforms.validators import DataRequired, Length, Email, Regexp, EqualTo +from wtforms.validators import DataRequired, Length, Email, Regexp, EqualTo, Optional from wtforms import ValidationError from ..models import User @@ -48,6 +48,22 @@ class PasswordResetRequestForm(FlaskForm): class ChangeProfileForm(FlaskForm): - email = StringField('Email', validators=[DataRequired(), Length(1, 64), + email = StringField('Email', validators=[Optional(), Length(1, 64), Email()]) + username = StringField('Username', validators=[ + Optional(), Length(1, 64), + Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0, + 'Usernames must have only letters, numbers, dots or ' + 'underscores')]) + password = PasswordField('Password', validators=[ + Optional(), EqualTo('password2', message='Passwords must match.')]) + password2 = PasswordField('Confirm password', validators=[Optional()]) submit = SubmitField('Submit') + + def validate_email(self, field): + if User.query.filter_by(email=field.data.lower()).first(): + raise ValidationError('Email already registered.') + + def validate_username(self, field): + if User.query.filter_by(username=field.data).first(): + raise ValidationError('Username already in use.') diff --git a/app/auth/views.py b/app/auth/views.py index 65ef647f..09045826 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -87,7 +87,7 @@ def resend_confirmation(): send_email(current_user.email, 'Confirm Your Account', 'auth/email/confirm', user=current_user, token=token) flash('A new confirmation email has benn sent to you by email.') - return redirect(url_for('maind.index')) + return redirect(url_for('main.index')) @auth.route('/reset', methods=['GET', 'POST']) @@ -130,7 +130,15 @@ def password_reset(token): def profile(): form = ChangeProfileForm() if form.validate_on_submit(): - flash('It\'s just a test, nothing changed.') + flash('It is just a test, nothing changed.') + if form.username.data: + current_user.username = form.username.data + db.session.add(current_user) + if form.email.data: + current_user.email = form.email.data + current_user.confirmed = False + db.session.add(current_user) + db.session.commit() return redirect(url_for('auth.profile')) return render_template('auth/profile.html.j2', form=form, title='Profile') diff --git a/app/templates/auth/profile.html.j2 b/app/templates/auth/profile.html.j2 index 37942949..5d81a6c3 100644 --- a/app/templates/auth/profile.html.j2 +++ b/app/templates/auth/profile.html.j2 @@ -4,17 +4,41 @@
- Register + Change profile
{{ form.hidden_tag() }}
email - {{ form.email(class='validate', type='email') }} + {{ form.email(type='email', placeholder=current_user.email) }} {{ form.email.label }} {% for error in form.email.errors %} {{ error }} {% endfor %}
+
+ person + {{ form.username(placeholder=current_user.username) }} + {{ form.username.label }} + {% for error in form.username.errors %} + {{ error }} + {% endfor %} +
+
+ vpn_key + {{ form.password() }} + {{ form.password.label }} + {% for error in form.password.errors %} + {{ error }} + {% endfor %} +
+
+ vpn_key + {{ form.password2() }} + {{ form.password2.label }} + {% for error in form.password2.errors %} + {{ error }} + {% endfor %} +
{{ form.submit(class='btn right') }}
diff --git a/data_dev.sqlite b/data_dev.sqlite index 42cd48d7f9b9b7a64ecfbde1a9e833fa7ab62ec0..5462b370e2e8468195b654f744b5dc8c9058fa37 100644 GIT binary patch delta 88 zcmZo@U}|V!njp=nFj2;tQDI{Oe*`1{=7NZc?1KD{8Tk0-GV<-_`^a~N--&PTW}$>` sK4w{F$H`R@(wleZsWY-N0D