Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1.  
  2. #FIELDS REQUIRED: email, plan_id
  3. @app.route('/set_user_plan', methods=['POST'])
  4. def set_user_plan(email, plan_id):
  5. try:
  6. email = request.form['email']
  7. plan_id = request.form['plan_id']
  8. conn = MySQLdb.connect(host='localhost', user='muscle', password='some_pass')
  9. c = conn.cursor()
  10. c.execute("UPDATE USER SET Plan_id = {} WHERE Email = '{}'").format(plan_id, email)
  11. conn.commit()
  12. c.close()
  13. conn.close()
  14.  
  15. return "Plan " + str(plan_id) + " atribuited to " + str(email)
  16. except Exception as e:
  17. return str(e)
  18.  
  19. #FIELDS REQUIRED: email
  20. @app.route('/user_exists', methods=['POST'])
  21. def user_exists(email):
  22. try:
  23. email = request.form['email']
  24. conn = MySQLdb.connect(host='localhost', user='muscle', password='some_pass')
  25. c = conn.cursor(MySQLdb.cursors.DictCursor)
  26. c.execute('USE muscle')
  27.  
  28. c.execute("SELECT * FROM USER WHERE Email = '{}'".format(email))
  29.  
  30. fetched = c.fetchall()
  31.  
  32. c.close()
  33. conn.close()
  34. if fetched:
  35. return "True"
  36.  
  37. return "False"
  38. except Exception as e:
  39. return str(e)
  40.  
  41. #FIELDS REQUIRED: email, password
  42. @app.route('/user_login', methods=['POST'])
  43. def user_login(email, password):
  44. try:
  45. email = request.form['email']
  46. password = request.form['password']
  47. conn = MySQLdb.connect(host='localhost', user='muscle', password='some_pass')
  48. c = conn.cursor(MySQLdb.cursors.DictCursor)
  49. c.execute('USE muscle')
  50.  
  51.  
  52. c.execute("SELECT Password FROM USER WHERE Email = '{}'".format(email))
  53. fetched = c.fetchall();
  54. c.close()
  55. conn.close()
  56. if not fetched:
  57. return "User does not exist"
  58.  
  59. return str(pbkdf2_sha256.verify(password, fetched[0]['Password']))
  60.  
  61. except Exception as e:
  62. return str(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement