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 @@
{% endif %} diff --git a/files/templates/userpage/userpage.html b/files/templates/userpage/userpage.html index 0931cd881..8d5c9ea19 100644 --- a/files/templates/userpage/userpage.html +++ b/files/templates/userpage/userpage.html @@ -2,6 +2,13 @@ {% block pagetype %}userpage{% endblock %} {% block pagetitle %}@{{u.username}}'s profile{% endblock %} {% block head_final %} + {% if u.profile_background %} + + {% endif %} {% if u and u.profilecss and not request.values.get('nocss') %} {% endif %} @@ -190,6 +197,19 @@
{% if v and v.id == u.id %} Edit profile + +
+ + + +
{% endif %} {% if FEATURES['USERS_PROFILE_SONG'] and u.song and v and (v.id == u.id or v.mute and not u.unmutable) %} @@ -388,6 +408,19 @@
{% if v and v.id == u.id %} Edit profile + +
+ + + +
{% endif %} {% if FEATURES['USERS_PROFILE_SONG'] and u.song and v and (v.id == u.id or v.mute and not u.unmutable) %} diff --git a/migrations/20221205-profile-background.sql b/migrations/20221205-profile-background.sql new file mode 100644 index 000000000..73b009a8d --- /dev/null +++ b/migrations/20221205-profile-background.sql @@ -0,0 +1 @@ +alter table users add column profile_background varchar(30); diff --git a/schema.sql b/schema.sql index 4383f8e9d..022e0ce3d 100644 --- a/schema.sql +++ b/schema.sql @@ -981,7 +981,8 @@ CREATE TABLE public.users ( highres character varying(60), patron integer DEFAULT 0 NOT NULL, controversial boolean DEFAULT false NOT NULL, - background character varying(20), + background character varying(30), + profile_background character varying(30), verified character varying(100), cardview boolean NOT NULL, received_award_count integer DEFAULT 0 NOT NULL, @@ -2720,4 +2721,3 @@ ALTER TABLE ONLY public.comment_option_votes -- -- PostgreSQL database dump complete -- -