-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
43 lines (34 loc) · 1.18 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
from functools import wraps
from flask import url_for, redirect, session, g, flash
from models import User
def auth_required(f):
@wraps(f)
def wrapper(*args, **kwargs):
user = get_auth_user()
if user:
g.user = user
else:
return redirect(url_for("home"))
return f(*args, **kwargs)
return wrapper
def get_auth_user():
try:
if "credentials" in session:
g_user_id = session["credentials"].id_token["sub"]
return User.query.filter_by(google_user_id=g_user_id).first()
except:
return None
# def get_auth_http():
# credentials = session["credentials"]
# return credentials.authorize(httplib2.Http())
def detect_default_email():
"""flashes user about default email that is caused be youtube and G+ mess.
youtube id has been merged with google id and youtube users that are not
linked to gmail have @pages.plusgoogle.com email.
requires auth_requred()
"""
if "@pages.plusgoogle.com" in g.user.email:
flash(
"Your email %s. is default."
"Click your name in the navigation bar to change it." %
(g.user.email,), "warning")