# Path: app/models/user.py
# class User(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     type = db.Column(db.String(32), nullable=False, default='User')
#     username = db.Column(db.String(80), unique=True)
#     email = db.Column(db.String(120), unique=True)
#     name = db.Column(db.String(80))
#     bio = db.Column(db.String(180))
#     points = db.Column(db.Integer, default=0)
#     site_admin = db.Column(db.Boolean, default=False)
#     avatar_url = db.Column(db.String(256))
#     owner = db.Column(db.String(32), nullable=False, default='user')
#     github_id = db.Column(db.Integer, unique=True)
#     github_username = db.Column(db.String(64), unique=True)
#     github_token = db.Column(db.String(300), unique=True)
#     password = db.Column(db.String(300))
#     location = db.Column(db.String(255))
#     followers_count = db.Column(db.Integer, default=0)
#     public_repos_count = db.Column(db.Integer, default=0)
#     created_at = db.Column(db.DateTime, default=datetime.utcnow)
#     last_active_at = db.Column(db.DateTime, default=datetime.utcnow)
#     last_login_reward_at = db.Column(db.DateTime, default=datetime.utcnow)
#     following_topics = db.relationship('Topic', secondary=topics,
#         backref=db.backref('user', lazy='dynamic'))
# 
#     def __init__(self, username, email, password, name=None):
#         self.email = email
#         self.username = username
#         self.password = password
#         if name is None:
#             self.name = username
#         else:
#             self.name = name
# 
#     is_authenticated = True
#     is_anonymous =  False
#     is_active = True
# 
#     def get_id(self):
#         return unicode(self.id)
# 
#     def __repr__(self):
#         return '<User %r>' % self.username


from functools import wraps
from flask import request
from flask_restful import abort
from app.models.user import User
from werkzeug.security import check_password_hash

def auth_required(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth:
            return abort(401)
        login = auth.username
        if login[1:-1].find('@') >= 0:
            user = User.query.filter_by(email=login).first()
            login_type = 'email'
        else:

# Path: app/models/user.py
# class User(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     type = db.Column(db.String(32), nullable=False, default='User')
#     username = db.Column(db.String(80), unique=True)
#     email = db.Column(db.String(120), unique=True)
#     name = db.Column(db.String(80))
#     bio = db.Column(db.String(180))
#     points = db.Column(db.Integer, default=0)
#     site_admin = db.Column(db.Boolean, default=False)
#     avatar_url = db.Column(db.String(256))
#     owner = db.Column(db.String(32), nullable=False, default='user')
#     github_id = db.Column(db.Integer, unique=True)
#     github_username = db.Column(db.String(64), unique=True)
#     github_token = db.Column(db.String(300), unique=True)
#     password = db.Column(db.String(300))
#     location = db.Column(db.String(255))
#     followers_count = db.Column(db.Integer, default=0)
#     public_repos_count = db.Column(db.Integer, default=0)
#     created_at = db.Column(db.DateTime, default=datetime.utcnow)
#     last_active_at = db.Column(db.DateTime, default=datetime.utcnow)
#     last_login_reward_at = db.Column(db.DateTime, default=datetime.utcnow)
#     following_topics = db.relationship('Topic', secondary=topics,
#         backref=db.backref('user', lazy='dynamic'))
# 
#     def __init__(self, username, email, password, name=None):
#         self.email = email
#         self.username = username
#         self.password = password
#         if name is None:
#             self.name = username
#         else:
#             self.name = name
# 
#     is_authenticated = True
#     is_anonymous =  False
#     is_active = True
# 
#     def get_id(self):
#         return unicode(self.id)
# 
#     def __repr__(self):
#         return '<User %r>' % self.username


# Path: app/api/auth.py
from functools import wraps
from flask import request
from flask_restful import abort
from app.models.user import User
from werkzeug.security import check_password_hash


def auth_required(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth:
            return abort(401)
        login = auth.username
        if login[1:-1].find('@') >= 0:
            user = User.query.filter_by(email=login).first()
            login_type = 'email'
        else:

            user = User.query.filter_by(username=login).first()