PyMenuSite/main.py

78 lines
2.2 KiB
Python
Raw Normal View History

2023-02-11 08:37:10 -05:00
from flask import Flask, render_template, request, redirect, session
from flask_session import Session
import utils
import database
2023-02-10 08:17:47 -05:00
app = Flask(__name__);
2023-02-11 08:37:10 -05:00
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
2023-02-10 08:17:47 -05:00
@app.route("/")
def home():
2023-02-11 08:37:10 -05:00
return (render_template("home.html"));
@app.route("/connected")
def connected():
if (not session.get("email")):
return (redirect("/login"))
return (render_template("connected.html"));
@app.route("/login")
def login():
return (render_template("login.html"));
@app.route('/login', methods=['POST'])
def login_post():
2023-02-11 10:06:36 -05:00
if (not session.get("email")):
return (redirect("/connected"))
2023-02-11 08:37:10 -05:00
email = request.form.get('email')
password = request.form.get('password')
if (not database.user_exist(email)):
return (render_template("login.html", error="Email ou mot de passe faux"))
if (not database.check_password(email, password)):
return (render_template("login.html", error="Email ou mot de passe faux"))
session["email"] = email
return (redirect("/connected"))
@app.route('/logout')
def logout():
session.pop('email', None)
return redirect("/login")
@app.route("/signin")
def signin():
return (render_template("signin.html"));
@app.route('/signin', methods=['POST'])
def signup_post():
2023-02-11 10:06:36 -05:00
if (not session.get("email")):
return (redirect("/connected"))
2023-02-11 08:37:10 -05:00
email = request.form.get('email')
password = request.form.get('password')
repassword = request.form.get('repassword')
if (password != repassword):
return (render_template("signin.html", error="Les deux mots de passe sont differents"))
if (utils.check_email(email)):
return (render_template("signin.html", error="Votre email n'est pas valdie"))
if (database.user_exist(email)):
return (render_template("signin.html", error="Email deja utilisé"))
database.add_user(email, password);
return (redirect("/connected"))
@app.route("/forgot")
def forgot():
return (render_template("forgot.html"));
@app.route("/reset/<uuid>")
def reset(uuid):
return ("bozo")
@app.route("/join/<uuid>")
def join(uuid):
return ("bozo")
2023-02-10 08:17:47 -05:00
if __name__ == '__main__':
2023-02-11 08:37:10 -05:00
app.run(host='0.0.0.0', port=5000, debug=1)