diff --git a/files/classes/comment.py b/files/classes/comment.py index a0558fa24..dca421d79 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -316,6 +316,7 @@ class Comment(Base): url_noquery = url.split('?')[0] body = body.replace(url, f"{url_noquery}?{urlencode(p, True)}") + if self.author.sig_html: return body + '
' + self.author.sig_html return body def plainbody(self, v): diff --git a/files/classes/submission.py b/files/classes/submission.py index d7905e304..8939630b7 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -316,6 +316,7 @@ class Submission(Base): if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") + if self.author.sig_html: return body + '
' + self.author.sig_html return body def plainbody(self, v): diff --git a/files/classes/user.py b/files/classes/user.py index bae508633..15172ec25 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -84,6 +84,8 @@ class User(Base): controversial = Column(Boolean, default=False) bio = Column(String) bio_html = Column(String) + sig = Column(String) + sig_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 6ea87a63b..1fe36a2b0 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -148,6 +148,87 @@ def settings_profile_post(v): msg="Your bio has been updated.") + if v.patron and request.values.get("sig"): + sig = request.values.get("sig")[:1500] + + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', sig, re.MULTILINE): + if "wikipedia" not in i.group(1): sig = sig.replace(i.group(1), f'![]({i.group(1)})') + sig = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', sig) + + sig_html = CustomRenderer().render(mistletoe.Document(sig)) + sig_html = sanitize(sig_html) + bans = filter_comment_html(sig_html) + + if len(sig_html) > 10000: + return render_template("settings_profile.html", + v=v, + error="Your sig is too long") + + if bans: + ban = bans[0] + reason = f"Remove the {ban.domain} link from your sig and try again." + if ban.reason: + reason += f" {ban.reason}" + + return {"error": reason}, 401 + + if len(sig_html) > 10000: abort(400) + + v.sig = sig[:1500] + v.sig_html=sig_html + g.db.add(v) + g.db.commit() + return render_template("settings_profile.html", + v=v, + msg="Your sig has 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] + + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', bio, re.MULTILINE): + if "wikipedia" not in i.group(1): bio = bio.replace(i.group(1), f'![]({i.group(1)})') + bio = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', bio) + + if request.files.get('file'): + file = request.files['file'] + if not file.content_type.startswith('image/'): + if request.headers.get("Authorization"): return {"error": f"Image files only"}, 400 + else: return render_template("settings_profile.html", v=v, error=f"Image files only."), 400 + + name = f'/images/{int(time.time())}{secrets.token_urlsafe(2)}.gif' + file.save(name) + url = request.host_url[:-1] + process_image(name) + + bio += f"\n\n![]({url})" + + bio_html = CustomRenderer().render(mistletoe.Document(bio)) + bio_html = sanitize(bio_html) + bans = filter_comment_html(bio_html) + + if len(bio_html) > 10000: + return render_template("settings_profile.html", + v=v, + error="Your bio is too long") + + if bans: + ban = bans[0] + reason = f"Remove the {ban.domain} link from your bio and try again." + if ban.reason: + reason += f" {ban.reason}" + + return {"error": reason}, 401 + + if len(bio_html) > 10000: abort(400) + + v.bio = bio[:1500] + v.bio_html=bio_html + g.db.add(v) + g.db.commit() + return render_template("settings_profile.html", + v=v, + msg="Your bio has been updated.") + frontsize = request.values.get("frontsize") if frontsize: diff --git a/files/templates/authforms.html b/files/templates/authforms.html index f95d443b3..8c1a94218 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,11 +15,11 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 561fa849d..018abfff8 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -254,12 +254,12 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} {% endblock %} diff --git a/files/templates/log.html b/files/templates/log.html index eae6e1c16..4f3dbf41a 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -17,11 +17,11 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %}
diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 9e95b2f29..1a12b2a7c 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -12,7 +12,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 49af02a13..5523270b0 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -55,7 +55,7 @@ - + {% if v.agendaposter %}{% elif v.css %}{% endif %} diff --git a/files/templates/settings2.html b/files/templates/settings2.html index a43764a73..7dbf06dad 100644 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -40,10 +40,10 @@ {% if v %} - + {% else %} - + {% endif %} diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index 2e0e52671..94c4b7a69 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -587,6 +587,38 @@
+ {% if v.patron %} +
+ + +
+
+ +
+ +
+
+ +   + +   + +   + +   + +
+

+										
+ Limit of 200 characters + +
+
+
+ +
+ {% endif %} +
diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 268a30997..2aab8b41c 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -36,7 +36,7 @@ - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index beee52e9b..8dd678ba7 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -31,7 +31,7 @@ - + diff --git a/files/templates/submit.html b/files/templates/submit.html index 5847b489e..959c0603d 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -25,11 +25,11 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} {% endblock %}