add: sessions save
This commit is contained in:
parent
f79f66fcef
commit
161a7ff5b3
@ -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
|
||||
|
@ -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")
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"secret": "change me",
|
||||
"database": {
|
||||
"ip": "localhost",
|
||||
"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'])
|
||||
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
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 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")
|
||||
|
||||
|
2
panel.py
2
panel.py
@ -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"))
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user