Linking social media on profile

This commit is contained in:
Michał Gdula 2023-06-25 19:49:17 +00:00
parent 2b5daa78b7
commit dda7d1087b
8 changed files with 132 additions and 20 deletions

View file

@ -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"])

View file

@ -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,

View file

@ -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)
> .discord, > .twitter, > .twitch, > .youtube
margin: 0
padding: 0.2rem 0.3rem
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
// flex-direction: column
> img
margin: 0 auto
width: 15rem
height: 15rem
width: 5rem
height: 5rem

View file

@ -4,7 +4,7 @@
gap: 1rem
.picture
margin: 0
margin: 0 0 auto 0
width: 10rem
position: relative

View file

@ -52,7 +52,7 @@ body
margin: 0 auto
padding: 0
width: 800px
width: 900px
min-height: 100vh
position: relative

View file

@ -11,7 +11,7 @@
type="{{ type }}"
name="{{ name }}"
id="{{ id }}"
value="{{ value }}"
{% if value %}value="{{ value }}"{% endif %}
{% if required %}required{% endif %}
minlength="{{ minlength }}"
>

View file

@ -18,6 +18,9 @@
<div class="other">
{{ text(id="profile-username", name="username", value=current_user.username) }}
{{ text(id="profile-email", name="email") }}
<span style="height: 100%"></span>
{{ text(id="profile-password", name="password", type="password", required=True, minlength=8) }}
<span style="height: 100%"></span>
@ -28,6 +31,28 @@
</form>
</div>
<div class="block">
<h2 style="margin-bottom: 1rem;">Linked Socials</h2>
<form action="{{ url_for('account.post_settings') }}" method="POST" enctype="multipart/form-data">
<div class="profile-settings">
<div class="other">
{{ text(id="socials-discord", name="discord", value=current_user.discord) }}
{{ text(id="socials-twitter", name="twitter", value=current_user.twitter) }}
{{ text(id="socials-twitch", name="twitch", value=current_user.twitch) }}
{{ text(id="socials-youtube", name="youtube", value=current_user.youtube) }}
<span style="height: 100%"></span>
{{ text(id="socials-password", name="password", type="password", required=True, minlength=8) }}
<span style="height: 100%"></span>
<button type="submit" class="button primary">Save changes</button>
</div>
</div>
</form>
</div>
<div class="block">
<h2>Sessions</h2>
<p>Devices and games that you logged into. If you're looking to log out all website users, reset your password instead.</p>

View file

@ -42,17 +42,23 @@
{% else %}
<img src="{{ url_for('static', filename='images/pfp.png') }}" alt="Profile picture">
{% endif %}
<div class="other">
<div class="profile-title">
<h2>{{ user.username }}</h2>
{% for tag in tags %}
<span class="profile-tag" style="background-color:{{ tag.color }};">
{{ tag.tag }}
</span>
{% endfor %}
{% for tag in tags %}<span class="profile-tag" style="background-color:{{ tag.color }};">{{ tag.tag }}</span>{% endfor %}
</div>
<hr>
<p>Joined {{ user.joined_at|timesince }}</p>
<hr>
<div class="profile-links">
{% if user.discord %}<button class="discord"><i class="ph ph-discord-logo"></i></button>{% endif %}
{% if user.twitter %}<a href="https://twitter.com/{{ user.twitter }}" class="twitter"><i class="ph ph-twitter-logo"></i></a>{% endif %}
{% if user.twitch %}<a href="https://twitch.com/{{ user.twitch }}" class="twitch"><i class="ph ph-twitch-logo"></i></a>{% endif %}
{% if user.youtube %}<a href="https://youtube.com/{{ user.youtube }}" class="youtube"><i class="ph ph-youtube-logo"></i></a>{% endif %}
</div>
</div>
</div>
{% endif %}