当代数据库管理系统课程实验二
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

53 satır
1.8 KiB

  1. from flask import Blueprint
  2. from flask import request
  3. from flask import jsonify
  4. from be.model import user
  5. bp_auth = Blueprint("auth",__name__,url_prefix="/auth")
  6. @bp_auth.route("/login", methods=["POST"])
  7. def login():
  8. user_id = request.json.get("user_id", "")
  9. password = request.json.get("password", "")
  10. terminal = request.json.get("terminal", "")
  11. u = user.User()
  12. code, message, token = u.login(user_id=user_id, password=password, terminal=terminal)
  13. return jsonify({"message": message, "token": token}), code
  14. @bp_auth.route("/logout", methods=["POST"])
  15. def logout():
  16. user_id: str = request.json.get("user_id")
  17. token: str = request.headers.get("token")
  18. print(token)
  19. u = user.User()
  20. code, message = u.logout(user_id=user_id, token=token)
  21. return jsonify({"message": message}), code
  22. @bp_auth.route("/register", methods=["POST"])
  23. def register():
  24. user_id = request.json.get("user_id", "")
  25. password = request.json.get("password", "")
  26. u = user.User()
  27. code, message = u.register(user_id=user_id, password=password)
  28. return jsonify({"message": message}), code
  29. @bp_auth.route("/unregister", methods=["POST"])
  30. def unregister():
  31. user_id = request.json.get("user_id", "")
  32. password = request.json.get("password", "")
  33. u = user.User()
  34. code, message = u.unregister(user_id=user_id, password=password)
  35. return jsonify({"message": message}), code
  36. @bp_auth.route("/password", methods=["POST"])
  37. def change_password():
  38. user_id = request.json.get("user_id", "")
  39. old_password = request.json.get("oldPassword", "")
  40. new_password = request.json.get("newPassword", "")
  41. u = user.User()
  42. code, message = u.change_password(user_id=user_id, old_password=old_password, new_password=new_password)
  43. return jsonify({"message": message}), code