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)
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
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)