protected function _getUser() { $userId = $this->getRequest()->getParam('id'); if (!$userId) { throw new MissingParameterException("Needed parameter was not found. userId."); } $type = 'id'; if (strpos($userId, ':') !== false) { list($type, $userId) = explode(':', $userId, 2); } switch ($type) { case 'id': $user = $this->_userSrv->load($userId); break; case 'username': $user = $this->_userSrv->loadByUserName($userId); break; default: throw new InvalidArgumentException("Invalid parameter value: userId"); } if (!$user) { throw new NotFoundException("Resource user does not exist"); } $this->_helper->allowed('read', $user); return $user; }
public function resetPasswordAction() { if ($this->getRequest()->isPost()) { $data = $this->_helper->requestData(); $userId = $data['userId']; if (!$userId) { throw new InvalidArgumentException("userId parm not given"); } $user = $this->_userSrv->load($userId); $this->_helper->allowed('resetPassword', $user); try { $this->_userSrv->resetPassword($user); $this->view->data = true; } catch (\Exception $e) { throw new UnexpectedException("Unable to send email"); } } else { throw new ForbiddenException("ResetPassword action must be a post request"); } }
/** * Deletes the given user */ public function deleteAction() { // Try to load the chosen user $userId = $this->getRequest()->getParam('id'); $user = $this->_userSrv->load($userId); if (empty($user)) { throw new NotFoundException('User ' . $userId . ' not found', 404); } // Check permissions $this->_helper->allowed('delete', $user); // Remove the user $this->_userSrv->delete($userId); $this->view->data = true; }
/** * @expectedException Application\Exceptions\InvalidArgumentException */ public function testLoadUserWithoutId() { $user = $this->_service->load(null); }