public function actionChange($email, $token) { try { $this->user = $this->userManager->findUserByEmail($email); } catch (\Exceptions\Runtime\UserNotFoundException $u) { $this->flashMessage('<strong>Chyba!</strong> Uživatel s E-mailem <strong>' . $email . '</strong> se v systému nenachází a proto není možné změnit heslo spojené s tímto E-mailem. V případě, že jste si jisti tím, že se v systému tento E-mail nacházel, zkuste pro více informací kontaktovat správce na adrese <strong>' . $this->systemEmail . '</strong>.', 'error'); $this->redirect('Password:reset'); } if ($this->user->token == NULL) { $this->flashMessage('<strong>Chyba!</strong> Nelze změnit heslo účtu spojeného s E-mailem <strong>' . $email . '</strong>. Zkuste si heslo znovu obnovit.', 'error'); $this->redirect('Password:reset'); } if ($this->user->token != $token) { $this->flashMessage('<strong>Chyba!</strong> Neoprávněný pokus o změnu hesla!', 'error'); $this->redirect('Password:reset'); } $currentTime = new \DateTime(); if ($currentTime > $this->user->tokenValidity) { $this->userManager->resetToken($this->user); $this->flashMessage('<strong>Chyba!</strong> Čas na změnu hesla vypršel. Pro obnovu hesla využijte formuláře níže.', 'error'); $this->redirect('Password:reset'); } $this['passwordChangeForm']['username']->setDefaultValue($this->user->username); $this['passwordChangeForm']['email']->setDefaultValue($this->user->email); }
/** * Performs an authentication against e.g. database. * and returns IIdentity on success or throws AuthenticationException * @return IIdentity * @throws AuthenticationException */ public function authenticate(array $credentials) { list($email, $password) = $credentials; try { $user = $this->userManager->findUserByEmail($email); } catch (\Exceptions\Runtime\UserNotFoundException $u) { throw new AuthenticationException('Zadali jste špatný email.'); } if (!Passwords::verify($password, $user->password)) { throw new AuthenticationException('Zadali jste špatné heslo.'); } elseif (Passwords::needsRehash($user->password)) { $user->password = Passwords::hash($password); $this->userManager->saveUser($user); } $info = array('lastLogin' => new \DateTime(), 'lastIP' => $this->httpRequest->getRemoteAddress()); $user->assign($info); $this->userManager->saveUser($user); $arr = $user->getData(); unset($arr['password']); return new Identity($user->userID, $user->role, $arr); }