diff --git a/files/classes/user.py b/files/classes/user.py index 79be657c9..b532a1b91 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -44,6 +44,7 @@ class User(Base): username = Column(String) namecolor = Column(String, default=DEFAULT_COLOR) background = Column(String) + profile_background = Column(String) customtitle = Column(String) customtitleplain = deferred(Column(String)) titlecolor = Column(String, default=DEFAULT_COLOR) diff --git a/files/routes/settings.py b/files/routes/settings.py index d491645f7..45802ad31 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -73,6 +73,28 @@ def upload_custom_background(v): return redirect('/settings/personal') +@app.post('/settings/profile_background') +@limiter.limit(DEFAULT_RATELIMIT_SLOWER) +@auth_required +@ratelimit_user() +def upload_profile_background(v): + if g.is_tor: abort(403, "Image uploads are not allowed through TOR.") + + file = request.files["file"] + + name = f'/images/{time.time()}'.replace('.','') + '.webp' + file.save(name) + background = process_image(name, v) + + if background: + if v.profile_background: + fpath = '/images/' + v.profile_background.split('/images/')[1] + if path.isfile(fpath): os.remove(fpath) + v.profile_background = background + g.db.add(v) + badge_grant(badge_id=193, user=v) + return redirect(f'/@{v.username}') + @app.post("/settings/personal") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) @auth_required diff --git a/files/templates/settings/personal.html b/files/templates/settings/personal.html index 07da1e65a..9aa713dfb 100644 --- a/files/templates/settings/personal.html +++ b/files/templates/settings/personal.html @@ -71,7 +71,7 @@ {% if v.background and v.background.startswith('/images/') %} {{v.background}} {% else %} - Upload Custom Background + Upload custom site background {% endif %} @@ -80,7 +80,7 @@