Ejemplo n.º 1
0
 def create_user(self, json):
     valid_params = self.verify_params(json, User.USER_REQUIRED_PARAMETERS)
     if valid_params:
         try:
             new_user = User(**valid_params)
             created_user = new_user.create()
             result = {
                 "message": "Success!",
                 "user": created_user.to_dict(),
             }
             return jsonify(result), 201
         except:
             return jsonify(message="Server error!"), 500
     else:
         return jsonify(message="Bad Request!"), 400
Ejemplo n.º 2
0
 def create_user(json):
     valid_params = UserHandler.verify_params(json, User.USER_REQUIRED_PARAMETERS)
     if valid_params:
         try:
             print(valid_params)
             username_exists = User.verify_username(valid_params.get('username'))
             if username_exists:
                 return jsonify(message="Username already taken."), 400
             new_user = User(**valid_params)
             created_user = new_user.create()
             result = {
                 "message": "Success!",
                 "user": created_user.to_dict(),
             }
             return jsonify(result), 201
         except Exception as err:
             return jsonify(message="Server error!", error=err.__str__()), 500
     else:
         return jsonify(message="Bad Request!"), 400