# Path: makesite/modules/flask/base/ext.py
# def config_extensions(app):
# def config_babel(app):
#     def get_locale():
# 
# Path: makesite/modules/flask/base/auth/models.py
# class User(db.Model, UserMixin, BaseMixin):
#     " Main user model. "
# 
#     __tablename__ = 'users_user'
# 
#     username = db.Column(db.String(50), unique=True)
#     email = db.Column(db.String(120))
#     active = db.Column(db.Boolean, default=True)
#     _pw_hash = db.Column(db.String(199), nullable=False)
# 
#     # OAuth creds
#     oauth_token = db.Column(db.String(200))
#     oauth_secret = db.Column(db.String(200))
# 
#     @declared_attr
#     def roles(self):
#         assert self
#         return db.relationship("Role", secondary=userroles, backref="users")
# 
#     @hybrid_property
#     def pw_hash(self):
#         """Simple getter function for the user's password."""
#         return self._pw_hash
# 
#     @pw_hash.setter
#     def pw_hash(self, raw_password):
#         """ Password setter, that handles the hashing
#             in the database.
#         """
#         self._pw_hash = generate_password_hash(raw_password)
# 
#     @staticmethod
#     def permission(role):
#         perm = Permission(RoleNeed(role))
#         return perm.can()
# 
#     def check_password(self, password):
#         return check_password_hash(self.pw_hash, password)
# 
#     def is_active(self):
#         return self.active
# 
#     def __unicode__(self):
#         return self.username
# 
#     def __repr__(self):
#         return '<User %r>' % (self.username)
# 
# Path: makesite/modules/flask/base/auth/views.py
# def profile():
# def login():
# def logout():
# def register():


from flask import url_for, request, flash, redirect
from flask_login import current_user
from flaskext.babel import lazy_gettext as _
from flaskext.oauth import OAuth
from random import choice
from ..ext import db
from .models import User
from .views import users
            return current_user.oauth_token, current_user.oauth_secret

    def authorize(self, resp):
        pass


class OAuthTwitter(OAuthBase):
    name = 'twitter'

    def authorize(self, resp):
        next_url = request.args.get('next') or url_for('urls.index')
        if resp is None:
            flash(_(u'You denied the request to sign in.'))
            return redirect(next_url)

        user = current_user
        if not user.is_authenticated():
            user = User.query.filter(
                User.username == resp['screen_name']).first()

            if user is None:
                user = User(
                    username=resp['screen_name'],
                    pw_hash=''.join(choice(ASCII_LOWERCASE) for c in xrange(15)))
                db.session.add(user)

        user.oauth_token = resp['oauth_token']
        user.oauth_secret = resp['oauth_token_secret']
        db.session.commit()


# Path: makesite/modules/flask/base/ext.py
# def config_extensions(app):
# def config_babel(app):
#     def get_locale():
# 
# Path: makesite/modules/flask/base/auth/models.py
# class User(db.Model, UserMixin, BaseMixin):
#     " Main user model. "
# 
#     __tablename__ = 'users_user'
# 
#     username = db.Column(db.String(50), unique=True)
#     email = db.Column(db.String(120))
#     active = db.Column(db.Boolean, default=True)
#     _pw_hash = db.Column(db.String(199), nullable=False)
# 
#     # OAuth creds
#     oauth_token = db.Column(db.String(200))
#     oauth_secret = db.Column(db.String(200))
# 
#     @declared_attr
#     def roles(self):
#         assert self
#         return db.relationship("Role", secondary=userroles, backref="users")
# 
#     @hybrid_property
#     def pw_hash(self):
#         """Simple getter function for the user's password."""
#         return self._pw_hash
# 
#     @pw_hash.setter
#     def pw_hash(self, raw_password):
#         """ Password setter, that handles the hashing
#             in the database.
#         """
#         self._pw_hash = generate_password_hash(raw_password)
# 
#     @staticmethod
#     def permission(role):
#         perm = Permission(RoleNeed(role))
#         return perm.can()
# 
#     def check_password(self, password):
#         return check_password_hash(self.pw_hash, password)
# 
#     def is_active(self):
#         return self.active
# 
#     def __unicode__(self):
#         return self.username
# 
#     def __repr__(self):
#         return '<User %r>' % (self.username)
# 
# Path: makesite/modules/flask/base/auth/views.py
# def profile():
# def login():
# def logout():
# def register():


# Path: makesite/modules/flask/base/auth/oauth.py
from flask import url_for, request, flash, redirect
from flask_login import current_user
from flaskext.babel import lazy_gettext as _
from flaskext.oauth import OAuth
from random import choice
from ..ext import db
from .models import User
from .views import users

            return current_user.oauth_token, current_user.oauth_secret

    def authorize(self, resp):
        pass


class OAuthTwitter(OAuthBase):
    name = 'twitter'

    def authorize(self, resp):
        next_url = request.args.get('next') or url_for('urls.index')
        if resp is None:
            flash(_(u'You denied the request to sign in.'))
            return redirect(next_url)

        user = current_user
        if not user.is_authenticated():
            user = User.query.filter(
                User.username == resp['screen_name']).first()

            if user is None:
                user = User(
                    username=resp['screen_name'],
                    pw_hash=''.join(choice(ASCII_LOWERCASE) for c in xrange(15)))
                db.session.add(user)

        user.oauth_token = resp['oauth_token']
        user.oauth_secret = resp['oauth_token_secret']
        db.session.commit()


        users.login(user)