diff --git a/TFR/server/account.py b/TFR/server/account.py index 57d6091..af8a117 100644 --- a/TFR/server/account.py +++ b/TFR/server/account.py @@ -1,5 +1,6 @@ import uuid import os +import re from PIL import Image from flask import Blueprint, request, render_template, flash, redirect, url_for @@ -38,16 +39,28 @@ def get_settings(): @blueprint.route("/settings", methods=["POST"]) @login_required def post_settings(): + # This is the worst part of this entire project + # This gotta go :sobbing: username = request.form.get("username", "").strip() email = request.form.get("email", "").strip() password = request.form.get("password", "").strip() + + discord = request.form.get("discord", "").strip() + twitter = request.form.get("twitter", "").strip() + twitch = request.form.get("twitch", "").strip() + youtube = request.form.get("youtube", "").strip() + + twitter_regex = re.compile('^(?!.*\.\.)(?!.*\.$)[\w.]{1,15}$') + twitch_regex = re.compile('^(?=.{4,25}$)(?!_)(?!.*[_.]{2})[a-zA-Z0-9._]+$') + youtube_regex = re.compile('^(?!.*[._]{2})[a-zA-Z0-9._-]{1,50}$') + error = [] user = Users.query.filter_by(username=current_user.username).first() if not check_password_hash(user.password, password): flash("Password is incorrect!", "error") - return redirect(url_for("account.settings")) + return redirect(url_for("account.get_settings")) if "file" in request.files and request.files["file"].filename: picture = request.files["file"] @@ -96,15 +109,33 @@ def post_settings(): else: error.append("Email is invalid!") + if discord: + user.discord = discord + if twitter: + if twitter_regex.match(twitter): + user.twitter = twitter + else: + error.append("Twitter is invalid!") + if twitch: + if twitch_regex.match(twitch): + user.twitch = twitch + else: + error.append("Twitch is invalid!") + if youtube: + if youtube_regex.match(youtube): + user.youtube = youtube + else: + error.append("YouTube is invalid!") + if error: for err in error: flash(err, "error") - return redirect(url_for("account.settings")) + return redirect(url_for("account.get_settings")) db.session.commit() flash("Successfully updated account!", "success") - return redirect(url_for("account.settings")) + return redirect(url_for("account.get_settings")) @blueprint.route("/password", methods=["GET"]) diff --git a/TFR/server/models.py b/TFR/server/models.py index 0a4eaa2..04d6485 100644 --- a/TFR/server/models.py +++ b/TFR/server/models.py @@ -94,6 +94,11 @@ class Users(db.Model, UserMixin): email = db.Column(db.String) password = db.Column(db.String, nullable=False) + discord = db.Column(db.String) + twitter = db.Column(db.String) + twitch = db.Column(db.String) + youtube = db.Column(db.String) + joined_at = db.Column( db.DateTime, nullable=False, diff --git a/TFR/server/static/sass/block.sass b/TFR/server/static/sass/block.sass index 2ef75af..7ff7126 100644 --- a/TFR/server/static/sass/block.sass +++ b/TFR/server/static/sass/block.sass @@ -74,6 +74,7 @@ .profile-title display: flex flex-direction: row + justify-content: space-between gap: 0.5rem h2 @@ -83,9 +84,9 @@ .profile-tag margin: auto 0 - padding: 0.2rem + padding: 0.2rem 0.3rem - font-size: 0.7rem + font-size: 0.8rem color: RGB($black) background-color: RGB($white) @@ -96,12 +97,56 @@ height: 0.9rem margin-right: 0.2rem + .profile-links + display: flex + flex-direction: row + flex-wrap: wrap + gap: 0.5rem -@media (max-width: 621px) - .account-block - flex-direction: column + > .discord, > .twitter, > .twitch, > .youtube + margin: 0 + padding: 0.2rem 0.3rem - > img + width: 2rem + height: 2rem + + display: flex + flex-direction: row + align-items: center + justify-content: center + + text-decoration: none + + color: RGB($white) + border-radius: 2px + border: 0 solid transparent + + > i + font-size: 1.3rem + + &:hover + cursor: pointer + filter: brightness(1.2) + + > .discord + background-color: #5865F2 + + > .twitter + background-color: #1DA1F2 + + > .twitch + background-color: #9146FF + + > .youtube + background-color: #FF0000 + color: RGB($white) + + +@media (max-width: 550px) + .account-block + // flex-direction: column + + > img margin: 0 auto - width: 15rem - height: 15rem + width: 5rem + height: 5rem diff --git a/TFR/server/static/sass/profile-settings.sass b/TFR/server/static/sass/profile-settings.sass index 4b613ac..4b1c0ca 100644 --- a/TFR/server/static/sass/profile-settings.sass +++ b/TFR/server/static/sass/profile-settings.sass @@ -4,7 +4,7 @@ gap: 1rem .picture - margin: 0 + margin: 0 0 auto 0 width: 10rem position: relative diff --git a/TFR/server/static/sass/style.sass b/TFR/server/static/sass/style.sass index 716e30b..ecaebfe 100644 --- a/TFR/server/static/sass/style.sass +++ b/TFR/server/static/sass/style.sass @@ -52,7 +52,7 @@ body margin: 0 auto padding: 0 - width: 800px + width: 900px min-height: 100vh position: relative diff --git a/TFR/server/templates/macros/input.html b/TFR/server/templates/macros/input.html index 1f44540..b81d14c 100644 --- a/TFR/server/templates/macros/input.html +++ b/TFR/server/templates/macros/input.html @@ -11,7 +11,7 @@ type="{{ type }}" name="{{ name }}" id="{{ id }}" - value="{{ value }}" + {% if value %}value="{{ value }}"{% endif %} {% if required %}required{% endif %} minlength="{{ minlength }}" > diff --git a/TFR/server/templates/views/account_settings.html b/TFR/server/templates/views/account_settings.html index e92eda7..a53646e 100644 --- a/TFR/server/templates/views/account_settings.html +++ b/TFR/server/templates/views/account_settings.html @@ -18,6 +18,9 @@
Devices and games that you logged into. If you're looking to log out all website users, reset your password instead.
diff --git a/TFR/server/templates/views/scores.html b/TFR/server/templates/views/scores.html index 2a298a1..51c9e7e 100644 --- a/TFR/server/templates/views/scores.html +++ b/TFR/server/templates/views/scores.html @@ -42,17 +42,23 @@ {% else %}Joined {{ user.joined_at|timesince }}
+ +