diff --git a/files/classes/user.py b/files/classes/user.py index 15172ec25..7c07ed9c6 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -86,6 +86,8 @@ class User(Base): bio_html = Column(String) sig = Column(String) sig_html = Column(String) + friends = Column(String) + friends_html = Column(String) is_banned = Column(Integer, default=0) unban_utc = Column(Integer, default=0) ban_reason = Column(String) diff --git a/files/routes/settings.py b/files/routes/settings.py index eca3422df..324ce8f19 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -178,6 +178,36 @@ def settings_profile_post(v): msg="Your sig has been updated.") + if request.values.get("friends"): + friends = request.values.get("friends")[:500] + + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', friends, re.MULTILINE): + if "wikipedia" not in i.group(1): friends = friends.replace(i.group(1), f'![]({i.group(1)})') + + friends_html = CustomRenderer().render(mistletoe.Document(friends)) + friends_html = sanitize(friends_html) + bans = filter_comment_html(friends_html) + + if bans: + ban = bans[0] + reason = f"Remove the {ban.domain} link from your top 8 friends list and try again." + if ban.reason: reason += f" {ban.reason}" + return {"error": reason}, 401 + + if len(friends_html) > 1000: + return render_template("settings_profile.html", + v=v, + error="Your top 8 friends list is too long") + + v.friends = friends[:500] + v.friends_html=friends_html + g.db.add(v) + g.db.commit() + return render_template("settings_profile.html", + v=v, + msg="Your top 8 friends have been updated.") + + if request.values.get("bio") or request.files.get('file') and request.headers.get("cf-ipcountry") != "T1": bio = request.values.get("bio")[:1500] diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index 3f925a6a3..cfde9d254 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -587,6 +587,28 @@ + +
+ + + +
+
+ +
+ +
+

+										
+ Limit of 500 characters + +
+
+
+ +
+ + {% if v.patron or v.id == 1904 %}
diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 4985430b2..348df71d7 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -175,7 +175,10 @@ {% else %}

No bio...

{% endif %} - {% if u.bio_html and v %} + + {% if u.friends_html %} +

Top 8 friends:

+ {{u.friends_html | safe}} {% endif %} {% if u.received_awards %} @@ -441,7 +444,12 @@
joined {{u.created_date}}
{% if u.bio_html %} -

{{u.bio_html | safe}}

+

{{u.bio_html | safe}}

+ {% endif %} + + {% if u.friends_html %} +

Top 8 friends:

+ {{u.friends_html | safe}} {% endif %} {% if u.received_awards %}