Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
googappapiflaskIDs
from flask import g, session
from google.appengine.api import users
class GuestUser(object):
def email(self):
return None
def nickname(self):
return 'Guest'
def is_admin(self):
return False
def user_type(self):
return 'guest'
class GoogleUser(object):
def __init__(self, google_user):
self.google_user = google_user
def email(self):
return self.google_user.email()
def nickname(self):
return self.google_user.nickname()
def is_admin(self):
return users.is_current_user_admin()
def user_type(self):
return 'google'
class TwitterUser(object):
# add these to twitter user.
def email(self):
return None
def nickname(self):
return self.screen_name
def is_admin(self):
authorized_users = ['maxart', 'lukeinth']
return self.screen_name in authorized_users
def user_type(self):
return 'twitter'
def get_current_user():
user_id = session.get('user_id')
user = None
if user_id:
user = TwitterUser.get_by_user_id(session['user_id'])
else:
user = users.get_current_user()
if user:
user = GoogleUser(user)
if not user:
user = GuestUser()
return user
@app.before_request
def add_user_to_globals():
g.user = get_current_user()
@app.route('/some/path')
def some_path():
user = g.user
if user.is_admin():
return render_template('admin.html', user=user)
else:
return render_template('normal.html', user=user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.