本文整理汇总了PHP中UserController::validateJSONFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP UserController::validateJSONFormat方法的具体用法?PHP UserController::validateJSONFormat怎么用?PHP UserController::validateJSONFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserController
的用法示例。
在下文中一共展示了UserController::validateJSONFormat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setNewPassword
/**
* @param $json
* @param $email_type
* @return ErrorResponse|null|Response
*/
public static function setNewPassword($json, $email_type)
{
$response = null;
$missing_fields = UserController::validateJSONFormat($json, User::REQUIRED_PASSWORD_RESET_FIELD);
// Check that required fields are not missing
if (!$missing_fields) {
$user_mapper = new UserDBMapper();
$email = $json['email'];
$user = User::fromDBArray($user_mapper->getByEmail($email));
// Set random password
$password = ResetPasswordController::getRandomString(ResetPasswordController::PASSWORD_LENGTH);
$json['password'] = $password;
$id = $user->getId();
$reset_password_user = User::fromResetPasswordQuery($id, $json);
if ($reset_password_user) {
$db_response = $user_mapper->resetPassword($reset_password_user);
if ($db_response instanceof DBError) {
$response = new ErrorResponse($db_response);
} else {
$reset_password_user = $user_mapper->getById($id);
if ($reset_password_user) {
EmailSender::sendEmail($email, $password, $email_type);
// Sending Email notification
$response = new Response(json_encode(array('message' => ResetPasswordController::RESET_PASSWORD_ACCEPTED_MESSAGE), JSON_PRETTY_PRINT), Response::STATUS_CODE_ACCEPTED);
} else {
$response = new ErrorResponse(new NotFoundError());
}
}
}
return $response;
}
return new Response($response);
}
示例2: update
/**
* Updates password in database
* @return ErrorResponse|Response
*/
protected function update()
{
$missing_fields = UserController::validateJSONFormat($this->body, User::REQUIRED_PASSWORD_PUT_FIELD);
// Check that required fields are not missing
if (!$missing_fields) {
$mapper = new UserDBMapper();
$json = $this->body;
$user = User::fromResetPasswordQuery($this->id, $json);
// If user is set
if ($user) {
$db_response = $mapper->resetPassword($user);
if ($db_response instanceof DBError) {
$response = new ErrorResponse($db_response);
} else {
$user = $mapper->getById($this->id);
if ($user) {
$response = new Response(json_encode($user->toArray(), JSON_PRETTY_PRINT), Response::STATUS_CODE_CREATED);
} else {
$response = new ErrorResponse(new NotFoundError());
}
return $response;
}
} else {
$response = new ErrorResponse(new ApplicationError("Reset password error", "There was a problem with the password"));
}
} else {
$response = new ErrorResponse(new MalformedJSONFormatError($missing_fields));
}
return $response;
}
示例3: update
protected function update()
{
$missing_fields = UserController::validateJSONFormat($this->body, User::REQUIRED_PUT_FIELDS);
// Check that required fields are not missing
if (!$missing_fields) {
$mapper = new UserDBMapper();
$json = $this->body;
$json["id"] = $this->id;
$user = User::fromJSON($json);
$db_response = $mapper->update($user);
if ($db_response instanceof DBError) {
$response = new ErrorResponse($db_response);
} else {
$response = $this->get();
}
} else {
$response = new ErrorResponse(new MalformedJSONFormatError($missing_fields));
}
$this->controller = new ErrorController(new AuthenticationError($this->method));
return $response;
}