当前位置: 首页>>代码示例>>PHP>>正文


PHP UserService::findTokenBy方法代码示例

本文整理汇总了PHP中UserService::findTokenBy方法的典型用法代码示例。如果您正苦于以下问题:PHP UserService::findTokenBy方法的具体用法?PHP UserService::findTokenBy怎么用?PHP UserService::findTokenBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserService的用法示例。


在下文中一共展示了UserService::findTokenBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: post

 /**
  * Verify user registration with token and user id
  *
  * @param  Request $request
  * @return array
  */
 public function post(Request $request)
 {
     $id = $request->attributes->get('id');
     $token = Arr::get($this->getContentAsArray($request), 'token');
     if (!$token) {
         return $this->createSimpleResponse(422, 'Token not specified.');
     }
     $conditions = ['user_id' => $id, 'token' => $token, 'token_type_id' => TokenEntity::TYPE_VERIFY_REGISTRATION];
     $token = $this->userService->findTokenBy($conditions);
     if (!$token) {
         return $this->createNotFoundResponse();
     }
     try {
         $user = $this->userService->verifyRegistration($token);
     } catch (OutOfBoundsException $e) {
         $httpCodes = [UserService::INCORRECT_TOKEN_TYPE => 422, UserService::TOKEN_EXPIRED => 410, UserService::TOKEN_NOT_FOUND => 404];
         return $this->createErrorResponse(['token' => ['INVALID']], $httpCodes[$e->getCode()]);
     }
     $user = $user->getArrayCopy();
     unset($user['password']);
     return $user;
 }
开发者ID:bodetree,项目名称:synapse-base,代码行数:28,代码来源:VerifyRegistrationController.php

示例2: put

 /**
  * Reset password using token and new password
  *
  * @param  Request $request
  * @return array
  */
 public function put(Request $request)
 {
     $token = Arr::get($this->getContentAsArray($request), 'token');
     // Ensure token is valid
     $token = $this->userService->findTokenBy(['token' => $token, 'token_type_id' => TokenEntity::TYPE_RESET_PASSWORD]);
     if (!$token) {
         return $this->createNotFoundResponse();
     }
     if ($token->getExpires() < time()) {
         return $this->createNotFoundResponse();
     }
     $user = $this->userService->findById($token->getUserId());
     if (!$user) {
         return $this->createNotFoundResponse();
     }
     $password = Arr::get($this->getContentAsArray($request), 'password');
     // Ensure user input is valid
     if (!$password) {
         return $this->createErrorResponse(['password' => ['EMPTY']], 422);
     }
     $this->userService->resetPassword($user, $password);
     $this->userService->deleteToken($token);
     return $this->userArrayWithoutPassword($user);
 }
开发者ID:bodetree,项目名称:synapse-base,代码行数:30,代码来源:ResetPasswordController.php


注:本文中的UserService::findTokenBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。