mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-07-26 14:01:33 +00:00
user settings page
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import (
|
||||
BooleanField,
|
||||
FileField,
|
||||
PasswordField,
|
||||
SelectField,
|
||||
StringField,
|
||||
SubmitField,
|
||||
TextAreaField,
|
||||
ValidationError
|
||||
)
|
||||
from wtforms.validators import (
|
||||
@@ -47,6 +49,9 @@ class ChangePasswordForm(FlaskForm):
|
||||
|
||||
|
||||
class EditGeneralSettingsForm(FlaskForm):
|
||||
user_avatar = FileField(
|
||||
'Image File'
|
||||
)
|
||||
email = StringField(
|
||||
'E-Mail',
|
||||
validators=[InputRequired(), Length(max=254), Email()]
|
||||
@@ -65,8 +70,41 @@ class EditGeneralSettingsForm(FlaskForm):
|
||||
)
|
||||
]
|
||||
)
|
||||
full_name = StringField(
|
||||
'Full name',
|
||||
validators=[Length(max=128)]
|
||||
)
|
||||
bio = TextAreaField(
|
||||
'About me',
|
||||
validators=[
|
||||
Length(max=254)
|
||||
]
|
||||
)
|
||||
website = StringField(
|
||||
'Website',
|
||||
validators=[
|
||||
Length(max=254)
|
||||
]
|
||||
)
|
||||
organization = StringField(
|
||||
'Organization',
|
||||
validators=[
|
||||
Length(max=128)
|
||||
]
|
||||
)
|
||||
location = StringField(
|
||||
'Location',
|
||||
validators=[
|
||||
Length(max=128)
|
||||
]
|
||||
)
|
||||
|
||||
submit = SubmitField()
|
||||
|
||||
def validate_image_file(self, field):
|
||||
if not field.data.filename.lower().endswith('.jpg' or '.png' or '.jpeg'):
|
||||
raise ValidationError('only .jpg, .png and .jpeg!')
|
||||
|
||||
def __init__(self, user, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.user = user
|
||||
@@ -96,3 +134,9 @@ class EditNotificationSettingsForm(FlaskForm):
|
||||
(x.name, x.name.capitalize())
|
||||
for x in UserSettingJobStatusMailNotificationLevel
|
||||
]
|
||||
|
||||
class EditPrivacySettingsForm(FlaskForm):
|
||||
public_profile = BooleanField(
|
||||
'Public profile'
|
||||
)
|
||||
submit = SubmitField()
|
||||
|
@@ -6,7 +6,8 @@ from . import bp
|
||||
from .forms import (
|
||||
ChangePasswordForm,
|
||||
EditGeneralSettingsForm,
|
||||
EditNotificationSettingsForm
|
||||
EditNotificationSettingsForm,
|
||||
EditPrivacySettingsForm
|
||||
)
|
||||
|
||||
|
||||
@@ -26,7 +27,10 @@ def settings():
|
||||
data=current_user.to_json_serializeable(),
|
||||
prefix='edit-notification-settings-form'
|
||||
)
|
||||
|
||||
edit_privacy_settings_form = EditPrivacySettingsForm(
|
||||
data=current_user.to_json_serializeable(),
|
||||
prefix='edit-privacy-settings-form'
|
||||
)
|
||||
if change_password_form.submit.data and change_password_form.validate():
|
||||
current_user.password = change_password_form.new_password.data
|
||||
db.session.commit()
|
||||
@@ -49,10 +53,13 @@ def settings():
|
||||
db.session.commit()
|
||||
flash('Your changes have been saved')
|
||||
return redirect(url_for('.settings'))
|
||||
user_image = 'static/images/user_avatar.png'
|
||||
return render_template(
|
||||
'settings/settings.html.j2',
|
||||
change_password_form=change_password_form,
|
||||
edit_general_settings_form=edit_general_settings_form,
|
||||
edit_notification_settings_form=edit_notification_settings_form,
|
||||
title='Settings'
|
||||
edit_privacy_settings_form=edit_privacy_settings_form,
|
||||
user_image=user_image,
|
||||
title='Profile & Settings'
|
||||
)
|
||||
|
Reference in New Issue
Block a user