Exemplo n.º 1
0
 def post(self, username):
     # get the json from the request, it's already validated
     req_json = request.get_json(force=True)
     # validate the request data given a schema for the entity
     err = validate(req_json, self.schema)
     # if it could not be validated, return why
     if err:
         return jsonify(message=err), 400
     # if everything went smootly, create the new entity
     UserViewMapper.to_model_from_json(req_json)
     # indicate success
     return jsonify(message=strings.API_SUCCESS), 200
Exemplo n.º 2
0
 def post(self, username):
     # get the json from the request, it's already validated
     req_json = request.get_json(force=True)
     # validate the request data given a schema for the entity
     err = validate(req_json, self.schema)
     # if it could not be validated, return why
     if err:
         return jsonify(message=err), 400
     # if everything went smootly, create the new entity
     UserViewMapper.to_model_from_json(req_json)
     # indicate success
     return jsonify(message=strings.API_SUCCESS), 200
Exemplo n.º 3
0
 def post(self, repository):
     # get the json from the request, it's already validated
     req_json = request.get_json(force=True)
     # validate the request data given a schema for the entity
     err = validate(req_json, self.schema)
     # if it could not be validated, return why
     if err:
         return jsonify(message=err), 400
     # try to get the tags from the request query string
     try:
         tags = self.get_tags(request)
     except exceptions.InvalidTagsException:
         return jsonify(message=strings.ENTITY_INVALID_TAGS), 401
     # if everything went smootly, create the new entity
     self.entity_type.create_entity_from_dict(req_json, tags)
     # indicate success
     return jsonify(message=strings.API_SUCCESS), 200
Exemplo n.º 4
0
 def post(self, repository):
     # get the json from the request, it's already validated
     req_json = request.get_json(force=True)
     # validate the request data given a schema for the entity
     err = validate(req_json, self.schema)
     # if it could not be validated, return why
     if err:
         return jsonify(message=err), 400
     # try to get the tags from the request query string
     try:
         tags = self.get_tags(request)
     except exceptions.InvalidTagsException:
         return jsonify(message=strings.ENTITY_INVALID_TAGS), 401
     # if everything went smootly, create the new entity
     self.entity_type.create_entity_from_dict(req_json, tags)
     # indicate success
     return jsonify(message=strings.API_SUCCESS), 200
Exemplo n.º 5
0
 def post(self):
     """ Handles client requests to authenticate with the system """
     # validate the json request
     req_json = request.get_json(silent=True)
     err = validate(req_json, auth_schema)
     if err:
         res = jsonify(message=err)
         res.status_code = 400
         return res
     # get the username and password and attempt to login
     username = req_json.get('username')
     password = req_json.get('password')
     res = AuthService.attempt_login(username, password)
     # if theres no user matching those credentials
     if res is None:
         res = jsonify(message=strings.API_BAD_CREDENTIALS)
         res.status_code = 401
         return res
     # if it's valid, return a json object with their auth token
     else:
         return jsonify(token=res)
Exemplo n.º 6
0
 def post(self):
     """ Handles client requests to authenticate with the system """
     # validate the json request
     req_json = request.get_json(silent=True)
     err = validate(req_json, auth_schema)
     if err:
         res = jsonify(message=err)
         res.status_code = 400
         return res
     # get the username and password and attempt to login
     username = req_json.get('username')
     password = req_json.get('password')
     res = AuthService.attempt_login(username, password)
     # if theres no user matching those credentials
     if res is None:
         res = jsonify(message=strings.API_BAD_CREDENTIALS)
         res.status_code = 401
         return res
     # if it's valid, return a json object with their auth token
     else:
         return jsonify(token=res)