mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 02:24:20 +00:00
Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development
This commit is contained in:
commit
da1ef0e1f1
@ -1,13 +1,12 @@
|
||||
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
|
||||
|
||||
|
||||
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,25 @@ class PasswordResetRequestForm(FlaskForm):
|
||||
email = StringField('Email', validators=[DataRequired(), Length(1, 64),
|
||||
Email()])
|
||||
submit = SubmitField('Reset Password')
|
||||
|
||||
|
||||
class ChangeProfileForm(FlaskForm):
|
||||
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.')
|
||||
|
@ -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')
|
||||
@ -121,3 +123,22 @@ 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 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')
|
||||
|
@ -24,9 +24,9 @@
|
||||
<form method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">email</i>
|
||||
{{ form.email(class='validate', type='email') }}
|
||||
{{ form.email.label }}
|
||||
<i class="material-icons prefix">person</i>
|
||||
{{ form.login(class='validate') }}
|
||||
{{ form.login.label }}
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">vpn_key</i>
|
||||
|
49
app/templates/auth/profile.html.j2
Normal file
49
app/templates/auth/profile.html.j2
Normal file
@ -0,0 +1,49 @@
|
||||
{% extends "base.html.j2" %}
|
||||
|
||||
{% block page_content %}
|
||||
<div class="col s12">
|
||||
<div class="card large">
|
||||
<div class="card-content">
|
||||
<span class="card-title">Change profile</span>
|
||||
<form method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
<div class="input-field ">
|
||||
<i class="material-icons prefix">email</i>
|
||||
{{ form.email(type='email', placeholder=current_user.email) }}
|
||||
{{ form.email.label }}
|
||||
{% for error in form.email.errors %}
|
||||
<span class="helper-text" style="color:red;">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="input-field ">
|
||||
<i class="material-icons prefix">person</i>
|
||||
{{ form.username(placeholder=current_user.username) }}
|
||||
{{ form.username.label }}
|
||||
{% for error in form.username.errors %}
|
||||
<span class="helper-text" style="color:red;">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">vpn_key</i>
|
||||
{{ form.password() }}
|
||||
{{ form.password.label }}
|
||||
{% for error in form.password.errors %}
|
||||
<span class="helper-text" style="color:red;">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">vpn_key</i>
|
||||
{{ form.password2() }}
|
||||
{{ form.password2.label }}
|
||||
{% for error in form.password2.errors %}
|
||||
<span class="helper-text" style="color:red;">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="card-action">
|
||||
{{ form.submit(class='btn right') }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user