/** * Starts the password recovery process. * * @return void */ public function forgot() { if (!empty($this->request->data['username'])) { $this->loadModel('User.Users'); $user = $this->Users->find()->where(['Users.username' => $this->request->data['username']])->orWhere(['Users.email' => $this->request->data['username']])->first(); if ($user) { $emailSent = NotificationManager::passwordRequest($user)->send(); if ($emailSent) { $this->Flash->success(__d('user', 'Further instructions have been sent to your e-mail address.')); } else { $this->Flash->warning(__d('user', 'Instructions could not been sent to your e-mail address, please try again later.')); } } else { $this->Flash->danger(__d('user', 'Sorry, "{0}" is not recognized as a user name or an e-mail address.', $this->request->data['username'])); } } $this->title(__d('user', 'Password Recovery')); }
/** * test __callStatic() for passwordRequest(). * * @return void */ public function testCallStaticPasswordRequest() { $user = new User(); $passwordRequestMessage = NotificationManager::passwordRequest($user); $this->assertInstanceOf('User\\Notification\\Message\\PasswordRequestMessage', $passwordRequestMessage); }
/** * Sends password recovery instructions to the given user. * * @param int $id User's ID * @return void Redirects to previous page */ public function passwordInstructions($id) { $this->loadModel('User.Users'); $user = $this->Users->get($id, ['fields' => ['id', 'name', 'email']]); if ($user) { NotificationManager::passwordRequest($user)->send(); $this->Flash->success(__d('user', 'Instructions we successfully sent to {0}', $user->name)); } else { $this->Flash->danger(__d('user', 'User was not found.')); } $this->title(__d('user', 'Recovery Instructions')); $this->redirect($this->referer()); }