def star_article(): try: data=request.get_json() user_id=data.get('user_id') article_id=data.get('article_id') Article=Meeting_article.query.filter_by(id=article_id).first() Count=User_article.query.filter_by(user_id=user_id,title=Article.title).count() print(Count) if(Count!=0): return responseError(Responses.EXIST_STAR) userArticle=User_article(create_time=Article.create_time,meeting_name=Article.meeting_name,title=Article.title, author=Article.author,abstract=Article.abstract,address=Article.address, keyword=Article.keyword,user_id=user_id) db.session.add(userArticle) db.session.commit() temp=User_article.query.filter_by(author=Article.author,abstract=Article.abstract, address=Article.address,user_id=user_id).first() newNote=Note(user_id=user_id,article_id=temp.id) db.session.add(newNote) db.session.commit() return responseSuccess(Responses.OPERATION_SUCCESS) except Exception as e: print(e) return responseError(Responses.PARAMETERS_ERROR)
def register(): try: data = request.get_json() user_name = data.get("user_name") user_account = data.get("user_account") user_password = data.get("user_password") user_repassword = data.get("user_repassword") #验证两次密码是否相同 if user_password != user_repassword: return responseError(Responses.NOT_SAME_PASSWORD) #验证用户名是否已存在 if User.query.filter_by(username=user_name).count() != 0: return responseError(Responses.EXIST_NAME) #验证用户账号是否已存在 if User.query.filter_by(account=user_account).count() != 0: return responseError(Responses.EXIST_ACCOUNT) user=User(account=user_account,username=user_name,password=user_password) db.session.add(user) db.session.commit() return responseSuccess(Responses.OPERATION_SUCCESS) except Exception as e: print(e) db.session.rollback() return responseError(Responses.PARAMETERS_ERROR)
def update_infos(): try: data = request.get_json() user_id = int(data.get("user_id")) # 列表分别为user_name,user_password,user_mobile,user_email,user_school,user_info,user_gender user_list = (data.get("user_list")) user = User.query.filter_by(id=user_id).first() user.username = user_list[0] user.password=user_list[1] user.mobile = user_list[2] user.email = user_list[3] user.college = user_list[4] user.info = user_list[5] if(user_list[6]=="男"): user.gender = True else: user.gender=False db.session.commit() return responseSuccess(Responses.OPERATION_SUCCESS) except Exception as e: print(e) db.session.rollback() return responseError(Responses.PARAMETERS_ERROR)
def logout(): try: # 清空session session["token"] = None session["user_id"] = None data = request.get_json() user_id = int(data.get("user_id")) return responseSuccess(Responses.OPERATION_SUCCESS) except Exception as e: print(e) return responseError(Responses.PARAMETERS_ERROR)
def del_article(): try: data=request.get_json() article_id=data.get("article_id") article=Meeting_article.query.filter_by(id=article_id).first() if not article: return responseError(Responses.NO_RECORD_FOUND) db.session.delete(article) db.session.commit() return responseSuccess(Responses.OPERATION_SUCCESS) except Exception as e: print(e) db.session.rollback() return responseError(Responses.PARAMETERS_ERROR)
def update_note(): try: data = request.get_json() user_id = data.get("user_id") article_id = data.get("article_id") note_info=data.get("note_info") note = Note.query.filter_by(user_id=user_id, article_id=article_id).first() if not note: return responseError(Responses.NO_RECORD_FOUND) note.note=note_info db.session.commit() return responseSuccess(Responses.OPERATION_SUCCESS) except Exception as e: print(e) db.session.rollback() return responseError(Responses.PARAMETERS_ERROR)