Start repo
This commit is contained in:
35
app/utils.py
Normal file
35
app/utils.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from flask import Flask, render_template, url_for, request, flash, redirect, session
|
||||
from functools import wraps
|
||||
import os
|
||||
|
||||
|
||||
def login_required(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if 'username' not in session:
|
||||
return redirect(url_for('login', next=request.url))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
def init_app(config):
|
||||
|
||||
if 'USERS_FOLDER' in config.keys() and 'PUBLIC_FOLDER' in config.keys():
|
||||
users_folder = config['USERS_FOLDER']
|
||||
public_folder = config['PUBLIC_FOLDER']
|
||||
else:
|
||||
print ("L'application n'est pas configuré correctement, veuillez renseigner les paramètres USERS_FOLDER et/ou PUBLIC_FOLDER ne sont pas configuré")
|
||||
return False
|
||||
|
||||
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))
|
||||
|
||||
if os.path.isdir(public_folder):
|
||||
print("Le dossier {} existe".format(public_folder))
|
||||
else:
|
||||
os.makedirs(public_folder)
|
||||
print("Le dossier {} a été créé".format(public_folder))
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user