Fix Settings button

This commit is contained in:
Patrick Jentsch 2020-02-20 10:03:42 +01:00
parent 50746ab821
commit 4c6b1ee461
3 changed files with 12 additions and 8 deletions

View File

@ -6,12 +6,12 @@ from wtforms.validators import DataRequired, Email, EqualTo
class EditEmailForm(FlaskForm):
email = StringField('New email', validators=[Email(), DataRequired()])
save_email = SubmitField('Save Email')
save_email = SubmitField('Save email')
class EditGeneralSettingsForm(FlaskForm):
dark_mode = BooleanField('Dark mode')
save_settings = SubmitField('Save Settings')
save_settings = SubmitField('Save settings')
class EditPasswordForm(FlaskForm):
@ -27,7 +27,7 @@ class EditPasswordForm(FlaskForm):
validators=[DataRequired(),
EqualTo('password', message='Passwords must match.')]
)
save_password = SubmitField('Save Password')
save_password = SubmitField('Save password')
def __init__(self, user, *args, **kwargs):
super(EditPasswordForm, self).__init__(*args, **kwargs)

View File

@ -1,4 +1,4 @@
from app import db
from app import db, logger
from flask import current_app, flash, redirect, render_template, url_for
from flask_login import current_user, login_required, logout_user
from threading import Thread
@ -12,13 +12,14 @@ from .forms import EditEmailForm, EditGeneralSettingsForm, EditPasswordForm
def settings():
edit_email_form = EditEmailForm(prefix='edit-email-form')
edit_general_settings_form = EditGeneralSettingsForm(
prefix='edit-settings-form'
prefix='edit-general-settings-form'
)
edit_password_form = EditPasswordForm(prefix='edit-password-form',
user=current_user)
# Check if edit_email_form is submitted and valid
if (edit_email_form.save_email.data
and edit_email_form.validate_on_submit()):
logger.warning('edit_email_form submitted')
db.session.add(current_user)
db.session.commit()
flash('Your email address has been updated.')
@ -26,6 +27,7 @@ def settings():
# Check if edit_settings_form is submitted and valid
if (edit_general_settings_form.save_settings.data
and edit_general_settings_form.validate_on_submit()):
logger.warning('edit_general_settings_form submitted')
current_user.is_dark = edit_general_settings_form.dark_mode.data
db.session.add(current_user)
db.session.commit()
@ -34,12 +36,14 @@ def settings():
# Check if edit_password_form is submitted and valid
if (edit_password_form.save_password.data
and edit_password_form.validate_on_submit()):
logger.warning('edit_password_form submitted')
current_user.password = edit_password_form.password.data
db.session.add(current_user)
db.session.commit()
flash('Your password has been updated.')
return redirect(url_for('profile.settings'))
# If no form is submitted or valid, fill out fields with current values
logger.warning('nothing submitted')
edit_email_form.email.data = current_user.email
edit_general_settings_form.dark_mode.data = current_user.is_dark
return render_template(

View File

@ -129,7 +129,7 @@
</ul>
</div>
<div class="card-action right-align">
<a href="#delete-account-modal" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete</a>
<a href="#delete-account-modal" class="btn modal-trigger red waves-effect waves-light"><i class="material-icons left">delete</i>Delete</a>
</div>
</div>
</div>
@ -142,8 +142,8 @@
<p>Do you really want to delete your account and all associated data? All associated jobs and job files will be permanently deleted!</p>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-light btn">Cancel</a>
<a href="{{ url_for('profile.delete') }}" class="btn red waves-effect waves-light"><i class="material-icons left">delete</i>Delete User</a>
<a href="#!" class="btn modal-close waves-effect waves-light">Cancel</a>
<a href="{{ url_for('profile.delete') }}" class="btn red waves-effect waves-light"><i class="material-icons left">delete</i>Delete</a>
</div>
</div>
{% endblock %}