Guest User

Untitled

a guest
Feb 3rd, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. {% block tab_content %}
  2. <canvas width="800" height="600" id="canvas"></canvas>
  3. <script>
  4. window.onload = init;
  5. function init(){
  6. console.log('работает');
  7. var canvas = document.getElementById('canvas');
  8. if (canvas) {
  9. if (canvas.getContext) {
  10. var ctx = canvas.getContext('2d');
  11.  
  12. ctx.fillRect(25, 25, 100, 100);
  13. }
  14. }
  15. }
  16. </script>
  17. {% endblock %}
  18.  
  19. {% block tab_content %}
  20. <canvas width="800" height="600" id="canvas"></canvas>
  21. <script>
  22. window.onload = init;
  23. function init(){
  24. console.log('работает');
  25. var canvas = document.getElementById('canvas');
  26. if (canvas) {
  27. if (canvas.getContext) {
  28. var ctx = canvas.getContext('2d');
  29.  
  30. ctx.fillRect(25, 25, 100, 100);
  31. }
  32. }
  33. }
  34. </script>
  35. {% endblock %}
  36.  
  37. @app.route('/validate_user', methods=['POST'])
  38. def validate_user():
  39. login = request.form['login']
  40. password = request.form['password']
  41.  
  42. try:
  43. c, conn = cursor_connection()
  44. c = conn.cursor()
  45. c.execute("SELECT hsh "
  46. "FROM auth_info "
  47. "WHERE login='{}' ; "
  48. "".format(login, password))
  49.  
  50. res = c.fetchall()[0][0]
  51. c.close()
  52. conn.close()
  53.  
  54. except Exception as e:
  55. logger.info(msg='Failed to execute /validate_user {}'.format(e))
  56. return render_template('500.html')
  57.  
  58. if check_password_hash(password=password, pwhash=res):
  59. return jsonify({'result': True})
  60. return jsonify({'result': False})
  61.  
  62. @app.route('/user_login', methods=['POST'])
  63. def user_login():
  64. login = request.form['login']
  65. if login is None or not login:
  66. return jsonify(data='Incorrect URL')
  67.  
  68. try:
  69. c, conn = cursor_connection()
  70. c = conn.cursor()
  71. c.execute("SELECT accounts_info_uid "
  72. "FROM auth_info WHERE login='{}' ".format(login))
  73.  
  74. id = c.fetchall()
  75. if not id:
  76. return jsonify(data='Incorrect login')
  77.  
  78. c.execute("SELECT * FROM boxes_id AS tb1 LEFT JOIN"
  79. " accounts_info AS tb2 ON tb2.boxes_ids=tb1.uid "
  80. # "LEFT JOIN electricity_info as tb3 ON tb3.boxes_id_uid=tb1.uid"
  81. " WHERE tb2.uid={} ".format(id[0][0]))
  82.  
  83. uid, mc_address, working_status, activation_status, _,
  84. first_name, second_name, registration_date, phone, email, boxes_id = c.fetchall()[0]
  85. c.execute(" SELECT consumed_electricity "
  86. "FROM electricity_info "
  87. "WHERE boxes_id_uid={} ".format(boxes_id))
  88. consumed_electricity = [float(val[0]) for val in c.fetchall()]
  89. c.close()
  90. conn.close()
  91.  
  92. except Exception as e:
  93. logger.error(msg='Cannot execute /user_login {}'.format(e))
  94. return str(e)
  95.  
  96. user = User()
  97. user.id = login
  98. login_user(user)
  99. return redirect(url_for('welcome'))
Add Comment
Please, Sign In to add comment