# Path: doorman/models.py
# class User(UserMixin, SurrogatePK, Model):
# 
#     username = Column(db.String(80), unique=True, nullable=False)
#     email = Column(db.String)
# 
#     password = Column(db.String, nullable=True)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
# 
#     # oauth related stuff
#     social_id = Column(db.String)
#     first_name = Column(db.String)
#     last_name = Column(db.String)
# 
#     def __init__(self, username, password=None, email=None, social_id=None,
#                  first_name=None, last_name=None):
#         self.username = username
#         self.email = email
#         if password:
#             self.set_password(password)
#         else:
#             self.password = None
# 
#         self.social_id = social_id
#         self.first_name = first_name
#         self.last_name = last_name
# 
#     def set_password(self, password):
#         self.update(password=bcrypt.generate_password_hash(password))
#         return
# 
#     def check_password(self, value):
#         if not self.password:
#             # still do the computation
#             return bcrypt.generate_password_hash(value) and False
#         return bcrypt.check_password_hash(self.password, value)


from flask import abort, current_app, flash, request, session, url_for
from requests_oauthlib import OAuth2Session
from doorman.models import User
            current_app.logger.error("No userinfo object returned!")
            abort(500)

        current_app.logger.debug("Got userinfo: %s", userinfo)

        if self.allowed_users and userinfo['email'] not in self.allowed_users:
            current_app.logger.error("%s is not authorized for this application",
                                     userinfo['email'])
            flash(u"{0} is not authorized for this application.".format(
                  userinfo['email']), 'danger')
            abort(401)

        if self.allowed_domains and userinfo['hd'] not in self.allowed_domains:
            current_app.logger.error("%s domain and %s not authorized",
                                     userinfo['hd'], userinfo['email'])
            flash(u"{0} is not authorized for this application.".format(
                  userinfo['email']), 'danger')
            abort(401)

        if not userinfo['verified_email']:
            flash(u"You must verify your email before using this application.",
                  'danger')
            abort(401)

        user = User.query.filter_by(
            email=userinfo['email'],
            social_id=userinfo['id'],
        ).first()

        if not user:

# Path: doorman/models.py
# class User(UserMixin, SurrogatePK, Model):
# 
#     username = Column(db.String(80), unique=True, nullable=False)
#     email = Column(db.String)
# 
#     password = Column(db.String, nullable=True)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
# 
#     # oauth related stuff
#     social_id = Column(db.String)
#     first_name = Column(db.String)
#     last_name = Column(db.String)
# 
#     def __init__(self, username, password=None, email=None, social_id=None,
#                  first_name=None, last_name=None):
#         self.username = username
#         self.email = email
#         if password:
#             self.set_password(password)
#         else:
#             self.password = None
# 
#         self.social_id = social_id
#         self.first_name = first_name
#         self.last_name = last_name
# 
#     def set_password(self, password):
#         self.update(password=bcrypt.generate_password_hash(password))
#         return
# 
#     def check_password(self, value):
#         if not self.password:
#             # still do the computation
#             return bcrypt.generate_password_hash(value) and False
#         return bcrypt.check_password_hash(self.password, value)


# Path: doorman/users/oauth.py
from flask import abort, current_app, flash, request, session, url_for
from requests_oauthlib import OAuth2Session
from doorman.models import User

            current_app.logger.error("No userinfo object returned!")
            abort(500)

        current_app.logger.debug("Got userinfo: %s", userinfo)

        if self.allowed_users and userinfo['email'] not in self.allowed_users:
            current_app.logger.error("%s is not authorized for this application",
                                     userinfo['email'])
            flash(u"{0} is not authorized for this application.".format(
                  userinfo['email']), 'danger')
            abort(401)

        if self.allowed_domains and userinfo['hd'] not in self.allowed_domains:
            current_app.logger.error("%s domain and %s not authorized",
                                     userinfo['hd'], userinfo['email'])
            flash(u"{0} is not authorized for this application.".format(
                  userinfo['email']), 'danger')
            abort(401)

        if not userinfo['verified_email']:
            flash(u"You must verify your email before using this application.",
                  'danger')
            abort(401)

        user = User.query.filter_by(
            email=userinfo['email'],
            social_id=userinfo['id'],
        ).first()

        if not user:

            user = User.create(