Add login_required decorator
This commit is contained in:
@@ -5,17 +5,12 @@ from tools.utils import gen_token
|
||||
from flask_bcrypt import Bcrypt
|
||||
|
||||
app = Flask( 'pywallter' )
|
||||
app.config.from_pyfile('config.py')
|
||||
bcrypt = Bcrypt(app)
|
||||
|
||||
DATABASE = app.config['DATABASE']
|
||||
DOSSIER_PERSO = app.config['DOSSIER_APP']
|
||||
DATABASE = app.config['DATABASE']
|
||||
|
||||
|
||||
|
||||
def init_db():
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
def init_db(database):
|
||||
conn = sqlite3.connect(database)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users(
|
||||
@@ -81,14 +76,16 @@ def init_db():
|
||||
conn.close()
|
||||
print ('table posts OK')
|
||||
|
||||
def init_dir():
|
||||
if os.path.isdir('users'):
|
||||
return False
|
||||
else:
|
||||
os.makedirs('./users/')
|
||||
def check_directories(users_folder):
|
||||
|
||||
def db_migrate():
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
if os.path.isdir(users_folder):
|
||||
print("Le dossier {} existe".format(users_folder))
|
||||
else:
|
||||
os.makedirs(users_folder)
|
||||
print("Le dossier {} a été créé".format(users_folder))
|
||||
|
||||
def db_migrate(database):
|
||||
conn = sqlite3.connect(database)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('users');""")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from flask import Flask
|
||||
from flask import Flask, url_for, session, redirect, request
|
||||
from functools import wraps
|
||||
import sqlite3
|
||||
import os
|
||||
import string
|
||||
@@ -14,6 +15,17 @@ DATABASE = app.config['DATABASE']
|
||||
DOSSIER_PERSO = app.config['DOSSIER_APP']
|
||||
DATABASE = app.config['DATABASE']
|
||||
|
||||
|
||||
def login_required(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if 'username' not in session:
|
||||
return redirect(url_for('loginlogout.login', next=request.url))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
|
||||
|
||||
def append_to_log(log_line, user):
|
||||
log_file=os.path.join(DOSSIER_PERSO, user, "log.txt")
|
||||
logs=open(log_file, "r")
|
||||
|
||||
Reference in New Issue
Block a user