public function resetAction() { if ($this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute('zfcuser'); } $this->passwordService->cleanExpiredForgotRequests(); $form = $this->getResetForm(); $userId = $this->params()->fromRoute('userId', null); $token = $this->params()->fromRoute('token', null); $passwordRequest = $this->passwordService->getPasswordMapper()->findByUserIdRequestKey($userId, $token); //no request for a new password found if ($passwordRequest === null || $passwordRequest == false) { return $this->redirect()->toRoute('zfcuser/forgotpassword'); } $user = $this->userService->getUserMapper()->findById($userId); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid() && $user !== null) { $this->passwordService->resetPassword($passwordRequest, $user, $form->getData()); $vm = new ViewModel(array('email' => $user->getEmail())); $vm->setTemplate('goalio-forgot-password/forgot/passwordchanged'); return $vm; } } // Render the form return new ViewModel(array('resetForm' => $form, 'userId' => $userId, 'token' => $token, 'email' => $user->getEmail())); }
/** * {@inheritDoc} * * @covers \BjyAuthorize\Provider\Identity\ZfcUserZendDb::__construct */ public function setUp() { $this->authService = $this->getMock('Zend\\Authentication\\AuthenticationService'); $this->userService = $this->getMock('ZfcUser\\Service\\User'); $this->tableGateway = $this->getMock('Zend\\Db\\TableGateway\\TableGateway', array(), array(), '', false); $this->userService->expects($this->any())->method('getAuthService')->will($this->returnValue($this->authService)); $this->provider = new ZfcUserZendDb($this->tableGateway, $this->userService); }
/** * * @param MvcAuthEvent $mvcAuthEvent * @throws \Dws\Exception\Service\ModelNotFoundException */ public function __invoke(MvcAuthEvent $mvcAuthEvent) { // Add validated identity to ZfcUser storage $identity = $mvcAuthEvent->getIdentity(); if ($identity instanceof AuthenticatedIdentity) { $user = $this->userService->getUserMapper()->findById($identity->getAuthenticationIdentity()['user_id']); if ($user) { $this->authenticationService->getStorage()->write($user); } $identity->setName(implode(', ', $user->getRoles()->toArray())); } }
/** * @return bool */ private function logIssues() { if (!$this->isVerbose()) { return false; } $form = $this->userService->getRegisterForm(); foreach ($form->getMessages() as $key => $messages) { foreach ($messages as $issueKey => $issueMessage) { $this->logger->info($key . '/' . $issueKey . ': ' . $issueMessage); } } return true; }
/** * {@inheritDoc} */ public function getIdentityRoles() { $authService = $this->userService->getAuthService(); if (!$authService->hasIdentity()) { return array($this->getDefaultRole()); } // get roles associated with the logged in user $sql = new Sql($this->adapter); $select = $sql->select()->columns(array('role_id' => 'roleId'))->from(array('roles' => 'user_role'))->join(array('linker' => $this->tableName), 'roles.id = linker.role_id', array())->where(array('linker.user_id = ?' => $authService->getIdentity()->getId())); $results = $sql->prepareStatementForSqlObject($select)->execute(); $roles = array(); foreach ($results as $i) { $roles[] = $i['role_id']; } return $roles; }
public function register(array $data) { $registerresult = parent::register($data); if ($registerresult !== false) { $userRole = array('user_id' => $registerresult->getId(), 'role_id' => 'user'); $this->getRoleMapper()->insert($userRole); } return $registerresult; }
/** * {@inheritDoc} */ public function getIdentityRoles() { $authService = $this->userService->getAuthService(); if (!$authService->hasIdentity()) { return array($this->getDefaultRole()); } // get roles associated with the logged in user $sql = new Sql($this->adapter); $select = $sql->select()->from($this->tableName); $where = new Where(); $where->equalTo('user_id', $authService->getIdentity()->getId()); $results = $sql->prepareStatementForSqlObject($select->where($where))->execute(); $roles = array(); foreach ($results as $i) { $roles[] = $i['role_id']; } return $roles; }
/** * {@inheritDoc} */ public function getIdentityRoles() { $authService = $this->userService->getAuthService(); if (!$authService->hasIdentity()) { return array($this->getDefaultRole()); } // get roles associated with the logged in user $sql = new Select(); $sql->from($this->tableName); // @todo these fields should eventually be configurable $sql->join('user_role', 'user_role.id = ' . $this->tableName . '.role_id'); $sql->where(array('user_id' => $authService->getIdentity()->getId())); $results = $this->tableGateway->selectWith($sql); $roles = array(); foreach ($results as $role) { $roles[] = $role['role_id']; } return $roles; }
/** * @covers ZfcUser\Service\User::getFormHydrator */ public function testGetFormHydrator() { $this->serviceManager->expects($this->once())->method('get')->with('zfcuser_user_hydrator')->will($this->returnValue($this->formHydrator)); $service = new Service(); $service->setServiceManager($this->serviceManager); $this->assertInstanceOf('ZfcUser\\Mapper\\HydratorInterface', $service->getFormHydrator()); }