public function forgotPassword(Request $request, Application $app) { $usernameOrEmail = $request->request->get('_username'); $user = new UserModel(); if (!$user->readByUsernameOrEmail($usernameOrEmail)) { $app['session']->getFlashBag()->add('errorMessage', 'User not found.'); return $this->view($request, $app, 'forgot_password'); } $identityCheck = UserCommands::checkIdentity($user->username, $user->email, $this->website); if (!$identityCheck->usernameExistsOnThisSite) { $user->siteRole[$this->website->domain] = $this->website->userDefaultSiteRole; } Communicate::sendForgotPasswordVerification($user, $this->website); $app['session']->getFlashBag()->add('infoMessage', 'Password Reset email sent for username "' . $usernameOrEmail . '"'); return $app->redirect('/auth/login'); }
public function forgotPassword(Request $request, Application $app) { $username = $request->request->get('_username'); $identityCheck = UserCommands::checkIdentity($username, '', $this->website); if (!$identityCheck->usernameExists) { $app['session']->getFlashBag()->add('errorMessage', 'User not found.'); return $this->view($request, $app, 'forgot_password'); } $user = new UserModel(); $user->readByUserName($username); if (!$identityCheck->usernameExistsOnThisSite and $user->role != SystemRoles::SYSTEM_ADMIN) { $app['session']->getFlashBag()->add('errorMessage', sprintf('Username "%s" not available on "%s". Use "Create an Account".', $username, $this->website->domain)); return $this->view($request, $app, 'forgot_password'); } Communicate::sendForgotPasswordVerification($user, $this->website); $app['session']->getFlashBag()->add('infoMessage', 'Password Reset email sent for username "' . $username . '"'); return $app->redirect('/auth/login'); }
public function testSendForgotPasswordVerification_PropertiesFromToBodyOk() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser('User', 'Name', '*****@*****.**'); $user = new UserModel($userId); $delivery = new MockCommunicateDelivery(); Communicate::sendForgotPasswordVerification($user, $e->website, $delivery); // What's in the delivery? $senderEmail = 'no-reply@' . $e->website->domain; $expectedFrom = array($senderEmail => $e->website->name); $expectedTo = array($user->email => $user->name); $this->assertEqual($expectedFrom, $delivery->from); $this->assertEqual($expectedTo, $delivery->to); $this->assertPattern('/' . $e->website->name . '/', $delivery->subject); $this->assertNoPattern('/<p>/', $delivery->content); $this->assertPattern('/Name/', $delivery->content); $this->assertPattern('/' . $user->resetPasswordKey . '/', $delivery->content); $this->assertPattern('/<p>/', $delivery->htmlContent); $this->assertPattern('/Name/', $delivery->htmlContent); $this->assertPattern('/' . $user->resetPasswordKey . '/', $delivery->htmlContent); }