-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
92 lines (82 loc) · 3.19 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from pymongo import MongoClient
from django.http import HttpResponseNotFound
def connectMongo(db_name):
client = MongoClient('mongodb+srv://altair-admin-victor:[email protected]/?retryWrites=true&w=majority&socketTimeoutMS=360000&connectTimeoutMS=360000')
db = client[db_name]
return db
def addRegra(database,regra):
collections = database['regra']
def authenticate(user,password):
db_client = connectMongo('Altair')
collection_usuario = db_client['usuario']
user_temp = collection_usuario.find_one({'userID':user,'senha':password})
if user_temp != None:
return [True,user_temp]
else:
return [False,None]
from django.contrib import messages
from django.shortcuts import redirect
def gestor_required(f):
def verifica(request, *args, **kwargs):
if request.session['cargo']!='Gestor':
messages.info(request, 'Necessario logar como gestor')
return redirect('/login')
else:
return f(request, *args, **kwargs)
verifica.__doc__= f.__doc__
verifica.__name__= f.__name__
return verifica
def aud_required(f):
def verifica(request, *args, **kwargs):
if request.session['cargo']!='Auditor':
messages.info(request, 'Necessario logar como auditor')
return redirect('/login')
else:
return f(request, *args, **kwargs)
verifica.__doc__= f.__doc__
verifica.__name__= f.__name__
return verifica
def login_required(f):
def verifica(request, *args, **kwargs):
if len(request.session.keys()) == 0:
messages.info(request, 'Necessario relizar login')
return redirect('/login')
else:
if request.session['logged'] == False:
messages.info(request, 'Necessario relizar login')
return redirect('/login')
return f(request, *args, **kwargs)
verifica.__doc__= f.__doc__
verifica.__name__= f.__name__
return verifica
def logged(f):
def verifica(request, *args, **kwargs):
if len(request.session.keys()) != 0:
#messages.info(request, 'Usuario: '+request.session['nome']+' já logado')
if request.session['cargo']=='Auditor':
return redirect('/aud')
if request.session['cargo']=='Gestor':
return redirect('/gestor')
else:
return f(request, *args, **kwargs)
verifica.__doc__= f.__doc__
verifica.__name__= f.__name__
return verifica
def POST_required(f):
def verifica(request, *args, **kwargs):
if request.method == 'POST':
return f(request, *args, **kwargs)
else:
return HttpResponseNotFound('404')
verifica.__doc__= f.__doc__
verifica.__name__= f.__name__
return verifica
def GET_required(f):
def verifica(request, *args, **kwargs):
if request.method == 'GET':
return f(request, *args, **kwargs)
else:
return HttpResponseNotFound('404')
verifica.__doc__= f.__doc__
verifica.__name__= f.__name__
return verifica