Beispiel #1
0
 def update_password(self,id,old_password,new_password):
     try:
         user = User.query.filter_by(id=id).first()
         if(user.password != old_password):
             return ResponseResult.error(ResponseCode.PASSWORD_ERROR)
         user.password = new_password
         db.session.commit()
         return ResponseResult.success()
     except:
         return ResponseResult.error()
Beispiel #2
0
 def add_user(self,user_name, phone, password, email):
     if(self.check_add_param(user_name,phone,email,password)):
         return ResponseResult.error(ResponseCode.PARAM_IS_NULL)
     # 创建时间
     created_time = datetime.datetime.now()
     user = User(user_name, phone, password, email,created_time)
     try:
         db.session.add(user)
         db.session.commit()
         return ResponseResult.success()
     except:
         return ResponseResult.error()
Beispiel #3
0
 def login(self,phone,password):
     try:
         print(phone)
         print(password)
         user = User.query.filter_by(phone=phone,password=password).first()
         print(user)
         if(user):
             return ResponseResult.success(data=user.to_json())
         else:
             return ResponseResult.error(ResponseCode.LOGIN_ERROR)
     except:
         return ResponseResult.error()
Beispiel #4
0
 def delete_user(self,id):
     try:
         User.query.filter_by(id=id).delete()
         db.session.commit()
         return ResponseResult.success()
     except:
         return ResponseResult.error()
Beispiel #5
0
 def getHotWeiboList(self, orderBy, weibo_keywords, topic_keywords, limit,
                     page):
     print(orderBy)
     if (orderBy == 1):
         orderBy = Weibo.comments_count.desc()
     elif (orderBy == 2):
         orderBy = Weibo.attitudes_count.desc()
     elif (orderBy == 3):
         orderBy = Weibo.reposts_count.desc()
     else:
         return ResponseResult.error()
     if (weibo_keywords != None and weibo_keywords != ''):
         if (topic_keywords != None and topic_keywords != ''):
             data = Weibo.query.filter(
                 Weibo.text.contains(weibo_keywords),
                 Weibo.topics.contains(topic_keywords)).order_by(
                     orderBy).all()
         else:
             data = Weibo.query.filter(Weibo.text.contains(
                 weibo_keywords)).order_by(orderBy).all()
     else:
         if (topic_keywords != None and topic_keywords != ''):
             data = Weibo.query.filter(Weibo.topics.contains(
                 topic_keywords)).order_by(orderBy).all()
         else:
             data = Weibo.query.order_by(orderBy).all()
     start = (page - 1) * limit
     end = page * limit if len(data) > page * limit else len(data)
     result = []
     for i in range(start, end):
         result.append(data[i].to_json())
     return ResponseResult.lay_success(data=result, count=len(data))
Beispiel #6
0
 def update_user(self,id,user_name,phone,email):
     try:
         User.query.filter_by(id=id).update({"user_name":user_name,"phone":phone,"email":email})
         db.session.commit()
         user = User.query.filter_by(id=id).first()
         return ResponseResult.success(data=user.to_json())
     except:
         return ResponseResult.error()
Beispiel #7
0
 def get_user(self,id):
     try:
         print(id)
         user = User.query.filter_by(id=id).first()
         print(user.user_name)
         return ResponseResult.success(data=user.to_json())
     except:
         return ResponseResult.error()
Beispiel #8
0
 def register(self,user_name, phone, password, email):
     user = userService.get_user_by_phone(phone)
     if(user):
         return ResponseResult.error(ResponseCode.PHONE_EXIST_ERROR)
     return userService.add_user(user_name, phone, password, email)