# Path: data_news/user/models.py
# class User(db.Model, UserMixin):
#     """ Users!
#         Nothing too crazy here
#         The confirmed_at through login_count columns are updated by Flask-Security
#     """
#     id = db.Column(db.Integer, primary_key=True)
#     email = db.Column(db.String(255))
#     password = db.Column(db.String(255))
#     name = db.Column(db.String(255), unique=True)
#     active = db.Column(db.Boolean())
#     created_at = db.Column(db.DateTime())
#     confirmed_at = db.Column(db.DateTime())
#     last_login_at = db.Column(db.DateTime())
#     current_login_at = db.Column(db.DateTime())
#     last_login_ip = db.Column(db.String(255))
#     current_login_ip = db.Column(db.String(255))
#     login_count = db.Column(db.Integer)
#     twitter_handle = db.Column(db.String(20))
#     karma = db.relationship('Vote', backref="user_to", primaryjoin="Vote.user_to_id==User.id")
#     votes = db.relationship('Vote', backref="user_from", primaryjoin="Vote.user_from_id==User.id")
#     roles = db.relationship('Role', secondary=roles_users,
#                             backref=db.backref('users', lazy='dynamic'))
# 
#     def __repr__(self):
#         return '<Item %r>' % (self.name)
# 
#     def __str__(self):
#         return self.name
# 
#     @property
#     def avatar(self, size):
#         return 'http://www.gravatar.com/avatar/' + md5(self.email).hexdigest() + '?d=mm&s=' + str(size)
# 
#     @property
#     @cache.memoize(60*5)
#     def is_admin(self):
#         for role in self.roles:
#             if role.name == 'admin' or role.name == 'super':
#                 return True
#         return False
# 
#     @property
#     @cache.memoize(60*5)
#     def is_super(self):
#         for role in self.roles:
#             if role.name == 'super':
#                 return True
#         return False
# 
#     @classmethod
#     def find_user_by_name(cls, name):
#         """ Finds user by name, making sure to look in all lowercase
#             Returns Query object not user! Then can use first_or_404.
#         """
#         user_query = cls.query.filter(
#                     func.lower(cls.name) == func.lower(name))
#         return user_query
# 
#     @classmethod
#     def find_user_by_email(cls, email):
#         """ Finds user by EMAIL, making sure to look in all lowercase
#             Returns Query object not user! Then can use first_or_404.
#         """
#         user_query = cls.query.filter(
#                     func.lower(cls.email) == func.lower(email))
#         return user_query
# 
#     @classmethod
#     def find_user_by_twitter(cls, twitter):
#         """ Finds user by EMAIL, making sure to look in all lowercase
#             Returns Query object not user! Then can use first_or_404.
#         """
#         user_query = cls.query.filter(
#                     func.lower(cls.twitter_handle) == func.lower(twitter))
#         return user_query
# 
#     @classmethod
#     def make_unique_name(cls, name):
#         """ Checks if name is being used. If it is, returns a new version.
#         """
#         if name in ILLEGAL_NAMES:
#             name = name + str(1)
#         if not cls.find_user_by_name(name).first():
#             return name
#         version = 2
#         while True:
#             new_name = name + str(version)
#             if not cls.find_user_by_name(new_name).first():
#                 break 
#             version += 1
#         return new_name
# 
# Path: data_news/utils.py
# NAME_LEN_MIN = 2
# 
# NAME_LEN_MAX = 15
# 
# ILLEGAL_NAMES = ['active']


from .models import User
from ..utils import NAME_LEN_MIN, NAME_LEN_MAX, ILLEGAL_NAMES
from flask.ext.wtf import Form
from flask.ext.wtf.html5 import URLField, EmailField
from wtforms import TextField
from wtforms.validators import required, email, optional
from flask.ext.security import current_user
from flask.ext.security.forms import RegisterForm, LoginForm
from flask.ext.security.utils import verify_and_update_password
import re
        validate_name = True
        validate_twitter = True

        if self.twitter.data and '@' in self.twitter.data:
            self.twitter.data = self.twitter.data.replace('@', '')

        name = self.name.data
        email = self.email.data
        twitter = self.twitter.data

        current_name = current_user.name
        current_email = current_user.email
        current_twitter = current_user.twitter_handle


        if email == current_email:
            validate_email = False
        if name == current_name:
            validate_name = False
        if twitter == current_twitter:
            validate_twitter = False

        if not re.match("^[a-zA-Z0-9_-]+$", name):
            self.name.errors.append('Only letters, digits, dashes, underscores allowed')
            return False

        if not re.search("[a-zA-Z0-9]", name):
            self.name.errors.append('Must have at least one letter or number')
            return False


