def authenticate(self, login, password): user = self.filter(db.or_(User.username==login, User.email==login)).first() if user: authenticated = user.check_password(password) else: authenticated = False return user, authenticated
def search(self, keywords): criteria = [] for keyword in keywords.split(): keyword = '%' + keyword + '%' criteria.append(db.or_(Post.title.ilike(keyword), Post.content.ilike(keyword), Post.tags.ilike(keyword) )) q = reduce(db.and_, criteria) return self.filter(q)
def search(self, key): query = self.filter(db.or_(User.email==key, User.nickname.ilike('%'+key+'%'), User.username.ilike('%'+key+'%'))) return query