mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
Fix Settings button
This commit is contained in:
parent
50746ab821
commit
4c6b1ee461
@ -6,12 +6,12 @@ from wtforms.validators import DataRequired, Email, EqualTo
|
|||||||
|
|
||||||
class EditEmailForm(FlaskForm):
|
class EditEmailForm(FlaskForm):
|
||||||
email = StringField('New email', validators=[Email(), DataRequired()])
|
email = StringField('New email', validators=[Email(), DataRequired()])
|
||||||
save_email = SubmitField('Save Email')
|
save_email = SubmitField('Save email')
|
||||||
|
|
||||||
|
|
||||||
class EditGeneralSettingsForm(FlaskForm):
|
class EditGeneralSettingsForm(FlaskForm):
|
||||||
dark_mode = BooleanField('Dark mode')
|
dark_mode = BooleanField('Dark mode')
|
||||||
save_settings = SubmitField('Save Settings')
|
save_settings = SubmitField('Save settings')
|
||||||
|
|
||||||
|
|
||||||
class EditPasswordForm(FlaskForm):
|
class EditPasswordForm(FlaskForm):
|
||||||
@ -27,7 +27,7 @@ class EditPasswordForm(FlaskForm):
|
|||||||
validators=[DataRequired(),
|
validators=[DataRequired(),
|
||||||
EqualTo('password', message='Passwords must match.')]
|
EqualTo('password', message='Passwords must match.')]
|
||||||
)
|
)
|
||||||
save_password = SubmitField('Save Password')
|
save_password = SubmitField('Save password')
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
def __init__(self, user, *args, **kwargs):
|
||||||
super(EditPasswordForm, self).__init__(*args, **kwargs)
|
super(EditPasswordForm, self).__init__(*args, **kwargs)
|
||||||
|
@ -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 import current_app, flash, redirect, render_template, url_for
|
||||||
from flask_login import current_user, login_required, logout_user
|
from flask_login import current_user, login_required, logout_user
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
@ -12,13 +12,14 @@ from .forms import EditEmailForm, EditGeneralSettingsForm, EditPasswordForm
|
|||||||
def settings():
|
def settings():
|
||||||
edit_email_form = EditEmailForm(prefix='edit-email-form')
|
edit_email_form = EditEmailForm(prefix='edit-email-form')
|
||||||
edit_general_settings_form = EditGeneralSettingsForm(
|
edit_general_settings_form = EditGeneralSettingsForm(
|
||||||
prefix='edit-settings-form'
|
prefix='edit-general-settings-form'
|
||||||
)
|
)
|
||||||
edit_password_form = EditPasswordForm(prefix='edit-password-form',
|
edit_password_form = EditPasswordForm(prefix='edit-password-form',
|
||||||
user=current_user)
|
user=current_user)
|
||||||
# Check if edit_email_form is submitted and valid
|
# Check if edit_email_form is submitted and valid
|
||||||
if (edit_email_form.save_email.data
|
if (edit_email_form.save_email.data
|
||||||
and edit_email_form.validate_on_submit()):
|
and edit_email_form.validate_on_submit()):
|
||||||
|
logger.warning('edit_email_form submitted')
|
||||||
db.session.add(current_user)
|
db.session.add(current_user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Your email address has been updated.')
|
flash('Your email address has been updated.')
|
||||||
@ -26,6 +27,7 @@ def settings():
|
|||||||
# Check if edit_settings_form is submitted and valid
|
# Check if edit_settings_form is submitted and valid
|
||||||
if (edit_general_settings_form.save_settings.data
|
if (edit_general_settings_form.save_settings.data
|
||||||
and edit_general_settings_form.validate_on_submit()):
|
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
|
current_user.is_dark = edit_general_settings_form.dark_mode.data
|
||||||
db.session.add(current_user)
|
db.session.add(current_user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@ -34,12 +36,14 @@ def settings():
|
|||||||
# Check if edit_password_form is submitted and valid
|
# Check if edit_password_form is submitted and valid
|
||||||
if (edit_password_form.save_password.data
|
if (edit_password_form.save_password.data
|
||||||
and edit_password_form.validate_on_submit()):
|
and edit_password_form.validate_on_submit()):
|
||||||
|
logger.warning('edit_password_form submitted')
|
||||||
current_user.password = edit_password_form.password.data
|
current_user.password = edit_password_form.password.data
|
||||||
db.session.add(current_user)
|
db.session.add(current_user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Your password has been updated.')
|
flash('Your password has been updated.')
|
||||||
return redirect(url_for('profile.settings'))
|
return redirect(url_for('profile.settings'))
|
||||||
# If no form is submitted or valid, fill out fields with current values
|
# 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_email_form.email.data = current_user.email
|
||||||
edit_general_settings_form.dark_mode.data = current_user.is_dark
|
edit_general_settings_form.dark_mode.data = current_user.is_dark
|
||||||
return render_template(
|
return render_template(
|
||||||
|
@ -129,7 +129,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action right-align">
|
<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>
|
</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>
|
<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>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a href="#!" class="modal-close waves-effect waves-light btn">Cancel</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 User</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>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user