from flask import abort from flask_login import UserMixin, LoginManager login_manager = LoginManager() class User(UserMixin): def __init__(self, id, admin=False): self.admin = admin self.id = id def __unicode__(self): return u"{}".format(self.id) def __str__(self): return str(self.id) @property def is_admin(self): return self.admin admin_user = User("admin", True) @login_manager.user_loader def load_user(id): if id == "admin": return admin_user return User(id) @login_manager.unauthorized_handler def unauthorized(): return abort(403)