# Path: fbone/user/models.py
# class User(db.Model, UserMixin):
# 
#     __tablename__ = 'users'
# 
#     id = Column(db.Integer, primary_key=True)
#     name = Column(db.String(STRING_LEN), nullable=False, unique=True)
#     email = Column(db.String(STRING_LEN), nullable=False, unique=True)
#     openid = Column(db.String(STRING_LEN), unique=True)
#     activation_key = Column(db.String(STRING_LEN))
#     created_time = Column(db.DateTime, default=get_current_time)
# 
#     _password = Column('password', db.String(STRING_LEN), nullable=False)
# 
#     def _get_password(self):
#         return self._password
# 
#     def _set_password(self, password):
#         self._password = generate_password_hash(password)
#     # Hide password encryption by exposing password field only.
#     password = db.synonym('_password',
#                           descriptor=property(_get_password,
#                                               _set_password))
# 
#     def check_password(self, password):
#         if self.password is None:
#             return False
#         return check_password_hash(self.password, password)
# 
#     # ================================================================
#     role_code = Column(db.SmallInteger, default=USER, nullable=False)
# 
#     @property
#     def role(self):
#         return USER_ROLE[self.role_code]
# 
#     def is_admin(self):
#         return self.role_code == ADMIN
# 
#     # ================================================================
#     # One-to-many relationship between users and user_statuses.
#     status_code = Column(db.SmallInteger, default=INACTIVE)
# 
#     @property
#     def status(self):
#         return USER_STATUS[self.status_code]
# 
#     # ================================================================
#     # Class methods
# 
#     @classmethod
#     def authenticate(cls, login, password):
#         user = cls.query.filter(db.or_(User.name == login,
#                                        User.email == login)).first()
# 
#         if user:
#             authenticated = user.check_password(password)
#         else:
#             authenticated = False
# 
#         return user, authenticated
# 
#     @classmethod
#     def search(cls, keywords):
#         criteria = []
#         for keyword in keywords.split():
#             keyword = '%' + keyword + '%'
#             criteria.append(db.or_(
#                 User.name.ilike(keyword),
#                 User.email.ilike(keyword),
#             ))
#         q = reduce(db.and_, criteria)
#         return cls.query.filter(q)
# 
#     @classmethod
#     def get_by_id(cls, user_id):
#         return cls.query.filter_by(id=user_id).first_or_404()
# 
#     def check_name(self, name):
#         return User.query.filter(db.and_(User.name == name,
#                                          User.email != self.id)).count() == 0
# 
# Path: fbone/utils.py
# PASSWORD_LEN_MIN = 6
# 
# PASSWORD_LEN_MAX = 16
# 
# USERNAME_LEN_MIN = 4
# 
# USERNAME_LEN_MAX = 25


from flask import Markup
from flask.ext.wtf import Form
from wtforms import (ValidationError, HiddenField, BooleanField, TextField,
                     PasswordField, SubmitField)
from wtforms.validators import Required, Length, EqualTo, Email
from flask.ext.wtf.html5 import EmailField
from ..user import User
from ..utils import (PASSWORD_LEN_MIN, PASSWORD_LEN_MAX, USERNAME_LEN_MIN,
                     USERNAME_LEN_MAX)
# -*- coding: utf-8 -*-





class LoginForm(Form):
    next = HiddenField()
    login = TextField(u'Username or email', [Required()])
    password = PasswordField('Password',
                             [Required(),
                              Length(PASSWORD_LEN_MIN, PASSWORD_LEN_MAX)])
    remember = BooleanField('Remember me')
    submit = SubmitField('Sign in')


