1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-17 23:24:20 +00:00

More updates

This commit is contained in:
Steffo 2018-06-05 12:31:11 +02:00
parent cbf76aa555
commit 33036a69e0
7 changed files with 88 additions and 19 deletions

11
db.py
View file

@ -1,7 +1,7 @@
import datetime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy import Column, BigInteger, Integer, String, DateTime, ForeignKey, Float, Enum, create_engine, UniqueConstraint, PrimaryKeyConstraint, Boolean, or_, LargeBinary
from sqlalchemy import Column, BigInteger, Integer, String, DateTime, ForeignKey, Float, Enum, create_engine, UniqueConstraint, PrimaryKeyConstraint, Boolean, or_, LargeBinary, Text
import requests
from errors import RequestError, NotFoundError, AlreadyExistingError
import re
@ -795,6 +795,15 @@ class AprilFoolsBan(Base):
datetime = Column(DateTime, nullable=False)
class CustomCSS(Base):
__tablename__ = "customcss"
royal_id = Column(Integer, ForeignKey("royals.id"), primary_key=True)
royal = relationship("Royal", lazy="joined")
css = Column(Text, nullable=False)
# If run as script, create all the tables in the db
if __name__ == "__main__":
print("Creating new tables...")

View file

@ -350,3 +350,7 @@ input[type="text"], input[type="password"] {
color: #ffffff;
}
}
#edit-css {
font-size: medium;
}

View file

@ -12,6 +12,11 @@
Benvenuto al sito web della Royal Games! E' ancora un po' triste e spoglio, ma spero che collaboriate a migliorarlo!
</p>
<p>
Attualmente, sto sviluppando i <b>profili RYG</b>! Clicca <a href="/profile/{{ session['username'] }}">qui</a> per vedere il tuo.
Attualmente, sto sviluppando i <b>profili RYG</b>!
</p>
<ul>
{% for user in royals %}
<li><a href="/profile/{{ user.username }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
{% endblock %}

View file

@ -21,9 +21,9 @@
</div>
<div class="game-score soloq">
{% if lol.solo_division is none %}
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" game-title="Non classificato" class="rank">
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" title="Non classificato" class="rank">
{% else %}
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.solo_division.name|lower + "_" + lol.solo_rank.name|lower + ".png") }}" class="rank" game-title="{{ lol.solo_division.name|capitalize }} {{ lol.solo_rank.name }}">
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.solo_division.name|lower + "_" + lol.solo_rank.name|lower + ".png") }}" class="rank" title="{{ lol.solo_division.name|capitalize }} {{ lol.solo_rank.name }}">
{% endif %}
</div>
<div class="game-title flexq">
@ -31,9 +31,9 @@
</div>
<div class="game-score flexq">
{% if lol.flex_division is none %}
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" game-title="Non classificato" class="rank">
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" title="Non classificato" class="rank">
{% else %}
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.flex_division.name|lower + "_" + lol.flex_rank.name|lower + ".png") }}" class="rank" game-title="{{ lol.flex_division.name|capitalize }} {{ lol.flex_rank.name }}">
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.flex_division.name|lower + "_" + lol.flex_rank.name|lower + ".png") }}" class="rank" title="{{ lol.flex_division.name|capitalize }} {{ lol.flex_rank.name }}">
{% endif %}
</div>
<div class="game-title twtrq">
@ -41,9 +41,9 @@
</div>
<div class="game-score twtrq">
{% if lol.twtr_division is none %}
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" game-title="Non classificato" class="rank">
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" title="Non classificato" class="rank">
{% else %}
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.twtr_division.name|lower + "_" + lol.twtr_rank.name|lower + ".png") }}" class="rank" game-title="{{ lol.twtr_division.name|capitalize }} {{ lol.twtr_rank.name }}">
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.twtr_division.name|lower + "_" + lol.twtr_rank.name|lower + ".png") }}" class="rank" title="{{ lol.twtr_division.name|capitalize }} {{ lol.twtr_rank.name }}">
{% endif %}
</div>
</div>

View file

@ -4,9 +4,17 @@
Royal Games
{% endblock %}
{% block posthead %}
{% if css %}
<style>
{{ css.css }}
</style>
{% endif %}
{% endblock %}
{% block body %}
<h1>
Profilo di {{ royal.username }}
Profilo di {{ royal.username }} {% if session.get('user_id', '') == royal.id %}<a href="/setcss" id="edit-css">Modifica</a>{% endif %}
</h1>
{% if steam %}
{% include "minis/steam.html" %}

