public function testGenerateTokenCustomMinMaxCharacterList() { $token = TokenGenerator::generateToken(4, 8, '1234567890'); $this->assertGreaterThanOrEqual(4, strlen($token)); $this->assertLessThanOrEqual(8, strlen($token)); $this->assertRegExp('/^\\d+$/', $token); }
/** * Perform a login recovery action for the given email address. * * @param string $email * * @throws \InvalidArgumentException */ public function recoverLogin($email) { LoggerRegistry::debug('UserIntegrationModule::recoverLogin({email})', array('email' => TypeUtilities::describe($email))); // TODO Implement token storage $token = TokenGenerator::generateToken(); $url = $this->getRouteUrl('recover-login-token', array('token' => $token)); $siteInfo = $this->getEngine()->getSiteInfo(); $subject = sprintf('Login Recovery from %s', $siteInfo->getDisplayName()); $addresses = array('sender' => $siteInfo->getAdministratorEmail(), 'to' => $email); $data = array('name' => $siteInfo->getDisplayName(), 'adminName' => $siteInfo->getAdministratorName(), 'adminEmail' => $siteInfo->getAdministratorEmail(), 'email' => $email, 'url' => $url); $type = $this->config('recover-login.notification.type'); $contentType = $this->config('recover-login.notification.content-type'); $content = $this->config('recover-login.notification.content'); switch ($type) { case 'tokens': $body = StringUtilities::replaceTokens($content, $data); $this->getEngine()->swiftMailer()->send($subject, $addresses, $body, $contentType); break; case 'template': $this->getEngine()->swiftMailer()->sendTemplate(new Request(), $subject, $addresses, $content, $data, $contentType); break; default: throw new \InvalidArgumentException(sprintf('Could not process login recovery due to invalid configuration: invalid email type "%s" specified', $type)); } $this->getEngine()->pageMessages()->add($this->config('recover-login.messages.success'), 'success'); }