# Path: data_news/user/models.py
# class User(db.Model, UserMixin):
#     """ Users!
#         Nothing too crazy here
#         The confirmed_at through login_count columns are updated by Flask-Security
#     """
#     id = db.Column(db.Integer, primary_key=True)
#     email = db.Column(db.String(255))
#     password = db.Column(db.String(255))
#     name = db.Column(db.String(255), unique=True)
#     active = db.Column(db.Boolean())
#     created_at = db.Column(db.DateTime())
#     confirmed_at = db.Column(db.DateTime())
#     last_login_at = db.Column(db.DateTime())
#     current_login_at = db.Column(db.DateTime())
#     last_login_ip = db.Column(db.String(255))
#     current_login_ip = db.Column(db.String(255))
#     login_count = db.Column(db.Integer)
#     twitter_handle = db.Column(db.String(20))
#     karma = db.relationship('Vote', backref="user_to", primaryjoin="Vote.user_to_id==User.id")
#     votes = db.relationship('Vote', backref="user_from", primaryjoin="Vote.user_from_id==User.id")
#     roles = db.relationship('Role', secondary=roles_users,
#                             backref=db.backref('users', lazy='dynamic'))
# 
#     def __repr__(self):
#         return '<Item %r>' % (self.name)
# 
#     def __str__(self):
#         return self.name
# 
#     @property
#     def avatar(self, size):
#         return 'http://www.gravatar.com/avatar/' + md5(self.email).hexdigest() + '?d=mm&s=' + str(size)
# 
#     @property
#     @cache.memoize(60*5)
#     def is_admin(self):
#         for role in self.roles:
#             if role.name == 'admin' or role.name == 'super':
#                 return True
#         return False
# 
#     @property
#     @cache.memoize(60*5)
#     def is_super(self):
#         for role in self.roles:
#             if role.name == 'super':
#                 return True
#         return False
# 
#     @classmethod
#     def find_user_by_name(cls, name):
#         """ Finds user by name, making sure to look in all lowercase
#             Returns Query object not user! Then can use first_or_404.
#         """
#         user_query = cls.query.filter(
#                     func.lower(cls.name) == func.lower(name))
#         return user_query
# 
#     @classmethod
#     def find_user_by_email(cls, email):
#         """ Finds user by EMAIL, making sure to look in all lowercase
#             Returns Query object not user! Then can use first_or_404.
#         """
#         user_query = cls.query.filter(
#                     func.lower(cls.email) == func.lower(email))
#         return user_query
# 
#     @classmethod
#     def find_user_by_twitter(cls, twitter):
#         """ Finds user by EMAIL, making sure to look in all lowercase
#             Returns Query object not user! Then can use first_or_404.
#         """
#         user_query = cls.query.filter(
#                     func.lower(cls.twitter_handle) == func.lower(twitter))
#         return user_query
# 
#     @classmethod
#     def make_unique_name(cls, name):
#         """ Checks if name is being used. If it is, returns a new version.
#         """
#         if name in ILLEGAL_NAMES:
#             name = name + str(1)
#         if not cls.find_user_by_name(name).first():
#             return name
#         version = 2
#         while True:
#             new_name = name + str(version)
#             if not cls.find_user_by_name(new_name).first():
#                 break 
#             version += 1
#         return new_name
# 
# Path: data_news/utils.py
# NAME_LEN_MIN = 2
# 
# NAME_LEN_MAX = 15
# 
# ILLEGAL_NAMES = ['active']


# Path: data_news/user/forms.py
from .models import User
from ..utils import NAME_LEN_MIN, NAME_LEN_MAX, ILLEGAL_NAMES
from flask.ext.wtf import Form
from flask.ext.wtf.html5 import URLField, EmailField
from wtforms import TextField
from wtforms.validators import required, email, optional
from flask.ext.security import current_user
from flask.ext.security.forms import RegisterForm, LoginForm
from flask.ext.security.utils import verify_and_update_password
import re

        validate_name = True
        validate_twitter = True

        if self.twitter.data and '@' in self.twitter.data:
            self.twitter.data = self.twitter.data.replace('@', '')

        name = self.name.data
        email = self.email.data
        twitter = self.twitter.data

        current_name = current_user.name
        current_email = current_user.email
        current_twitter = current_user.twitter_handle


        if email == current_email:
            validate_email = False
        if name == current_name:
            validate_name = False
        if twitter == current_twitter:
            validate_twitter = False

        if not re.match("^[a-zA-Z0-9_-]+$", name):
            self.name.errors.append('Only letters, digits, dashes, underscores allowed')
            return False

        if not re.search("[a-zA-Z0-9]", name):
            self.name.errors.append('Must have at least one letter or number')
            return False


        if not NAME_LEN_MIN < len(name) + 1 < NAME_LEN_MAX: