mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-07-30 15:25:19 +00:00
Add function to change user email
This commit is contained in:
@@ -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 ChangePasswordForm, LoginForm, PasswordResetForm, PasswordResetRequestForm, RegistrationForm
|
||||
from .forms import ChangePasswordForm, LoginForm, PasswordResetForm, PasswordResetRequestForm, RegistrationForm, EditProfileForm
|
||||
from ..email import send_email
|
||||
from ..models import User
|
||||
|
||||
@@ -131,9 +131,9 @@ def password_reset(token):
|
||||
title='Password Reset')
|
||||
|
||||
|
||||
@auth.route('/settings', methods=['GET', 'POST'])
|
||||
@auth.route('/edit_profile', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def settings():
|
||||
def edit_profile():
|
||||
"""
|
||||
View where loged in User can change own User information like Password etc.
|
||||
"""
|
||||
@@ -144,11 +144,19 @@ def settings():
|
||||
db.session.add(current_user)
|
||||
db.session.commit()
|
||||
flash('Your password has been updated.')
|
||||
return redirect(url_for('auth.settings'))
|
||||
return redirect(url_for('auth.edit_profile'))
|
||||
else:
|
||||
flash('Invalid password.')
|
||||
change_profile_form = EditProfileForm(user=current_user)
|
||||
if change_profile_form.validate_on_submit():
|
||||
current_user.email = change_profile_form.email.data
|
||||
db.session.add(current_user._get_current_object())
|
||||
db.session.commit()
|
||||
flash('Your email has been updated.')
|
||||
change_profile_form.email.data = current_user.email
|
||||
return render_template(
|
||||
'auth/settings.html.j2',
|
||||
form=change_password_form,
|
||||
title='Settings'
|
||||
'auth/edit_profile.html.j2',
|
||||
change_password_form=change_password_form,
|
||||
change_profile_form=change_profile_form,
|
||||
title='Edit Profile'
|
||||
)
|
||||
|
Reference in New Issue
Block a user