/** * returns the advertised title * * @return array */ public function __invoke() { $SocialNetworksEnabled = []; foreach ($this->config['hybridauth'] as $key => $val) { if ($val['enabled'] and in_array(strtolower($key), $this->options->getEnableLogins())) { $SocialNetworksEnabled[strtolower($key)] = $key; } } return $SocialNetworksEnabled; }
/** * {@inheritDoc} */ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); $configArray = isset($config['auth_options']) ? $config['auth_options'] : array(); $options = new ModuleOptions($configArray); if ("" == $options->getFromName()) { /* @var $coreOptions \Core\Options\ModuleOptions */ $coreOptions = $serviceLocator->get('Core\\Options'); $options->setFromName($coreOptions->getSiteName()); } return new ModuleOptions($configArray); }
/** * test, if configuration overwrites default values * * @dataProvider providerTestFactory */ public function testFactory($config) { $serviceManager = new ServiceManager(); $serviceManager->setService('Config', $config); $factory = new ModuleOptionsFactory(); $defaultOption = new ModuleOptions(array()); $object = $factory->createService($serviceManager); $this->assertInstanceOf('Auth\\Options\\ModuleOptions', $object); if (isset($config['auth_options'])) { $this->assertNotEquals($defaultOption->getFromName(), $object->getFromName()); $this->assertEquals($config['auth_options']['from_name'], $object->getFromName()); } else { $this->assertNotEquals($defaultOption->getFromEmail(), '<string:email@example.com>'); $this->assertEquals($defaultOption->getFromName(), $object->getFromName()); } }
public function indexAction() { if (!$this->options->getEnableRegistration()) { $this->notification()->info('Registration is disabled'); return $this->redirect()->toRoute('lang'); } /** @var \Zend\Http\Request $request */ $request = $this->getRequest(); $viewModel = new ViewModel(); try { if ($request->isPost()) { $this->form->setData($request->getPost()->toArray() ?: array()); if ($this->form->isValid()) { $mailer = $this->getPluginManager()->get('Mailer'); $url = $this->plugin('url'); // we cannot check reCaptcha twice (security protection) so we have to remove it $filter = $this->form->getInputFilter()->remove('captcha'); $this->service->proceed($filter, $mailer, $url); $this->notification()->success('An Email with an activation link has been sent, please try to check your email box'); $viewModel->setTemplate('auth/register/completed'); } else { $viewModel->setTemplate(null); $this->notification()->danger('Please fill form correctly'); } } else { /* @var $register \Zend\Form\Fieldset */ $register = $this->form->get('register'); $register->get('role')->setValue($this->params('role')); } } catch (Exception\UserAlreadyExistsException $e) { $this->notification()->danger('User with this email address already exists'); } catch (\Auth\Exception\UserDeactivatedException $e) { $this->notification()->danger('User with this email address already exists'); } catch (\Exception $e) { $this->logger->crit($e); $this->notification()->danger('An unexpected error has occurred, please contact your system administrator'); } $this->form->setAttribute('action', $this->url()->fromRoute('lang/register')); $viewModel->setVariable('form', $this->form); return $viewModel; }
/** * */ public function proceedMail() { $siteName = $this->options->getSiteName(); $url = $this->getUrlPlugin(); $user = $this->getUser(); if (isset($user)) { $confirmationLink = $url->fromRoute('lang/register-confirmation', array('userId' => $user->getId()), array('force_canonical' => true)); $userEmail = $user->getInfo()->getEmail(); $userName = $user->getInfo()->getDisplayName(); $mailService = $this->getMailService(); $mail = $mailService->get('htmltemplate'); $mail->user = $user; $mail->name = $userName; $mail->confirmationlink = $confirmationLink; $mail->siteName = $siteName; $mail->setTemplate('mail/register'); $mail->setFormattedSubject('your registration on %s', $siteName); $mail->setTo($userEmail); $mailService->send($mail); } }
/** * Login via an external Application. This will get obsolet as soon we'll have a full featured Rest API. * * Passed in params: * - appKey: Application identifier key * - user: Name of the user to log in * - pass: Password of the user to log in * * Returns an json response with the session-id. * Non existent users will be created! * */ public function loginExternAction() { $services = $this->serviceLocator; $adapter = $services->get('ExternalApplicationAdapter'); $appKey = $this->params()->fromPost('appKey'); $adapter->setIdentity($this->params()->fromPost('user'))->setCredential($this->params()->fromPost('pass'))->setApplicationKey($appKey); $auth = $this->auth; $result = $auth->authenticate($adapter); if ($result->isValid()) { $this->logger->info('User ' . $this->params()->fromPost('user') . ' logged via ' . $appKey); // the external login may include some parameters for an update $updateParams = $this->params()->fromPost(); unset($updateParams['user'], $updateParams['pass'], $updateParams['appKey']); $resultMessage = $result->getMessages(); $password = null; if (array_key_exists('firstLogin', $resultMessage) && $resultMessage['firstLogin'] === true) { $password = substr(md5(uniqid()), 0, 6); $updateParams['password'] = $password; } if (!empty($updateParams)) { $user = $auth->getUser(); try { foreach ($updateParams as $updateKey => $updateValue) { if ('email' == $updateKey) { $user->info->email = $updateValue; } $user->{$updateKey} = $updateValue; } } catch (\Exception $e) { } $services->get('repositories')->store($user); } $resultMessage = $result->getMessages(); // TODO: send a mail also when required (maybe first mail failed or email has changed) if (array_key_exists('firstLogin', $resultMessage) && $resultMessage['firstLogin'] === true) { // first external Login $userName = $this->params()->fromPost('user'); $this->logger->debug('first login for User: '******'/^(.*)@\\w+$/', $userName, $realUserName)) { $userName = $realUserName[1]; } $mail = $this->mailer('htmltemplate'); /* @var $mail \Core\Mail\HTMLTemplateMessage */ $apps = $this->config('external_applications'); $apps = array_flip($apps); $application = isset($apps[$appKey]) ? $apps[$appKey] : null; $mail->setVariables(array('application' => $application, 'login' => $userName, 'password' => $password)); $mail->setSubject($this->options->getMailSubjectRegistration()); $mail->setTemplate('mail/first-external-login'); $mail->addTo($user->getInfo()->getEmail()); try { $this->mailer($mail); $this->logger->info('Mail first-login sent to ' . $userName); } catch (\Zend\Mail\Transport\Exception\ExceptionInterface $e) { $this->logger->warn('No Mail was sent'); $this->logger->debug($e); } } return new JsonModel(array('status' => 'success', 'token' => session_id())); } else { $this->logger->info('Failed to authenticate User ' . $this->params()->fromPost('user') . ' via ' . $this->params()->fromPost('appKey')); $this->getResponse()->setStatusCode(Response::STATUS_CODE_401); return new JsonModel(array('status' => 'failure', 'user' => $this->params()->fromPost('user'), 'appKey' => $this->params()->fromPost('appKey'), 'code' => $result->getCode(), 'messages' => $result->getMessages())); } }
/** * @covers Auth\Options\ModuleOptions::getFromName * @covers Auth\Options\ModuleOptions::setFromName */ public function testSetGetFromName() { $input = 'Thomas Müller'; $this->options->setFromName($input); $this->assertEquals($input, $this->options->getFromName()); }
/** * @covers Auth\Options\ModuleOptions::getEnableLogins * @covers Auth\Options\ModuleOptions::setEnableLogins */ public function testSetGetEnableLogins() { $input = ['xing', 'linkedin']; $this->options->setEnableLogins($input); $this->assertEquals($input, $this->options->getEnableLogins()); }