diff --git a/files/routes/settings.py b/files/routes/settings.py index e9f29aec3..6142d4c10 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -15,7 +15,17 @@ import os from files.helpers.sanitize import filter_emojis_only from shutil import copyfile import requests -import tldextract + +@app.get("/settings") +@auth_required +def settings(v): + return redirect("/settings/personal") + + +@app.get("/settings/personal") +@auth_required +def settings_personal(v): + return render_template("settings_personal.html", v=v) @app.post("/settings/removebackground") @limiter.limit("1/second;30/minute;200/hour;1000/day") @@ -116,25 +126,25 @@ def settings_profile_post(v): v.bio = None v.bio_html = None g.db.add(v) - return render_template("settings_profile.html", v=v, msg="Your bio has been updated.") + return render_template("settings_personal.html", v=v, msg="Your bio has been updated.") elif request.values.get("sig") == "": v.sig = None v.sig_html = None g.db.add(v) - return render_template("settings_profile.html", v=v, msg="Your sig has been updated.") + return render_template("settings_personal.html", v=v, msg="Your sig has been updated.") elif request.values.get("friends") == "": v.friends = None v.friends_html = None g.db.add(v) - return render_template("settings_profile.html", v=v, msg="Your friends list has been updated.") + return render_template("settings_personal.html", v=v, msg="Your friends list has been updated.") elif request.values.get("enemies") == "": v.enemies = None v.enemies_html = None g.db.add(v) - return render_template("settings_profile.html", v=v, msg="Your enemies list has been updated.") + return render_template("settings_personal.html", v=v, msg="Your enemies list has been updated.") elif v.patron and request.values.get("sig"): sig = request.values.get("sig")[:200].replace('\n','').replace('\r','') @@ -142,14 +152,14 @@ def settings_profile_post(v): sig_html = sanitize(sig) if len(sig_html) > 1000: - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, error="Your sig is too long") v.sig = sig[:200] v.sig_html=sig_html g.db.add(v) - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, msg="Your sig has been updated.") @@ -162,7 +172,7 @@ def settings_profile_post(v): friends_html = sanitize(friends) if len(friends_html) > 2000: - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, error="Your friends list is too long") @@ -177,7 +187,7 @@ def settings_profile_post(v): v.friends = friends[:500] v.friends_html=friends_html g.db.add(v) - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, msg="Your friends list has been updated.") @@ -188,7 +198,7 @@ def settings_profile_post(v): enemies_html = sanitize(enemies) if len(enemies_html) > 2000: - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, error="Your enemies list is too long") @@ -203,7 +213,7 @@ def settings_profile_post(v): v.enemies = enemies[:500] v.enemies_html=enemies_html g.db.add(v) - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, msg="Your enemies list has been updated.") @@ -219,7 +229,7 @@ def settings_profile_post(v): bio_html = sanitize(bio) if len(bio_html) > 10000: - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, error="Your bio is too long") @@ -228,7 +238,7 @@ def settings_profile_post(v): v.bio = bio[:1500] v.bio_html=bio_html g.db.add(v) - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, msg="Your bio has been updated.") @@ -325,7 +335,7 @@ def namecolor(v): if color.startswith('#'): color = color[1:] if not color_regex.fullmatch(color): - return render_template("settings_profile.html", v=v, error="Invalid color hex code") + return render_template("settings_personal.html", v=v, error="Invalid color hex code") v.namecolor = color g.db.add(v) @@ -341,7 +351,7 @@ def themecolor(v): if themecolor.startswith('#'): themecolor = themecolor[1:] if not color_regex.fullmatch(themecolor): - return render_template("settings_profile.html", v=v, error="Invalid color hex code") + return render_template("settings_personal.html", v=v, error="Invalid color hex code") v.themecolor = themecolor g.db.add(v) @@ -393,7 +403,7 @@ def titlecolor(v): if titlecolor.startswith('#'): titlecolor = titlecolor[1:] if not color_regex.fullmatch(titlecolor): - return render_template("settings_profile.html", v=v, error="Invalid color hex code") + return render_template("settings_personal.html", v=v, error="Invalid color hex code") v.titlecolor = titlecolor g.db.add(v) return redirect("/settings/profile") @@ -405,7 +415,7 @@ def titlecolor(v): def verifiedcolor(v): verifiedcolor = str(request.values.get("verifiedcolor", "")).strip() if verifiedcolor.startswith('#'): verifiedcolor = verifiedcolor[1:] - if len(verifiedcolor) != 6: return render_template("settings_profile.html", v=v, error="Invalid color hex code") + if len(verifiedcolor) != 6: return render_template("settings_personal.html", v=v, error="Invalid color hex code") v.verifiedcolor = verifiedcolor g.db.add(v) return redirect("/settings/profile") @@ -544,7 +554,7 @@ def settings_images_profile(v): g.db.add(v) - return render_template("settings_profile.html", v=v, msg="Profile picture successfully updated.") + return render_template("settings_personal.html", v=v, msg="Profile picture successfully updated.") @app.post("/settings/images/banner") @@ -568,19 +578,11 @@ def settings_images_banner(v): v.bannerurl = bannerurl g.db.add(v) - return render_template("settings_profile.html", v=v, msg="Banner successfully updated.") - - -@app.get("/settings/blocks") -@auth_required -def settings_blockedpage(v): - - return render_template("settings_blocks.html", v=v) + return render_template("settings_personal.html", v=v, msg="Banner successfully updated.") @app.get("/settings/css") @auth_required def settings_css_get(v): - return render_template("settings_css.html", v=v) @app.post("/settings/css") @@ -600,11 +602,6 @@ def settings_css(v): return render_template("settings_css.html", v=v) -@app.get("/settings/profilecss") -@auth_required -def settings_profilecss_get(v): - return render_template("settings_profilecss.html", v=v) - @app.post("/settings/profilecss") @limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') @@ -614,11 +611,20 @@ def settings_profilecss(v): valid, error = validate_css(profilecss) if not valid: - return render_template("settings_profilecss.html", error=error, v=v) + return render_template("settings_css.html", error=error, v=v) v.profilecss = profilecss g.db.add(v) - return render_template("settings_profilecss.html", v=v) + return render_template("settings_css.html", v=v) + +@app.get("/settings/security") +@auth_required +def settings_security(v): + return render_template("settings_security.html", + v=v, + mfa_secret=pyotp.random_base32() if not v.mfa_secret else None, + now=int(time.time()) + ) @app.post("/settings/block") @limiter.limit("1/second;20/day") @@ -626,7 +632,6 @@ def settings_profilecss(v): @auth_required def settings_block_user(v): user = get_user(request.values.get("username"), graceful=True) - if not user: abort(404, "This user doesn't exist.") if user.unblockable: @@ -638,17 +643,13 @@ def settings_block_user(v): if user.id == AUTOJANNY_ID: abort(403, "You can't block this user") if v.has_blocked(user): abort(409, f"You have already blocked @{user.username}") - new_block = UserBlock(user_id=v.id, - target_id=user.id, - ) + new_block = UserBlock(user_id=v.id, target_id=user.id) g.db.add(new_block) if user.admin_level >= PERMS['USER_BLOCKS_VISIBLE']: send_notification(user.id, f"@{v.username} has blocked you!") cache.delete_memoized(frontlist) - - return {"message": f"@{user.username} blocked."} @@ -661,27 +662,20 @@ def settings_unblock_user(v): x = v.has_blocked(user) if not x: abort(409, "You can't unblock someone you haven't blocked") g.db.delete(x) - if not v.shadowbanned and user.admin_level >= PERMS['USER_BLOCKS_VISIBLE']: send_notification(user.id, f"@{v.username} has unblocked you!") - cache.delete_memoized(frontlist) - - return {"message": f"@{user.username} unblocked."} - @app.get("/settings/apps") @auth_required def settings_apps(v): - return render_template("settings_apps.html", v=v) -@app.get("/settings/content") +@app.get("/settings/advanced") @auth_required -def settings_content_get(v): - - return render_template("settings_filters.html", v=v) +def settings_advanced_get(v): + return render_template("settings_advanced.html", v=v) @app.post("/settings/name_change") @limiter.limit("1/second;30/minute;200/hour;1000/day") @@ -691,12 +685,12 @@ def settings_name_change(v): new_name=request.values.get("name").strip() if new_name==v.username: - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, error="You didn't change anything") if not valid_username_regex.fullmatch(new_name): - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, error="This isn't a valid username.") @@ -710,7 +704,7 @@ def settings_name_change(v): ).one_or_none() if x and x.id != v.id: - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, error=f"Username `{new_name}` is already in use.") @@ -733,7 +727,7 @@ def settings_song_change_mp3(v): file = request.files['file'] if file.content_type != 'audio/mpeg': - return render_template("settings_profile.html", v=v, error="Not a valid MP3 file") + return render_template("settings_personal.html", v=v, error="Not a valid MP3 file") song = str(time.time()).replace('.','') @@ -743,7 +737,7 @@ def settings_song_change_mp3(v): size = os.stat(name).st_size if size > 8 * 1024 * 1024: os.remove(name) - return render_template("settings_profile.html", v=v, error="MP3 file must be smaller than 8MB") + return render_template("settings_personal.html", v=v, error="MP3 file must be smaller than 8MB") if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: os.remove(f"/songs/{v.song}.mp3") @@ -778,7 +772,7 @@ def settings_song_change(v): elif song.startswith("https://youtu.be/"): id = song.split("https://youtu.be/")[1] else: - return render_template("settings_profile.html", v=v, error="Not a youtube link.") + return render_template("settings_personal.html", v=v, error="Not a youtube link.") if "?" in id: id = id.split("?")[0] if "&" in id: id = id.split("&")[0] @@ -792,15 +786,15 @@ def settings_song_change(v): req = requests.get(f"https://www.googleapis.com/youtube/v3/videos?id={id}&key={YOUTUBE_KEY}&part=contentDetails", timeout=5).json() duration = req['items'][0]['contentDetails']['duration'] if duration == 'P0D': - return render_template("settings_profile.html", v=v, error="Can't use a live youtube video!") + return render_template("settings_personal.html", v=v, error="Can't use a live youtube video!") if "H" in duration: - return render_template("settings_profile.html", v=v, error="Duration of the video must not exceed 15 minutes.") + return render_template("settings_personal.html", v=v, error="Duration of the video must not exceed 15 minutes.") if "M" in duration: duration = int(duration.split("PT")[1].split("M")[0]) if duration > 15: - return render_template("settings_profile.html", v=v, error="Duration of the video must not exceed 15 minutes.") + return render_template("settings_personal.html", v=v, error="Duration of the video must not exceed 15 minutes.") if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: @@ -820,7 +814,7 @@ def settings_song_change(v): try: ydl.download([f"https://youtube.com/watch?v={id}"]) except Exception as e: print(e, flush=True) - return render_template("settings_profile.html", + return render_template("settings_personal.html", v=v, error="Age-restricted videos aren't allowed.") @@ -846,14 +840,14 @@ def settings_title_change(v): customtitleplain = request.values.get("title").strip().replace("𒐪","")[:100] if customtitleplain == v.customtitleplain: - return render_template("settings_profile.html", v=v, error="You didn't change anything") + return render_template("settings_personal.html", v=v, error="You didn't change anything") customtitle = filter_emojis_only(customtitleplain) customtitle = censor_slurs(customtitle, None) if len(customtitle) > 1000: - return render_template("settings_profile.html", v=v, error="Flair too long!") + return render_template("settings_personal.html", v=v, error="Flair too long!") v.customtitleplain = customtitleplain v.customtitle = customtitle @@ -873,13 +867,13 @@ def settings_pronouns_change(v): pronouns = request.values.get("pronouns").replace("𒐪","").strip() if len(pronouns) > 11: - return render_template("settings_profile.html", v=v, error="Your pronouns exceed the character limit (11 characters)") + return render_template("settings_personal.html", v=v, error="Your pronouns exceed the character limit (11 characters)") if pronouns == v.pronouns: - return render_template("settings_profile.html", v=v, error="You didn't change anything.") + return render_template("settings_personal.html", v=v, error="You didn't change anything.") if not pronouns_regex.fullmatch(pronouns): - return render_template("settings_profile.html", v=v, error="The pronouns you entered don't match the required format.") + return render_template("settings_personal.html", v=v, error="The pronouns you entered don't match the required format.") bare_pronouns = pronouns.lower().replace('/', '') if 'nig' in bare_pronouns: pronouns = 'BI/POC' @@ -896,28 +890,10 @@ def settings_pronouns_change(v): @limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') @auth_required def settings_checkmark_text(v): - if not v.verified: abort(403) - new_name=request.values.get("title").strip()[:100].replace("𒐪","") - if not new_name: abort(400) - - if new_name == v.verified: return render_template("settings_profile.html", v=v, error="You didn't change anything") - + if new_name == v.verified: return render_template("settings_personal.html", v=v, error="You didn't change anything") v.verified = new_name g.db.add(v) - return redirect("/settings/profile") - - -@app.get("/settings") -@auth_required -def settings(v): - return redirect("/settings/profile") - - -@app.get("/settings/profile") -@auth_required -def settings_profile(v): - return render_template("settings_profile.html", v=v) diff --git a/files/routes/static.py b/files/routes/static.py index cff4f6f1f..afa6e5a9b 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -360,16 +360,6 @@ def serviceworker(): with open("files/assets/js/service-worker.js", "r", encoding="utf-8") as f: return Response(f.read(), mimetype='application/javascript') -@app.get("/settings/security") -@auth_required -def settings_security(v): - return render_template("settings_security.html", - v=v, - mfa_secret=pyotp.random_base32() if not v.mfa_secret else None, - now=int(time.time()) - ) - - @app.post("/dismiss_mobile_tip") def dismiss_mobile_tip(): session["tooltip_last_dismissed"] = int(time.time()) diff --git a/files/templates/settings_apps.html b/files/templates/settings_apps.html index 0d4c9c7f6..bfcbc6b24 100644 --- a/files/templates/settings_apps.html +++ b/files/templates/settings_apps.html @@ -1,11 +1,9 @@ {% extends "settings.html" %} -{% block pagetitle %}Apps/Bots - {{SITE_NAME}}{% endblock %} +{% block pagetitle %}Apps/Bots - {{SITE_NAME}}{% endblock %} {% block content %}
- -
API Guide
Your API Applications
{% for app in v.applications if app.client_id %} diff --git a/files/templates/settings_personal.html b/files/templates/settings_personal.html index 12936995f..fecf37a61 100644 --- a/files/templates/settings_personal.html +++ b/files/templates/settings_personal.html @@ -1,6 +1,18 @@ {% extends "settings.html" %} {% block pagetitle %}Content Settings - {{SITE_NAME}}{% endblock %} {% import 'settings_common.html' as common with context %} + {# common sections start #} {% macro color_section(id, form_action, form_name, section_title, current_color) %}
diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html deleted file mode 100644 index a8a6e6492..000000000 --- a/files/templates/settings_profile.html +++ /dev/null @@ -1,701 +0,0 @@ -{% extends "settings.html" %} - -{% block pagetitle %}Profile Settings - {{SITE_NAME}}{% endblock %} - -{% block content %} - - - -
-
-
- {% if FEATURES['HOUSES'] %} -
House
-
-
-
- -
-
- {% if v.house %} - {% set cost = HOUSE_SWITCH_COST %} -

Change your house (cost: {{cost}} coins or marseybux).

- {% if ' Founder' in v.house %} -

Warning: you'll lose your founder status if you join a different house

- {% endif %} - {% else %} - {% set cost = HOUSE_JOIN_COST %} -

Join a house (cost: {{cost}} coins or marseybux).

- {% endif %} -
- -
-
-
-
- {% endif %} - -
Theme
-
-
-
- -
-
-
- - -
- Enable if you would like to display images and videos in full size on the frontpage. -
-
-
- -
- -
- -
- -
- - -
- - Enable if you would like to highlight comments made after the last time you visited a thread. - -
- -
- - -
-
- -
- -
-

Change the theme for the website.

-
- -
- -
- -
-
- - - -
- -
- - - {% for themecolor in COLORS %} - - - {% endfor %} - -
- -
- -

Or type a color hex code:

-
-
- - - - -
-
- -
-
-
- -
-
-

Change the background for the website.

-
- -
- {% if v.background %} -
- -
- {% endif %} -
-
-
-
- -
Profile Picture
- -
- -
- -
- your profile picture -
- -
- -
- -
-
- - -
- -
- -
- -
All image files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.
- -
- -
- -
- - {% if FEATURES['USERS_PROFILE_BANNER'] -%} -
Profile Banner
- -
- -
- -
- -
- -
- -
- -
-
- - -
- -
- -
- -
All image files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.
- -
- -
- -
- {%- endif %} - -
Referrals
- -

Invite a friend.

- -
- -
- -
- -
- -
- -
- - - - - - {{v.referral_count}} - - -
- -
Share this link with a friend. {% if v.referral_count==0 %} When they sign up, you'll get the bronze recruitment badge. Learn more.{% elif v.referral_count<10 %} When you refer 10 friends, you'll receive the silver recruitment badge. Learn more.{% elif v.referral_count<100 %} When you refer 100 friends, you'll receive the gold recruitment badge. Learn more.{% endif %}
- -
- -
- -
- -
RSS Feed
- -

Subscribe to the {{SITE_NAME}} RSS feed.

- -
- -
- -
- - - -
You can change the feed by replacing "hot" with whatever sorting you want and "all" with whatever time filter you want.
- -
- -
- -
- -
Your Profile
- -

Edit how others see you on {{SITE_NAME}}.

- -
- -
- - - -
-

Your original username will always stay reserved for you: {{v.original_username}}

- -
- - - 3-25 characters, including letters, numbers, _ , and - -
- -
-
-
- -
- - {% if FEATURES['USERS_PROFILE_SONG'] -%} -
- - - -
-

You can use an MP3 file or a YouTube video.

- -
- - -
- -
- - - - - -
- -
In some browsers, users have to click at least once anywhere in the profile page for the anthem to play. -
- -
- {%- endif %} - -
- - - -
- -
- - - {% for color in COLORS %} - - - {% endfor %} - -
- -
- -

Or type a color hex code:

-
-
- - - -
-
-
- - {% if FEATURES['PRONOUNS'] %} -
- - - -
-
- - -
- {2-5 characters} / {2-5 characters} - -
-
-
- -
- {% endif %} - - -
- - - -
-
- - -
-
- Limit of 100 characters - -
-
-
- -
- -
- - - -
- -
- - - {% for titlecolor in COLORS %} - - - {% endfor %} - -
- -
- - - -

Or type a color hex code:

-
-
- - - -
-
- -
- - - - - - {% if v.verified %} - -
- - - -
- -
- - - {% for verifiedcolor in COLORS %} - - - {% endfor %} - -
- -
- -

Or type a color hex code:

-
-
- - - -
-
- -
- -
- - - -
- -
- - -
- Limit of 100 characters - -
-
-
- -
- {% endif %} - - - {% if FEATURES['USERS_PROFILE_BODYTEXT'] -%} -
- - - -
-
- - -
- -   - -   - -
-
- Limit of 1500 characters - -
-
-
- -
- - -
- - - -
-
- - -
- Limit of 500 characters - -
-
-
- -
- - -
- - - -
-
- - -
- Limit of 500 characters - -
-
-
- -
- {%- endif %} - - - {% if v.sig or v.patron %} -
- - -
-
- - -
- -   - -
-
- Limit of 200 characters - -
-
-
- -
- {% endif %} - -
- -
- -
- -
- -
- - -
- - This will hide your post and comment history from others. We will also ask search engines to not index your profile page. (Your content will still be accessible via direct link.) - -
- -
-
- -
- -
- -
- -
- - -
- - Prevent other users from following you. - -
- -
-
-
- -
- -
- -
- 1 %}disabled{% endif %} onchange="postToastSwitch(this,'/settings/profile?spider='+document.getElementById('spiderswitch').checked)"> - -
- - Have a spider friend accompany you during your journey on the site. -
-
-
-
- -
- -
- -
- -
- -
- - -{% include "emoji_modal.html" %} -{% include "gif_modal.html" %} - -{% if v.flairchanged %} - -{% endif %} - - - -{% endblock %}