add web
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
{% extends '__layout__.html' %}
|
||||
{% block title %}Home{% endblock %}
|
||||
{% block head %}
|
||||
<link href="/static/css/home.css" rel="stylesheet"/> <!-- Its just easier to resuse this-->
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div id="main">
|
||||
<div class="container">
|
||||
{% if not isEmailVerified: %}
|
||||
<div class="alert p-2 alert-warning d-flex align-items-center">
|
||||
<i class="bi bi-envelope-plus ms-2" style="font-size: 30px;"></i>
|
||||
<div class="m-2">
|
||||
Verify your email to secure your account and get a free item!
|
||||
</div>
|
||||
<a href="/settings/update-email" class="ms-auto text-decoration-none me-2"><button class="btn btn-warning btn-sm">Verify Email</button></a>
|
||||
</div>
|
||||
{%endif%}
|
||||
{% if not isDiscordLinked: %}
|
||||
<div class="alert p-2 alert-primary d-flex align-items-center">
|
||||
<i class="bi bi-discord ms-2" style="font-size: 30px;"></i>
|
||||
<div class="m-2">
|
||||
Link your Discord Account and you will get a lifetime builders club membership for free
|
||||
</div>
|
||||
<a href="/settings/discord_link" class="ms-auto text-decoration-none me-2"><button class="btn btn-primary btn-sm">Link Discord</button></a>
|
||||
</div>
|
||||
{%endif%}
|
||||
<div class="d-flex align-items-center">
|
||||
<img class="rounded-5 overflow-hidden me-4" src="/Thumbs/Head.ashx?x=150&y=150&userId={{currentuser.id}}" style="width:auto;max-height: 130px;"/>
|
||||
<div class="mt-2">
|
||||
<h1>
|
||||
<span id="greetings"></span>, {{currentuser.username}}!
|
||||
</h1>
|
||||
{% if membershipValue == 1: %}
|
||||
<span class="rbx-icon-bc"></span>
|
||||
{%endif%}
|
||||
{% if membershipValue == 2: %}
|
||||
<span class="rbx-icon-tbc"></span>
|
||||
{%endif%}
|
||||
{% if membershipValue == 3: %}
|
||||
<span class="rbx-icon-negative-obc"></span>
|
||||
{%endif%}
|
||||
</div>
|
||||
</div>
|
||||
<h4>Friends ( {{friendcount}} )</h4>
|
||||
<div class="w-100 p-2 d-flex card-container" style="overflow-x: hidden;min-height: 100px;">
|
||||
{% for friend in friends %}
|
||||
<a href="/users/{{friend.id}}/profile">
|
||||
<div style="height: fit-content; width:90px;" class="me-3">
|
||||
<div class="image-container">
|
||||
<img class="rounded w-100 d-table" src="/Thumbs/Head.ashx?x=100&y=100&userId={{friend.id}}" style="margin: 0 auto;height: fit-content; max-width: 100px;"/>
|
||||
{% if friend.isonline: %}<div class="status-icon {% if friend.ingame: %}status-icon-green{% endif %}"></div>{% endif %}
|
||||
</div>
|
||||
<p class="text-white w-100 text-center d-inline-block m-0 text-truncate" style="font-size: 12px;">{{friend.username}}</p>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% if friendcount == 0: %}
|
||||
<p style="margin: auto auto;" class="d-table align-items-center d-flex">You have no friends <img width="21" height="21" src="https://media.tenor.com/jeYb8iK3YfsAAAAi/skull-skullgif.gif"></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<h4 class="mt-2">Recently Played</h4>
|
||||
<div class="w-100 p-2 d-flex" style="overflow-x: hidden;min-height: 100px;overflow-x: auto;">
|
||||
{% for place in recentlyplayed %}
|
||||
<a class="text-decoration-none" href="/games/{{place.id}}/">
|
||||
<div class="me-3 overflow-hidden rounded place-card">
|
||||
<div class="position-relative">
|
||||
<img width="100%" style="aspect-ratio: 1/1;" src="/Thumbs/PlaceIcon.ashx?assetId={{place.id}}&x=150&y=150">
|
||||
<div class="position-absolute" style="bottom: 0px;left: 0px;">
|
||||
<div class="fw-bold bg-dark text-white" style="font-size: 12px;padding: 3px;border-top-right-radius: 4px;">{{place.placeyear.value}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-1">
|
||||
<h5 class="mb-0" style="font-size: 17px;text-overflow: ellipsis;">{{place.name}}</h5>
|
||||
<div class="d-flex align-items-center">
|
||||
<p style="margin:0;font-size: 14px;" class="text-secondary"><i class="bi bi-people"></i> {{place.playercount}} <span style="font-size: 13px;">Playing</span></p>
|
||||
</div>
|
||||
<div class="w-100 votePercentageBackground">
|
||||
<div class="votePercentageFill" style="width: {{place.likePercentage}}%;"></div>
|
||||
<div>
|
||||
<div class="segment" style="left: 18%;"></div>
|
||||
<div class="segment" style="left: 38%;"></div>
|
||||
<div class="segment" style="left: 58%;"></div>
|
||||
<div class="segment" style="left: 78%;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% if recentlyplayedcount == 0: %}
|
||||
<p style="margin: auto auto;" class="d-table">Looks like you havent played any games yet, maybe you should go <a class="text-decoration-none" href="/games">play</a> one right now!</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const hour = new Date().getHours();
|
||||
let greeting;
|
||||
|
||||
if (hour >= 5 && hour < 12) {
|
||||
greeting = "Good Morning";
|
||||
} else if (hour >= 12 && hour < 18) {
|
||||
greeting = "Good Afternoon";
|
||||
} else if (hour >= 18 && hour < 22) {
|
||||
greeting = "Good Evening";
|
||||
} else {
|
||||
greeting = "Good Night";
|
||||
}
|
||||
|
||||
document.getElementById("greetings").textContent = greeting;
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,95 @@
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, jsonify, make_response
|
||||
from app.extensions import db
|
||||
from app.util import auth, friends, placeinfo, membership
|
||||
from app.models.user import User
|
||||
from app.models.asset import Asset
|
||||
from app.models.place import Place
|
||||
from app.models.previously_played import PreviouslyPlayed
|
||||
from app.models.placeserver_players import PlaceServerPlayer
|
||||
from app.models.linked_discord import LinkedDiscord
|
||||
from app.models.user_email import UserEmail
|
||||
from datetime import datetime
|
||||
from app.routes.rate import GetAssetVotePercentage
|
||||
|
||||
home = Blueprint("home", __name__, template_folder="pages")
|
||||
|
||||
def InsertRecentlyPlayed( UserObj : User, PlaceId : int ):
|
||||
"""
|
||||
Updates the recently played table for the user
|
||||
"""
|
||||
# Check if the user has played this place before
|
||||
PreviouslyPlayedObj : PreviouslyPlayed = PreviouslyPlayed.query.filter_by(userid=UserObj.id, placeid=PlaceId).first()
|
||||
if PreviouslyPlayedObj is None:
|
||||
# User has not played this place before
|
||||
PreviouslyPlayedObj = PreviouslyPlayed(UserObj.id, PlaceId)
|
||||
db.session.add(PreviouslyPlayedObj)
|
||||
db.session.commit()
|
||||
|
||||
# If the user has more than 25 recently played places, remove the oldest one
|
||||
PreviouslyPlayedObjs : list[PreviouslyPlayed] = PreviouslyPlayed.query.filter_by(userid=UserObj.id).all()
|
||||
if len(PreviouslyPlayedObjs) > 25:
|
||||
PreviouslyPlayedObjs.sort(key=lambda x: x.lastplayed)
|
||||
db.session.delete(PreviouslyPlayedObjs[0])
|
||||
db.session.commit()
|
||||
|
||||
return
|
||||
# User has played this place before, update the lastplayed timestamp
|
||||
PreviouslyPlayedObj.lastplayed = datetime.utcnow()
|
||||
db.session.commit()
|
||||
|
||||
@home.route("/home", methods=["GET"])
|
||||
@auth.authenticated_required
|
||||
def home_page():
|
||||
user_agent = request.headers.get("User-Agent", "")
|
||||
if "RobloxStudio" in user_agent:
|
||||
return redirect("/ide/welcome")
|
||||
Authuser : User = auth.GetCurrentUser()
|
||||
Friends = friends.GetFriends(Authuser.id)
|
||||
FriendCount = len(Friends)
|
||||
FriendsData = []
|
||||
for friend in Friends:
|
||||
# Get the friend's thumbnail
|
||||
friendObjData = {
|
||||
"id": friend.id,
|
||||
"username": friend.username,
|
||||
"isonline": True if (datetime.utcnow() - friend.lastonline).total_seconds() < 60 else False,
|
||||
"ingame": True if PlaceServerPlayer.query.filter_by(userid=friend.id).first() is not None else False
|
||||
}
|
||||
FriendsData.append(friendObjData)
|
||||
# Sort the friends by online status
|
||||
FriendsData.sort(key=lambda x: x["isonline"], reverse=True)
|
||||
# Sort the friends by ingame status
|
||||
FriendsData.sort(key=lambda x: x["ingame"], reverse=True)
|
||||
# Limit the friends to 12
|
||||
FriendsData = FriendsData[:12]
|
||||
|
||||
RecentlyPlayedData = []
|
||||
RecentlyPlayedObjs : list[PreviouslyPlayed] = PreviouslyPlayed.query.filter_by(userid=Authuser.id).order_by(PreviouslyPlayed.lastplayed.desc()).limit(12).all()
|
||||
for RecentlyPlayedObj in RecentlyPlayedObjs:
|
||||
PlaceAssetObj : Asset = Asset.query.filter_by(id=RecentlyPlayedObj.placeid).first()
|
||||
if PlaceAssetObj is None:
|
||||
continue
|
||||
PlaceObj : Place = Place.query.filter_by(placeid=PlaceAssetObj.id).first()
|
||||
if PlaceObj is None:
|
||||
continue
|
||||
RecentlyPlayedData.append({
|
||||
"id": PlaceObj.placeid,
|
||||
"name": PlaceAssetObj.name,
|
||||
"playercount": placeinfo.GetPlayingCount(PlaceObj),
|
||||
"likePercentage": GetAssetVotePercentage(PlaceObj.placeid),
|
||||
"placeyear": PlaceObj.placeyear
|
||||
})
|
||||
membershipValue : int = membership.GetUserMembership(Authuser).value
|
||||
isDiscordLinked : bool = LinkedDiscord.query.filter_by(user_id=Authuser.id).first() is not None
|
||||
isEmailVerified : bool = UserEmail.query.filter_by(user_id=Authuser.id).first() is not None
|
||||
|
||||
return render_template(
|
||||
"home/home.html",
|
||||
friends=FriendsData,
|
||||
friendcount=FriendCount,
|
||||
recentlyplayed=RecentlyPlayedData,
|
||||
recentlyplayedcount=len(RecentlyPlayedData),
|
||||
membershipValue=membershipValue,
|
||||
isDiscordLinked=isDiscordLinked,
|
||||
isEmailVerified=isEmailVerified
|
||||
)
|
||||
Reference in New Issue
Block a user