mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-15 02:20:40 +00:00
Add dark mode
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import PasswordField, StringField, SubmitField, ValidationError
|
||||
from wtforms import (PasswordField, StringField, SubmitField,
|
||||
ValidationError, BooleanField)
|
||||
from wtforms.validators import DataRequired, EqualTo, Length
|
||||
from ..models import User
|
||||
|
||||
import logging
|
||||
|
||||
class ChangePasswordForm(FlaskForm):
|
||||
"""
|
||||
@ -36,3 +37,8 @@ class EditProfileForm(FlaskForm):
|
||||
if field.data != self.user.email and \
|
||||
User.query.filter_by(email=field.data).first():
|
||||
raise ValidationError('Email already registered!')
|
||||
|
||||
|
||||
class EditUserSettingsForm(FlaskForm):
|
||||
is_dark = BooleanField('Dark Mode')
|
||||
submit = SubmitField('Save Settings')
|
||||
|
@ -2,9 +2,12 @@ from app.utils import background_delete_user
|
||||
from flask import current_app, flash, redirect, render_template, url_for
|
||||
from flask_login import current_user, login_required, logout_user
|
||||
from . import profile
|
||||
from .forms import ChangePasswordForm, EditProfileForm
|
||||
from .forms import ChangePasswordForm, EditProfileForm, EditUserSettingsForm
|
||||
from .. import db
|
||||
import threading
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@profile.route('/', methods=['GET', 'POST'])
|
||||
@ -23,6 +26,7 @@ def index():
|
||||
return redirect(url_for('profile.index'))
|
||||
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
|
||||
@ -30,15 +34,27 @@ def index():
|
||||
db.session.commit()
|
||||
flash('Your email has been updated.')
|
||||
change_profile_form.email.data = current_user.email
|
||||
|
||||
edit_user_settings_form = EditUserSettingsForm()
|
||||
if edit_user_settings_form.validate_on_submit():
|
||||
current_user.is_dark = edit_user_settings_form.is_dark.data
|
||||
logger.warning('Form data: {}'.format(current_user.is_dark))
|
||||
db.session.add(current_user)
|
||||
db.session.commit()
|
||||
|
||||
return render_template('profile/index.html.j2',
|
||||
change_password_form=change_password_form,
|
||||
change_profile_form=change_profile_form,
|
||||
edit_user_settings_form=edit_user_settings_form,
|
||||
title='Profile')
|
||||
|
||||
|
||||
@profile.route('/delete_self', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def delete_self():
|
||||
"""
|
||||
Vie to delete yourslef and all associated data.
|
||||
"""
|
||||
delete_thread = threading.Thread(
|
||||
target=background_delete_user,
|
||||
args=(current_app._get_current_object(), current_user.id)
|
||||
|
Reference in New Issue
Block a user