add: sessions save
This commit is contained in:
parent
f79f66fcef
commit
161a7ff5b3
@ -21,8 +21,9 @@ docker build -t zeolak .
|
|||||||
``` bash
|
``` bash
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
6. Edit the config
|
6. Edit the config\
|
||||||
setup the database acces
|
`secret`: change to a random string\
|
||||||
|
`database`: setup the database acces
|
||||||
7. Relauch the docker
|
7. Relauch the docker
|
||||||
``` bash
|
``` bash
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
@ -36,4 +37,4 @@ docker build -t zeolak --no-cache .
|
|||||||
2. Relaunch the docker
|
2. Relaunch the docker
|
||||||
``` bash
|
``` bash
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
@ -5,6 +5,7 @@ try:
|
|||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
except:
|
except:
|
||||||
data = {
|
data = {
|
||||||
|
"secret": "SECRET_KEY",
|
||||||
"database": {
|
"database": {
|
||||||
"ip": "localhost",
|
"ip": "localhost",
|
||||||
"port": 3306,
|
"port": 3306,
|
||||||
@ -20,3 +21,4 @@ except:
|
|||||||
|
|
||||||
|
|
||||||
database = data.get("database");
|
database = data.get("database");
|
||||||
|
secret = data.get("secret")
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"secret": "change me",
|
||||||
"database": {
|
"database": {
|
||||||
"ip": "localhost",
|
"ip": "localhost",
|
||||||
"port": 3306,
|
"port": 3306,
|
||||||
|
3
login.py
3
login.py
@ -5,10 +5,13 @@ page = flask.Blueprint("login", __name__, template_folder="templates")
|
|||||||
|
|
||||||
@page.route("/login", methods=['POST', 'GET'])
|
@page.route("/login", methods=['POST', 'GET'])
|
||||||
def show():
|
def show():
|
||||||
|
if (flask.session.get("email")):
|
||||||
|
return (flask.redirect("/panel"))
|
||||||
if (flask.request.method == 'GET'):
|
if (flask.request.method == 'GET'):
|
||||||
return (flask.render_template("login/login.html"))
|
return (flask.render_template("login/login.html"))
|
||||||
email = flask.request.form['email']
|
email = flask.request.form['email']
|
||||||
password = flask.request.form['password']
|
password = flask.request.form['password']
|
||||||
if (database.database.account_test(email, password)):
|
if (database.database.account_test(email, password)):
|
||||||
return (flask.render_template("login/login.html", error = "Invalid credentials"))
|
return (flask.render_template("login/login.html", error = "Invalid credentials"))
|
||||||
|
flask.session["email"] = email;
|
||||||
return (flask.redirect("/panel"))
|
return (flask.redirect("/panel"))
|
||||||
|
9
logout.py
Normal file
9
logout.py
Normal 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("/"))
|
5
main.py
5
main.py
@ -1,13 +1,16 @@
|
|||||||
import flask
|
import flask
|
||||||
import database
|
import database
|
||||||
import home, login, panel, register
|
import config
|
||||||
|
import home, login, panel, register, logout
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
|
app.secret_key = config.secret
|
||||||
|
|
||||||
if (__name__ == "__main__"):
|
if (__name__ == "__main__"):
|
||||||
app.register_blueprint(home.page)
|
app.register_blueprint(home.page)
|
||||||
app.register_blueprint(login.page)
|
app.register_blueprint(login.page)
|
||||||
app.register_blueprint(panel.page)
|
app.register_blueprint(panel.page)
|
||||||
app.register_blueprint(register.page)
|
app.register_blueprint(register.page)
|
||||||
|
app.register_blueprint(logout.page)
|
||||||
app.run(host="0.0.0.0")
|
app.run(host="0.0.0.0")
|
||||||
|
|
||||||
|
2
panel.py
2
panel.py
@ -4,4 +4,6 @@ page = flask.Blueprint("panel", __name__, template_folder="templates")
|
|||||||
|
|
||||||
@page.route("/panel")
|
@page.route("/panel")
|
||||||
def show():
|
def show():
|
||||||
|
if (not flask.session.get("email")):
|
||||||
|
return (flask.redirect("/login"))
|
||||||
return (flask.render_template("panel/panel.html"))
|
return (flask.render_template("panel/panel.html"))
|
||||||
|
@ -6,6 +6,8 @@ page = flask.Blueprint("register", __name__, template_folder="templates")
|
|||||||
|
|
||||||
@page.route("/register", methods = ['POST', 'GET'])
|
@page.route("/register", methods = ['POST', 'GET'])
|
||||||
def show():
|
def show():
|
||||||
|
if (flask.session.get("email")):
|
||||||
|
return (flask.redirect("/panel"))
|
||||||
if (flask.request.method == 'GET'):
|
if (flask.request.method == 'GET'):
|
||||||
return (flask.render_template("register/register.html", error = None))
|
return (flask.render_template("register/register.html", error = None))
|
||||||
email = flask.request.form.get("email");
|
email = flask.request.form.get("email");
|
||||||
|
Loading…
Reference in New Issue
Block a user