Reformatage et suppression du .htaccess

This commit is contained in:
Valentin Moguérou 2023-05-17 00:03:11 +02:00
parent 7619f24fce
commit 22725ff897
3 changed files with 14 additions and 27 deletions

View File

@ -1,18 +0,0 @@
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/wdgl1530/antinote.fr"
PassengerBaseURI "/"
PassengerPython "/home/wdgl1530/virtualenv/antinote.fr/3.10/bin/python"
PassengerAppLogFile "/home/wdgl1530/logs/passenger.log"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END

View File

@ -2,6 +2,7 @@ from uuid import uuid4
import mysql.connector import mysql.connector
class Database: class Database:
def __init__(self, app): def __init__(self, app):
self.db = mysql.connector.connect( self.db = mysql.connector.connect(
@ -32,13 +33,13 @@ class Database:
def check_connection(self, uuid): def check_connection(self, uuid):
self.cur.execute("DELETE FROM sessions WHERE expiry_date <= CURRENT_TIMESTAMP") self.cur.execute("DELETE FROM sessions WHERE expiry_date <= CURRENT_TIMESTAMP")
self.cur.execute("SELECT session_id FROM sessions WHERE session_id=%s", (uuid,)) self.cur.execute("SELECT session_id FROM sessions WHERE session_id=%s", (uuid,))
result = self.cur.fetchall() return self.cur.fetchall()
return result
def __del__(self): def __del__(self):
self.cur.close() self.cur.close()
self.db.close() self.db.close()
class User: class User:
def __init__(self, user_id, username, nom, prenom, creation_date): def __init__(self, user_id, username, nom, prenom, creation_date):
self.id = user_id self.id = user_id
@ -47,6 +48,7 @@ class User:
self.prenom = prenom self.prenom = prenom
self.creation_date = creation_date self.creation_date = creation_date
class Session: class Session:
def __init__(self, db, uuid): def __init__(self, db, uuid):
self.db = db self.db = db
@ -55,14 +57,15 @@ class Session:
def get_user(self): def get_user(self):
self.db.cur.execute("SELECT utilisateurs.user_id, username, nom, prenom, creation_date FROM utilisateurs " self.db.cur.execute("SELECT utilisateurs.user_id, username, nom, prenom, creation_date FROM utilisateurs "
"JOIN sessions ON utilisateurs.user_id=sessions.user_id WHERE session_id=%s", (self.uuid,)) "JOIN sessions ON utilisateurs.user_id=sessions.user_id WHERE session_id=%s", (self.uuid,))
result = self.db.cur.fetchall() result = self.db.cur.fetchall()
return User(*result[0]) return User(*result[0])
def fetch_grades(self): def fetch_grades(self):
self.db.cur.execute("SELECT matieres.libelle, devoirs.libelle, date, coefficient, valeur, maximum FROM notes " self.db.cur.execute("SELECT matieres.libelle, devoirs.libelle, date, coefficient, valeur, maximum FROM notes "
"JOIN devoirs ON notes.id_devoir=devoirs.id_devoir " "JOIN devoirs ON notes.id_devoir=devoirs.id_devoir "
"JOIN matieres ON devoirs.id_matiere=matieres.id_matiere WHERE id_eleve=%s", (self.user.id,)) "JOIN matieres ON devoirs.id_matiere=matieres.id_matiere WHERE id_eleve=%s",
(self.user.id,))
result = self.db.cur.fetchall() result = self.db.cur.fetchall()
dico = {} dico = {}
@ -71,4 +74,4 @@ class Session:
dico[note[0]].append(note) dico[note[0]].append(note)
else: else:
dico[note[0]] = [note] dico[note[0]] = [note]
return dico return dico

View File

@ -6,6 +6,7 @@ from flask import render_template, send_from_directory, request, session, redire
from .database import Session from .database import Session
def views(app, db): def views(app, db):
def est_connecte(): def est_connecte():
return session.get("uuid") is not None and db.check_connection(session.get("uuid")) return session.get("uuid") is not None and db.check_connection(session.get("uuid"))
@ -15,6 +16,7 @@ def views(app, db):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
return func(*args, **kwargs) if est_connecte() else redirect("/login") return func(*args, **kwargs) if est_connecte() else redirect("/login")
return wrapper return wrapper
@app.route("/") @app.route("/")
@login_required @login_required
def index(): def index():
@ -44,8 +46,8 @@ def views(app, db):
@login_required @login_required
def grades(): def grades():
s = Session(db, session["uuid"]) s = Session(db, session["uuid"])
grades = s.fetch_grades() g = s.fetch_grades()
return render_template("grades.html", s=s, grades=grades) return render_template("grades.html", s=s, grades=g)
@app.route("/timetable/") @app.route("/timetable/")
@login_required @login_required