邓淳远、崔鹏宇、翁思扬组云计算期末项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. from flask import request, Flask, jsonify, Blueprint
  2. import json
  3. from APP.view.database import db_session
  4. from APP.view.model import Users
  5. bp_auth = Blueprint("bp_auth", __name__,url_prefix="/bp_auth")
  6. @bp_auth.route('/login', methods=['POST', 'GET'])
  7. def login():
  8. if request.method == 'POST':
  9. phonenum = request.form['phonenum']
  10. password = request.form['password']
  11. name = ''
  12. msg = ''
  13. userlist = db_session.query(Users)
  14. flag = 0
  15. for user in userlist:
  16. if user.phonenum == phonenum:
  17. if user.password == password:
  18. flag = 1
  19. name = user.name
  20. else:
  21. flag = 2
  22. break
  23. if flag == 1:
  24. return jsonify({'code': 1, 'name': name, 'phonenum': phonenum})
  25. else:
  26. if phonenum != '' and password != '':
  27. if flag == 0:
  28. msg = "手机号还未注册!"
  29. return jsonify({'code': 0, 'msg': msg})
  30. else:
  31. msg = "密码错误!"
  32. return jsonify({'code': 2, 'msg': msg})
  33. else:
  34. msg = "请输入完整登录信息!"
  35. return jsonify({'code': 3, 'msg': msg})
  36. else:
  37. msg = "提交失败,请重新登录!"
  38. return jsonify({'code': 4, 'msg': msg})
  39. @bp_auth.route('/register', methods=['POST', 'GET'])
  40. def register():
  41. if request.method == 'POST':
  42. phonenum = request.form['phonenum']
  43. username = request.form['username']
  44. password = request.form['password']
  45. password1 = request.form['password1']
  46. msg = ''
  47. userlist = db_session.query(Users)
  48. flag = 1
  49. for user in userlist:
  50. if user.phonenum == phonenum:
  51. flag = 0
  52. break
  53. if flag == 0:
  54. msg = "手机号已被注册!"
  55. return jsonify({'code': 0, 'msg': msg})
  56. else:
  57. if phonenum != '' and password != '':
  58. if password == password1:
  59. user = Users(phonenum=phonenum, name=username, password=password)
  60. db_session.add(user)
  61. db_session.commit()
  62. return jsonify({'code': 1, 'name': username, 'phonenum': phonenum})
  63. else:
  64. msg = "两次输入密码不一致!"
  65. return jsonify({'code': 2, 'msg': msg})
  66. else:
  67. msg = "请输入完整登录信息!"
  68. return jsonify({'code': 3, 'msg': msg})
  69. else:
  70. msg = "提交失败,请重新注册!"
  71. return jsonify({'code': 4, 'msg': msg})
  72. @bp_auth.route('/forget', methods=['POST', 'GET'])
  73. def forget():
  74. if request.method == 'POST':
  75. phonenum = request.form['phonenum']
  76. username = request.form['username']
  77. password = request.form['password']
  78. password1 = request.form['password1']
  79. msg = ''
  80. userlist = db_session.query(Users)
  81. flag = 0
  82. for user in userlist:
  83. if user.phonenum == phonenum:
  84. if user.name == username:
  85. user.password = password
  86. db_session.commit()
  87. flag = 1
  88. else:
  89. flag = 2
  90. break
  91. if flag == 0:
  92. msg = "手机号还未注册!"
  93. return jsonify({'code': 0, 'msg': msg})
  94. else:
  95. if phonenum != '' and password != '':
  96. if password == password1:
  97. if flag == 1:
  98. msg = "修改密码成功!"
  99. return jsonify({'code': 1, 'name': username, 'phonenum': phonenum})
  100. else:
  101. msg = "用户名输入错误!"
  102. return jsonify({'code': 2, 'msg': msg})
  103. else:
  104. msg = "两次输入密码不一致!"
  105. return jsonify({'code': 3, 'msg': msg})
  106. else:
  107. msg = "请输入完整修改密码信息!"
  108. return jsonify({'code': 4, 'msg': msg})
  109. else:
  110. msg = "提交失败,请重新修改密码!"
  111. return jsonify({'code': 5, 'msg': msg})