Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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):
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'])
user = users.get_current_user()
if user:
user = GoogleUser(user)
if not user:
user = GuestUser()
return user
def add_user_to_globals():
g.user = get_current_user()
def some_path():
user = g.user
if user.is_admin():
return render_template('admin.html', user=user)
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