2020-11-13 09:01:51 +00:00
|
|
|
from flask import flash, redirect, render_template, url_for
|
2020-10-26 10:23:19 +00:00
|
|
|
from flask_login import current_user, login_required, logout_user
|
2020-10-26 10:17:25 +00:00
|
|
|
from . import settings, tasks
|
2020-10-23 11:52:01 +00:00
|
|
|
from .forms import (ChangePasswordForm, EditGeneralSettingsForm,
|
|
|
|
EditNotificationSettingsForm)
|
|
|
|
from .. import db
|
|
|
|
|
|
|
|
|
|
|
|
@settings.route('/')
|
|
|
|
@login_required
|
|
|
|
def index():
|
|
|
|
return redirect(url_for('.edit_general_settings'))
|
|
|
|
|
|
|
|
|
|
|
|
@settings.route('/change_password', methods=['GET', 'POST'])
|
|
|
|
@login_required
|
|
|
|
def change_password():
|
|
|
|
form = ChangePasswordForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
current_user.password = form.new_password.data
|
|
|
|
db.session.commit()
|
|
|
|
flash('Your password has been updated.')
|
|
|
|
return redirect(url_for('.change_password'))
|
|
|
|
return render_template('settings/change_password.html.j2',
|
2020-11-13 09:01:51 +00:00
|
|
|
form=form, title='Change password')
|
2020-10-23 11:52:01 +00:00
|
|
|
|
|
|
|
|
2020-10-27 13:23:23 +00:00
|
|
|
@settings.route('/edit_general_settings', methods=['GET', 'POST'])
|
2020-10-23 11:52:01 +00:00
|
|
|
@login_required
|
|
|
|
def edit_general_settings():
|
|
|
|
form = EditGeneralSettingsForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
current_user.email = form.email.data
|
|
|
|
current_user.setting_dark_mode = form.dark_mode.data
|
|
|
|
current_user.username = form.username.data
|
|
|
|
db.session.commit()
|
|
|
|
flash('Your changes have been saved.')
|
2020-11-13 09:01:51 +00:00
|
|
|
return redirect(url_for('.edit_general_settings'))
|
2020-10-27 13:23:23 +00:00
|
|
|
form.dark_mode.data = current_user.setting_dark_mode
|
|
|
|
form.email.data = current_user.email
|
|
|
|
form.username.data = current_user.username
|
2020-10-23 11:52:01 +00:00
|
|
|
return render_template('settings/edit_general_settings.html.j2',
|
2020-11-13 09:01:51 +00:00
|
|
|
form=form, title='General settings')
|
2020-10-23 11:52:01 +00:00
|
|
|
|
|
|
|
|
2020-10-27 13:23:23 +00:00
|
|
|
@settings.route('/edit_notification_settings', methods=['GET', 'POST'])
|
2020-10-23 11:52:01 +00:00
|
|
|
@login_required
|
|
|
|
def edit_notification_settings():
|
|
|
|
form = EditNotificationSettingsForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
current_user.setting_job_status_mail_notifications = \
|
|
|
|
form.job_status_mail_notifications.data
|
|
|
|
current_user.setting_job_status_site_notifications = \
|
|
|
|
form.job_status_site_notifications.data
|
|
|
|
db.session.commit()
|
|
|
|
flash('Your changes have been saved.')
|
2020-11-13 09:01:51 +00:00
|
|
|
return redirect(url_for('.edit_notification_settings'))
|
2020-10-27 13:23:23 +00:00
|
|
|
form.job_status_mail_notifications.data = \
|
|
|
|
current_user.setting_job_status_mail_notifications
|
|
|
|
form.job_status_site_notifications.data = \
|
|
|
|
current_user.setting_job_status_site_notifications
|
2020-10-23 11:52:01 +00:00
|
|
|
return render_template('settings/edit_notification_settings.html.j2',
|
2020-11-13 09:01:51 +00:00
|
|
|
form=form, title='Notification settings')
|
2020-10-23 11:52:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
@settings.route('/delete')
|
|
|
|
@login_required
|
|
|
|
def delete():
|
|
|
|
"""
|
|
|
|
View to delete current_user and all associated data.
|
|
|
|
"""
|
|
|
|
tasks.delete_user(current_user.id)
|
|
|
|
logout_user()
|
2020-11-13 09:01:51 +00:00
|
|
|
flash('Your account has been marked for deletion!')
|
2020-10-23 11:52:01 +00:00
|
|
|
return redirect(url_for('main.index'))
|