add: sessions save

This commit is contained in:
starnakin 2023-06-09 15:22:50 +02:00
parent f79f66fcef
commit 161a7ff5b3
8 changed files with 27 additions and 4 deletions

View File

@ -21,8 +21,9 @@ docker build -t zeolak .
``` bash
docker-compose up -d
```
6. Edit the config
setup the database acces
6. Edit the config\
`secret`: change to a random string\
`database`: setup the database acces
7. Relauch the docker
``` bash
docker-compose up -d
@ -36,4 +37,4 @@ docker build -t zeolak --no-cache .
2. Relaunch the docker
``` bash
docker-compose up -d
```
```

View File

@ -5,6 +5,7 @@ try:
data = json.load(f)
except:
data = {
"secret": "SECRET_KEY",
"database": {
"ip": "localhost",
"port": 3306,
@ -20,3 +21,4 @@ except:
database = data.get("database");
secret = data.get("secret")

View File

@ -1,4 +1,5 @@
{
"secret": "change me",
"database": {
"ip": "localhost",
"port": 3306,

View File

@ -5,10 +5,13 @@ page = flask.Blueprint("login", __name__, template_folder="templates")
@page.route("/login", methods=['POST', 'GET'])
def show():
if (flask.session.get("email")):
return (flask.redirect("/panel"))
if (flask.request.method == 'GET'):
return (flask.render_template("login/login.html"))
email = flask.request.form['email']
password = flask.request.form['password']
if (database.database.account_test(email, password)):
return (flask.render_template("login/login.html", error = "Invalid credentials"))
flask.session["email"] = email;
return (flask.redirect("/panel"))

9
logout.py Normal file
View File

@ -0,0 +1,9 @@
import flask
page = flask.Blueprint("logout", __name__, template_folder="templates")
@page.route("/logout")
def show():
if (flask.session.get("email")):
flask.session.pop("email", None)
return (flask.redirect("/"))

View File

@ -1,13 +1,16 @@
import flask
import database
import home, login, panel, register
import config
import home, login, panel, register, logout
app = flask.Flask(__name__)
app.secret_key = config.secret
if (__name__ == "__main__"):
app.register_blueprint(home.page)
app.register_blueprint(login.page)
app.register_blueprint(panel.page)
app.register_blueprint(register.page)
app.register_blueprint(logout.page)
app.run(host="0.0.0.0")

View File

@ -4,4 +4,6 @@ page = flask.Blueprint("panel", __name__, template_folder="templates")
@page.route("/panel")
def show():
if (not flask.session.get("email")):
return (flask.redirect("/login"))
return (flask.render_template("panel/panel.html"))

View File

@ -6,6 +6,8 @@ page = flask.Blueprint("register", __name__, template_folder="templates")
@page.route("/register", methods = ['POST', 'GET'])
def show():
if (flask.session.get("email")):
return (flask.redirect("/panel"))
if (flask.request.method == 'GET'):
return (flask.render_template("register/register.html", error = None))
email = flask.request.form.get("email");