# 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
        self.app = app
        self.config = {}
        if app:
            self.init_app(app)

    def init_app(self, app):
        self.config = app.config

        if not self.config['DOORMAN_OAUTH_CLIENT_ID']:
            raise ValueError("DOORMAN_OAUTH_CLIENT_ID must be configured")

        if not self.config['DOORMAN_OAUTH_CLIENT_SECRET']:
            raise ValueError("DOORMAN_OAUTH_CLIENT_SECRET must be configured")

        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_BASE_URL',
                               'https://accounts.google.com/o/oauth2/auth')
        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_TOKEN_URL',
                               'https://www.googleapis.com/oauth2/v3/token')
        self.config.setdefault('DOORMAN_AUTH_REDIRECT_VIEW',
                               'users.oauth2callback')

        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_SCOPE', ['email', 'profile'])

        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_ALLOWED_DOMAINS', [])
        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_ALLOWED_USERS', [])

        app.oauth_provider = self

    @property
    def allowed_users(self):

# 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

        self.app = app
        self.config = {}
        if app:
            self.init_app(app)

    def init_app(self, app):
        self.config = app.config

        if not self.config['DOORMAN_OAUTH_CLIENT_ID']:
            raise ValueError("DOORMAN_OAUTH_CLIENT_ID must be configured")

        if not self.config['DOORMAN_OAUTH_CLIENT_SECRET']:
            raise ValueError("DOORMAN_OAUTH_CLIENT_SECRET must be configured")

        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_BASE_URL',
                               'https://accounts.google.com/o/oauth2/auth')
        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_TOKEN_URL',
                               'https://www.googleapis.com/oauth2/v3/token')
        self.config.setdefault('DOORMAN_AUTH_REDIRECT_VIEW',
                               'users.oauth2callback')

        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_SCOPE', ['email', 'profile'])

        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_ALLOWED_DOMAINS', [])
        self.config.setdefault('DOORMAN_OAUTH_GOOGLE_ALLOWED_USERS', [])

        app.oauth_provider = self

    @property
    def allowed_users(self):

        return self.config.get('DOORMAN_OAUTH_GOOGLE_ALLOWED_USERS', [])