Guest User

Untitled

a guest
Jun 16th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. # sqlwitch tries to give you just the right amount of abstraction for fast MySQL-based web applications.
  2. # Avoid complex and memory hungry ORM libraries while keeping your code easy to maintain:
  3.  
  4. def get_db_handler(db_auth):
  5. conn = MySQLdb.connect(**db_auth)
  6. cursor = conn.cursor(MySQLdb.cursors.DictCursor)
  7. conn.set_character_set('utf8')
  8. cursor.execute('set names utf8;')
  9. cursor.execute('set character_set_connection = utf8;')
  10. return sqlwitch(cursor, conn)
  11.  
  12. @app.route('/-/users', methods=['POST'])
  13. def new_user():
  14. db = get_db_handler(config.db)
  15. with db.select('user_id', from_='users'):
  16. db.where('email = %s', request.form['email'])
  17. existing_user = db.fetchone()
  18. if existing_user:
  19. return jsonify(status=1, message='user_exists')
  20. user_id = new_user_id(db)
  21. with db.insert(into='users') as obj:
  22. obj.user_id = user_id
  23. obj.email = request.form['email']
  24. obj.password = request.form['password']
  25. db.execute()
  26. db.connection.commit()
  27. return jsonify(
  28. status=0,
  29. user_id=user_id,
  30. email=request.form['email']
  31. )
Add Comment
Please, Sign In to add comment