# -*- coding: utf-8 -*-
from bson.objectid import ObjectId
from flask import current_app
from power.extensions import db


class User(db.Document):
    email = db.StringField(required=True, primary_key=True)
    first_name = db.StringField(max_length=50)
    last_name = db.StringField(max_length=50)
    created_time = db.DateTimeField()
    avatar = db.StringField()
    password = db.StringField()

    def check_password(self, password):
        if self.password is None:
            return False
        return self.password == password

    def get_id(self):
        return str(self.id)

    def is_active(self):
        # TODO: User is active or just ignore?
        return True

    def is_authenticated(self):
        return True

    @classmethod
    def get_by_id(cls, user_id):
        current_app.logger.debug("User.get_by_id({0})".format(user_id))
        return cls.objects.first()

    @classmethod
    def authenticate(cls, login, password):
        user = User.objects(email=login).first()
        if user:
            authenticated = user.check_password(password)
        else:
            authenticated = False
        return user, authenticated


eefbbf68b31c45a9007880a9df33c27b4b5adab7
<mask token>


class User(db.Document):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def check_password(self, password):
        if self.password is None:
            return False
        return self.password == password
    <mask token>

    def is_active(self):
        return True
    <mask token>
    <mask token>
    <mask token>

<mask token>


class User(db.Document):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def check_password(self, password):
        if self.password is None:
            return False
        return self.password == password

    def get_id(self):
        return str(self.id)

    def is_active(self):
        return True
    <mask token>
    <mask token>

    @classmethod
    def authenticate(cls, login, password):
        user = User.objects(email=login).first()
        if user:
            authenticated = user.check_password(password)
        else:
            authenticated = False
        return user, authenticated

<mask token>


class User(db.Document):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def check_password(self, password):
        if self.password is None:
            return False
        return self.password == password

    def get_id(self):
        return str(self.id)

    def is_active(self):
        return True
    <mask token>

    @classmethod
    def get_by_id(cls, user_id):
        current_app.logger.debug('User.get_by_id({0})'.format(user_id))
        return cls.objects.first()

    @classmethod
    def authenticate(cls, login, password):
        user = User.objects(email=login).first()
        if user:
            authenticated = user.check_password(password)
        else:
            authenticated = False
        return user, authenticated

from bson.objectid import ObjectId
from flask import current_app
from power.extensions import db


class User(db.Document):
    email = db.StringField(required=True, primary_key=True)
    first_name = db.StringField(max_length=50)
    last_name = db.StringField(max_length=50)
    created_time = db.DateTimeField()
    avatar = db.StringField()
    password = db.StringField()

    def check_password(self, password):
        if self.password is None:
            return False
        return self.password == password

    def get_id(self):
        return str(self.id)

    def is_active(self):
        return True

    def is_authenticated(self):
        return True

    @classmethod
    def get_by_id(cls, user_id):
        current_app.logger.debug('User.get_by_id({0})'.format(user_id))
        return cls.objects.first()

    @classmethod
    def authenticate(cls, login, password):
        user = User.objects(email=login).first()
        if user:
            authenticated = user.check_password(password)
        else:
            authenticated = False
        return user, authenticated

# -*- coding: utf-8 -*-
from bson.objectid import ObjectId
from flask import current_app
from power.extensions import db


class User(db.Document):
    email = db.StringField(required=True, primary_key=True)
    first_name = db.StringField(max_length=50)
    last_name = db.StringField(max_length=50)
    created_time = db.DateTimeField()
    avatar = db.StringField()
    password = db.StringField()

    def check_password(self, password):
        if self.password is None:
            return False
        return self.password == password

    def get_id(self):
        return str(self.id)

    def is_active(self):
        # TODO: User is active or just ignore?
        return True

    def is_authenticated(self):
        return True

    @classmethod
    def get_by_id(cls, user_id):
        current_app.logger.debug("User.get_by_id({0})".format(user_id))
        return cls.objects.first()

    @classmethod
    def authenticate(cls, login, password):
        user = User.objects(email=login).first()
        if user:
            authenticated = user.check_password(password)
        else:
            authenticated = False
        return user, authenticated

