# Path: makesite/modules/flask/base/ext.py
# def config_extensions(app):
# def config_babel(app):
#     def get_locale():
# 
# Path: makesite/modules/flask/base/auth/forms.py
# class RegisterForm(Form, EmailFormMixin, PasswordFormMixin, PasswordConfirmFormMixin):
#     "  The default register form. "
# 
#     username = TextField(_('UserName'), [Required(message=_('Required'))])
#     # submit = SubmitField(_("Register"))
# 
#     def to_dict(self):
#         return dict(email=self.email.data, password=self.password.data)
# 
# class LoginForm(Form, EmailFormMixin, PasswordFormMixin):
#     " The default login form. "
# 
#     remember = BooleanField(_("Remember Me"), default=True)
#     next = HiddenField()
#     submit = SubmitField(_("Login"))
# 
#     def __init__(self, *args, **kwargs):
#         super(LoginForm, self).__init__(*args, **kwargs)
# 
#         if request.method == 'GET':
#             self.next.data = request.args.get('next', None)
# 
# Path: makesite/modules/flask/base/auth/manager.py
# class UserManager(Blueprint):
# 
#     def __init__(self, *args, **kwargs):
#         self._login_manager = None
#         self._principal = None
#         self.app = None
#         super(UserManager, self).__init__(*args, **kwargs)
# 
#     def register(self, app, *args, **kwargs):
#         " Activate loginmanager and principal. "
# 
#         if not self._login_manager or self.app != app:
#             self._login_manager = LoginManager()
#             self._login_manager.user_callback = self.user_loader
#             self._login_manager.setup_app(app)
#             self._login_manager.login_view = 'urls.index'
#             self._login_manager.login_message = u'You need to be signed in for this page.'
# 
#         self.app = app
# 
#         if not self._principal:
#             self._principal = Principal(app)
#             identity_loaded.connect(self.identity_loaded)
# 
#         super(UserManager, self).register(app, *args, **kwargs)
# 
#     @staticmethod
#     def user_loader(pk):
#         return User.query.options(db.joinedload(User.roles)).get(pk)
# 
#     @staticmethod
#     def login_required(fn):
#         return login_required(fn)
# 
#     def logout(self):
#         identity_changed.send(self.app, identity=AnonymousIdentity())
#         return logout_user()
# 
#     def login(self, user):
#         identity_changed.send(self.app, identity=Identity(user.id))
#         return login_user(user)
# 
#     @staticmethod
#     def identity_loaded(sender, identity):
#         identity.user = current_user
# 
#         # Add the UserNeed to the identity
#         if current_user.is_authenticated():
#             identity.provides.add(UserNeed(current_user.id))
# 
#             # Assuming the User model has a list of roles, update the
#             # identity with the roles that the user provides
#             for role in current_user.roles:
#                 identity.provides.add(RoleNeed(role.name))
# 
# 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)


from flask import request, render_template, flash, redirect, url_for
from flaskext.babel import lazy_gettext as _
from ..ext import db
from .forms import RegisterForm, LoginForm
from .manager import UserManager
from .models import User



users = UserManager(
    'users', __name__, url_prefix='/users', template_folder='templates')


@users.route('/profile/')
@users.login_required
def profile():
    return render_template("users/profile.html")


@users.route('/login/', methods=['POST'])
def login():
    " View function which handles an authentication request. "

# Path: makesite/modules/flask/base/ext.py
# def config_extensions(app):
# def config_babel(app):
#     def get_locale():
# 
# Path: makesite/modules/flask/base/auth/forms.py
# class RegisterForm(Form, EmailFormMixin, PasswordFormMixin, PasswordConfirmFormMixin):
#     "  The default register form. "
# 
#     username = TextField(_('UserName'), [Required(message=_('Required'))])
#     # submit = SubmitField(_("Register"))
# 
#     def to_dict(self):
#         return dict(email=self.email.data, password=self.password.data)
# 
# class LoginForm(Form, EmailFormMixin, PasswordFormMixin):
#     " The default login form. "
# 
#     remember = BooleanField(_("Remember Me"), default=True)
#     next = HiddenField()
#     submit = SubmitField(_("Login"))
# 
#     def __init__(self, *args, **kwargs):
#         super(LoginForm, self).__init__(*args, **kwargs)
# 
#         if request.method == 'GET':
#             self.next.data = request.args.get('next', None)
# 
# Path: makesite/modules/flask/base/auth/manager.py
# class UserManager(Blueprint):
# 
#     def __init__(self, *args, **kwargs):
#         self._login_manager = None
#         self._principal = None
#         self.app = None
#         super(UserManager, self).__init__(*args, **kwargs)
# 
#     def register(self, app, *args, **kwargs):
#         " Activate loginmanager and principal. "
# 
#         if not self._login_manager or self.app != app:
#             self._login_manager = LoginManager()
#             self._login_manager.user_callback = self.user_loader
#             self._login_manager.setup_app(app)
#             self._login_manager.login_view = 'urls.index'
#             self._login_manager.login_message = u'You need to be signed in for this page.'
# 
#         self.app = app
# 
#         if not self._principal:
#             self._principal = Principal(app)
#             identity_loaded.connect(self.identity_loaded)
# 
#         super(UserManager, self).register(app, *args, **kwargs)
# 
#     @staticmethod
#     def user_loader(pk):
#         return User.query.options(db.joinedload(User.roles)).get(pk)
# 
#     @staticmethod
#     def login_required(fn):
#         return login_required(fn)
# 
#     def logout(self):
#         identity_changed.send(self.app, identity=AnonymousIdentity())
#         return logout_user()
# 
#     def login(self, user):
#         identity_changed.send(self.app, identity=Identity(user.id))
#         return login_user(user)
# 
#     @staticmethod
#     def identity_loaded(sender, identity):
#         identity.user = current_user
# 
#         # Add the UserNeed to the identity
#         if current_user.is_authenticated():
#             identity.provides.add(UserNeed(current_user.id))
# 
#             # Assuming the User model has a list of roles, update the
#             # identity with the roles that the user provides
#             for role in current_user.roles:
#                 identity.provides.add(RoleNeed(role.name))
# 
# 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
from flask import request, render_template, flash, redirect, url_for
from flaskext.babel import lazy_gettext as _
from ..ext import db
from .forms import RegisterForm, LoginForm
from .manager import UserManager
from .models import User




users = UserManager(
    'users', __name__, url_prefix='/users', template_folder='templates')


@users.route('/profile/')
@users.login_required
def profile():
    return render_template("users/profile.html")


@users.route('/login/', methods=['POST'])
def login():
    " View function which handles an authentication request. "

    form = LoginForm(request.form)