diff --git a/app/templates/user/edit_profile.html b/app/templates/user/edit_profile.html
index 5bc19ea2..145b714a 100644
--- a/app/templates/user/edit_profile.html
+++ b/app/templates/user/edit_profile.html
@@ -1,5 +1,5 @@
{% extends "base.html" %}
-{% from 'bootstrap/form.html' import render_form %}
+{% from 'bootstrap/form.html' import render_field %}
{% block app_content %}
@@ -11,9 +11,21 @@
{{ _('Edit profile') }}
- {{ _('Edit profile') }}
-
diff --git a/app/user/forms.py b/app/user/forms.py
index c9f232fd..54c67e3a 100644
--- a/app/user/forms.py
+++ b/app/user/forms.py
@@ -11,6 +11,9 @@ class ProfileForm(FlaskForm):
password_field = PasswordField(_l('Set new password'), validators=[Optional(), Length(min=1, max=50)],
render_kw={"autocomplete": 'Off'})
about = TextAreaField(_l('Bio'), validators=[Optional(), Length(min=3, max=5000)])
+ profile_file = FileField(_('Avatar image'))
+ banner_file = FileField(_('Top banner image'))
+ bot = BooleanField(_l('This profile is a bot'))
submit = SubmitField(_l('Save profile'))
def validate_email(self, field):
@@ -20,7 +23,6 @@ class ProfileForm(FlaskForm):
class SettingsForm(FlaskForm):
newsletter = BooleanField(_l('Subscribe to email newsletter'))
- bot = BooleanField(_l('This profile is a bot'))
ignore_bots = BooleanField(_l('Hide posts by bots'))
nsfw = BooleanField(_l('Show NSFW posts'))
nsfl = BooleanField(_l('Show NSFL posts'))
diff --git a/app/user/routes.py b/app/user/routes.py
index 64c63688..0500e40e 100644
--- a/app/user/routes.py
+++ b/app/user/routes.py
@@ -5,10 +5,12 @@ from flask_login import login_user, logout_user, current_user, login_required
from flask_babel import _
from app import db, cache
+from app.community.util import save_icon_file, save_banner_file
from app.models import Post, Community, CommunityMember, User, PostReply, PostVote, Notification, utcnow
from app.user import bp
from app.user.forms import ProfileForm, SettingsForm
-from app.utils import get_setting, render_template, markdown_to_html, user_access, markdown_to_text, shorten_string
+from app.utils import get_setting, render_template, markdown_to_html, user_access, markdown_to_text, shorten_string, \
+ is_image_url
from sqlalchemy import desc, or_, text
@@ -47,6 +49,17 @@ def edit_profile(actor):
if form.password_field.data.strip() != '':
current_user.set_password(form.password_field.data)
current_user.about = form.about.data
+ current_user.bot = form.bot.data
+ profile_file = request.files['profile_file']
+ if profile_file and profile_file.filename != '':
+ file = save_icon_file(profile_file)
+ if file:
+ current_user.avatar = file
+ banner_file = request.files['banner_file']
+ if banner_file and banner_file.filename != '':
+ file = save_banner_file(banner_file)
+ if file:
+ current_user.cover = file
current_user.flush_cache()
db.session.commit()
@@ -73,7 +86,6 @@ def change_settings(actor):
form = SettingsForm()
if form.validate_on_submit():
current_user.newsletter = form.newsletter.data
- current_user.bot = form.bot.data
current_user.ignore_bots = form.ignore_bots.data
current_user.show_nsfw = form.nsfw.data
current_user.show_nsfl = form.nsfl.data