def change_password(): """ User profile :return: flask.render_template / flask.redirect """ form_u = MyProfileForm() form_pw = PasswordForm() form_u.username.data = current_user.username form_u.email.data = current_user.email if form_pw.validate_on_submit(): old_pw = form_pw.old_password.data if Users.check_old_password(current_user, old_pw): Users.update_user( user_id=current_user.id, password=form_pw.password.data ) flash('You successfully updated your password.', 'success') return redirect(url_for('users.my_profile')) else: form_pw.old_password.errors = ['Old password mismatch.'] data = { 'active_page': 'profile', 'form_u': form_u, 'form_pw': form_pw } return render_template('users/my_profile.html', **data) data = { 'active_page': 'profile', 'form_u': form_u, 'form_pw': form_pw } return render_template('users/my_profile.html', **data)
def my_profile(): """ User profile :return: flask.render_template / flask.redirect """ form_u = MyProfileForm() form_pw = PasswordForm() if request.method == 'POST': if form_u.username.data == current_user.username: form_u.username.raw_data = None if form_u.email.data == current_user.email: form_u.email.raw_data = None else: form_u.username.data = current_user.username form_u.email.data = current_user.email if form_u.validate_on_submit(): Users.update_user( user_id=current_user.id, username=form_u.username.data, email=form_u.email.data ) flash('You successfully updated your profile.', 'success') return redirect(url_for('users.my_profile')) data = { 'active_page': 'profile', 'form_u': form_u, 'form_pw': form_pw } return render_template('users/my_profile.html', **data)