src/Synapse/User/ResetPasswordController.php
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);
    }
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);
    }
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 ) ; }
Reset password using token and new password

@param  Request $request
@return array
Reset password using token and new password