當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserController::validateJSONFormat方法代碼示例

本文整理匯總了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);
 }
開發者ID:DEH-Standardization,項目名稱:ehelse_server,代碼行數:38,代碼來源:ResetPasswordController.php

示例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;
 }
開發者ID:DEH-Standardization,項目名稱:ehelse_server,代碼行數:34,代碼來源:PasswordController.php

示例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;
 }
開發者ID:DEH-Standardization,項目名稱:ehelse_server,代碼行數:21,代碼來源:UserController.php


注:本文中的UserController::validateJSONFormat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。