-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathauth.py
38 lines (30 loc) · 1.07 KB
/
auth.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
__author__ = 'powergx'
from util import hash_password
import json
from flask import Response, request, session, redirect, url_for
from functools import wraps
from crysadm import r_session
def requires_admin(f):
@wraps(f)
def decorated(*args, **kwargs):
if session.get('user_info') is None:
return redirect(url_for('login'))
if session.get('user_info').get('is_admin') is None or not session.get('user_info').get('is_admin'):
return redirect(url_for('dashboard'))
__handshake()
return f(*args, **kwargs)
return decorated
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
if session.get('user_info') is None:
return redirect(url_for('login'))
__handshake()
return f(*args, **kwargs)
return decorated
def __handshake():
user = session.get('user_info')
username = user.get('username') if user.get('username') is not None else ''
key = 'user:%s:is_online' % username
r_session.setex(key, '1', 120)
r_session.sadd('global:online.users', username)