class SignupForm(Form):
    next = HiddenField()
    email = EmailField(u'Email',
                       [Required(), Email()],
                       description=u"What's your email address?")
    password = PasswordField(u'Password',
                             [Required(),
                              Length(PASSWORD_LEN_MIN, PASSWORD_LEN_MAX)],
                             description=u'%s characters or more! Be tricky.' %
                             PASSWORD_LEN_MIN)
    name = TextField(u'Choose your username',
                     [Required(),

# Path: fbone/user/models.py
# class User(db.Model, UserMixin):
# 
#     __tablename__ = 'users'
# 
#     id = Column(db.Integer, primary_key=True)
#     name = Column(db.String(STRING_LEN), nullable=False, unique=True)
#     email = Column(db.String(STRING_LEN), nullable=False, unique=True)
#     openid = Column(db.String(STRING_LEN), unique=True)
#     activation_key = Column(db.String(STRING_LEN))
#     created_time = Column(db.DateTime, default=get_current_time)
# 
#     _password = Column('password', db.String(STRING_LEN), nullable=False)
# 
#     def _get_password(self):
#         return self._password
# 
#     def _set_password(self, password):
#         self._password = generate_password_hash(password)
#     # Hide password encryption by exposing password field only.
#     password = db.synonym('_password',
#                           descriptor=property(_get_password,
#                                               _set_password))
# 
#     def check_password(self, password):
#         if self.password is None:
#             return False
#         return check_password_hash(self.password, password)
# 
#     # ================================================================
#     role_code = Column(db.SmallInteger, default=USER, nullable=False)
# 
#     @property
#     def role(self):
#         return USER_ROLE[self.role_code]
# 
#     def is_admin(self):
#         return self.role_code == ADMIN
# 
#     # ================================================================
#     # One-to-many relationship between users and user_statuses.
#     status_code = Column(db.SmallInteger, default=INACTIVE)
# 
#     @property
#     def status(self):
#         return USER_STATUS[self.status_code]
# 
#     # ================================================================
#     # Class methods
# 
#     @classmethod
#     def authenticate(cls, login, password):
#         user = cls.query.filter(db.or_(User.name == login,
#                                        User.email == login)).first()
# 
#         if user:
#             authenticated = user.check_password(password)
#         else:
#             authenticated = False
# 
#         return user, authenticated
# 
#     @classmethod
#     def search(cls, keywords):
#         criteria = []
#         for keyword in keywords.split():
#             keyword = '%' + keyword + '%'
#             criteria.append(db.or_(
#                 User.name.ilike(keyword),
#                 User.email.ilike(keyword),
#             ))
#         q = reduce(db.and_, criteria)
#         return cls.query.filter(q)
# 
#     @classmethod
#     def get_by_id(cls, user_id):
#         return cls.query.filter_by(id=user_id).first_or_404()
# 
#     def check_name(self, name):
#         return User.query.filter(db.and_(User.name == name,
#                                          User.email != self.id)).count() == 0
# 
# Path: fbone/utils.py
# PASSWORD_LEN_MIN = 6
# 
# PASSWORD_LEN_MAX = 16
# 
# USERNAME_LEN_MIN = 4
# 
# USERNAME_LEN_MAX = 25


# Path: fbone/frontend/forms.py
from flask import Markup
from flask.ext.wtf import Form
from wtforms import (ValidationError, HiddenField, BooleanField, TextField,
                     PasswordField, SubmitField)
from wtforms.validators import Required, Length, EqualTo, Email
from flask.ext.wtf.html5 import EmailField
from ..user import User
from ..utils import (PASSWORD_LEN_MIN, PASSWORD_LEN_MAX, USERNAME_LEN_MIN,
                     USERNAME_LEN_MAX)

# -*- coding: utf-8 -*-





class LoginForm(Form):
    next = HiddenField()
    login = TextField(u'Username or email', [Required()])
    password = PasswordField('Password',
                             [Required(),
                              Length(PASSWORD_LEN_MIN, PASSWORD_LEN_MAX)])
    remember = BooleanField('Remember me')
    submit = SubmitField('Sign in')


class SignupForm(Form):
    next = HiddenField()
    email = EmailField(u'Email',
                       [Required(), Email()],
                       description=u"What's your email address?")
    password = PasswordField(u'Password',
                             [Required(),
                              Length(PASSWORD_LEN_MIN, PASSWORD_LEN_MAX)],
                             description=u'%s characters or more! Be tricky.' %
                             PASSWORD_LEN_MIN)
    name = TextField(u'Choose your username',
                     [Required(),

                      Length(USERNAME_LEN_MIN, USERNAME_LEN_MAX)],