Пример #1
0
class User(db.Document):
    id = db.SequenceField(primary_key=True)
    email = db.EmailField(required=True, unique=True)
    password = db.StringField(required=False)
    username = db.StringField(required=True, unique=True)
    profile_pic = db.StringField(required=False)
    is_blocked = db.BooleanField(required=False, default=False)
    provider = db.StringField(required=True)

    def serialize(self):  #to select what fields to return in get
        profile_info = {}
        if self.profile_pic:
            profile_info['picture'] = self.profile_pic

        return {
            'id': self.id,
            'email': self.email,
            'username': self.username,
            'profile': profile_info
        }

    def serialize_admin(self):
        fields = self.serialize()
        fields['is_blocked'] = self.is_blocked
        return fields
class User(db.Document):
    email = db.EmailField(required=True, unique=True)
    password = db.StringField(required=True, min_length=6)

    def hash_password(self):
        self.password = generate_password_hash(self.password).decode('utf8')

    def check_password(self, password):
        return check_password_hash(self.password, password)
Пример #3
0
class User(db.Document):
    email = db.EmailField(required=True, unique=True)
    password = db.StringField(required=True, min_length=6)
    movies = db.ListField(db.ReferenceField('Movie', reverse_delete_rule=db.PULL))

    def hash_password(self):
        self.password = generate_password_hash(self.password).decode('utf8')
    
    def check_password(self, password):
        return check_password_hash(self.password, password)
Пример #4
0
class User(db.Document):
    first_name = db.StringField(required=True)
    last_name = db.StringField(required=True)
    password = db.StringField(required=True)
    email = db.EmailField(required=True, unique=True)

    def save(self, *args, **kwargs):
        self.password = self.create_hashed_password(self.password)
        return super().save(*args, **kwargs)

    @staticmethod
    def create_hashed_password(password):
        return generate_password_hash(password).decode('utf8')

    def check_password(self, password):
        return check_password_hash(self.password, password)
Пример #5
0
class User(BaseModel):
    name = db.StringField(required=True, unique=True)
    email = db.EmailField(requred=True, unique=True)
    password = db.StringField(required=True, min_length=6)

    task_lists = db.ListField(
        db.ReferenceField('TaskList', revese_delete_rule=db.CASCADE),
        required=False
    )


    def hash_password(self):
        self.password = generate_password_hash(self.password).decode('utf8')
    

    def check_password(self, password):
        return check_password_hash(self.password, password)