-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
34 lines (26 loc) · 847 Bytes
/
helpers.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
# Description: Helper functions for the application
# import libraries
from flask import session, flash, redirect, url_for
from functools import wraps
def login_required(f):
"""
Decorator function to require login.
"""
@wraps(f)
def decorated_function(*args, **kwargs):
if not session.get("user_id"):
flash("You must be logged in to access this page.")
return redirect(url_for("login"))
return f(*args, **kwargs)
return decorated_function
def logout_required(f):
"""
Decorator function to require logOUT.
"""
@wraps(f)
def decorated_function(*args, **kwargs):
if session.get("user_id"):
flash("You are already logged in.")
return redirect(url_for("chat"))
return f(*args, **kwargs)
return decorated_function