-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecorators.py
More file actions
31 lines (26 loc) · 1.05 KB
/
decorators.py
File metadata and controls
31 lines (26 loc) · 1.05 KB
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
from exceptions import InputError, error_messages
from validate_email import validate_email
from functools import wraps
from flask import session, redirect, url_for, request
def login_required(f):
@wraps(f)
def decorated(*args, **kwargs):
if 'profile' not in session:
# Redirect to Login page here
return redirect('/login')
return f(*args, **kwargs)
return decorated
def check_user(f):
def d(self, email, password, first_name=None, last_name=None):
if not email or not validate_email(email):
raise InputError(email, [2])
if not password:
raise InputError('Password', error_messages[3])
if first_name:
if not all(x.isalpha() or x.isspace() for x in first_name):
raise InputError(first_name, error_messages[4])
if last_name:
if not last_name.isalpha():
raise InputError(last_name, error_messages[4])
f(self, email, password, first_name, last_name)
return d