15
templates/setcss.html Normal file
View file

@ -0,0 +1,15 @@
{% extends 'base.html' %}
{% block pagetitle %}
CSS
{% endblock %}
{% block body %}
<h1>
CSS
</h1>
<form action="{{ url_for('page_setcss') }}" method="POST">
<textarea name="css" placeholder="Incolla il CSS per il tuo profilo qui...">{{ css }}</textarea>
<input type="submit" value="Invia">
</form>
{% endblock %}

View file

@ -1,10 +1,8 @@
from flask import Flask, render_template, request, abort, redirect, url_for
from flask import session as fl_session
import db
from sqlalchemy import func, alias
import bcrypt
import configparser
import requests
app = Flask(__name__)
@ -19,8 +17,11 @@ app.secret_key = config["Flask"]["secret_key"]
@app.route("/")
def page_main():
if fl_session.get("username"):
return render_template("main.html", easter_egg=config["Flask"]["easter_egg"])
if fl_session.get("user_id"):
db_session = db.Session()
royals = db_session.query(db.Royal).all()
db_session.close()
return render_template("main.html", royals=royals)
return redirect(url_for("page_login"))
@ -32,13 +33,14 @@ def page_profile(name: str):
db_session.close()
abort(404)
return
css = db_session.query(db.CustomCSS).filter_by(royal=user).one_or_none()
steam = db_session.query(db.Steam).filter_by(royal=user).one_or_none()
osu = db_session.query(db.Osu).filter_by(royal=user).one_or_none()
rl = db_session.query(db.RocketLeague).join(db.Steam).filter_by(royal=user).one_or_none()
dota = db_session.query(db.Dota).join(db.Steam).filter_by(royal=user).one_or_none()
lol = db_session.query(db.LeagueOfLegends).filter_by(royal=user).one_or_none()
db_session.close()
return render_template("profile.html", royal=user, osu=osu, rl=rl, dota=dota, lol=lol, steam=steam)
return render_template("profile.html", royal=user, css=css, osu=osu, rl=rl, dota=dota, lol=lol, steam=steam)
@app.route("/login")
@ -57,10 +59,10 @@ def page_loggedin():
abort(403)
return
if user.password is None:
fl_session["username"] = username
fl_session["user_id"] = user.id
return redirect(url_for("page_password"))
if bcrypt.checkpw(bytes(password, encoding="utf8"), user.password):
fl_session["username"] = username
fl_session["user_id"] = user.id
return redirect(url_for("page_main"))
else:
abort(403)
@ -69,16 +71,16 @@ def page_loggedin():
@app.route("/password", methods=["GET", "POST"])
def page_password():
username = fl_session.get("username")
user_id = fl_session.get("user_id")
if request.method == "GET":
if username is None:
if user_id is None:
abort(403)
return
return render_template("password.html")
elif request.method == "POST":
new_password = request.form.get("new", "")
db_session = db.Session()
user = db_session.query(db.Royal).filter_by(username=username).one()
user = db_session.query(db.Royal).filter_by(id=user_id).one()
if user.password is None:
user.password = bcrypt.hashpw(bytes(new_password, encoding="utf8"), bcrypt.gensalt())
db_session.commit()
@ -90,6 +92,32 @@ def page_password():
return
@app.route("/setcss", methods=["GET", "POST"])
def page_setcss():
user_id = fl_session.get("user_id")
db_session = db.Session()
ccss = db_session.query(db.CustomCSS).filter_by(royal_id=user_id).one_or_none()
if request.method == "GET":
db_session.close()
if user_id is None:
abort(403)
return
return render_template("setcss.html", css=ccss.css)
elif request.method == "POST":
if user_id is None:
abort(403)
return
if ccss is None:
ccss = db.CustomCSS(royal_id=user_id, css=request.form.get("css", ""))
db_session.add(ccss)
else:
ccss.css = request.form.get("css", "")
db_session.commit()
royal = db_session.query(db.Royal).filter_by(id=user_id).one()
db_session.close()
return redirect(url_for("page_profile", name=royal.username))
if __name__ == "__main__":
try:
app.run(host="0.0.0.0", port=1234, debug=__debug__)