Exemple #1
0
 /**
  * @param string $service
  * @param string[]|null $parameters
  */
 public function handleConnect($service, $parameters = null)
 {
     $login = $this->securityManager->getLoginProviderByName($service);
     if ($parameters) {
         $login->setAuthenticationParameters(json_decode($parameters, true));
     }
     $login->connectWithUser($this->extendedUser->getUser());
     $this->redirect('this', array('provider' => null, 'loginTable-id' => null, 'loginTable-formName' => null));
 }
Exemple #2
0
 /**
  * @return \Nette\Application\UI\Form
  */
 public function create()
 {
     $form = $this->formFactory->create();
     $form->addHidden('provider')->setValue($this->provider);
     $form['parameters'] = $this->securityManager->getLoginProviderByName($this->provider)->getFormContainer();
     $form->addSubmit('_submit', 'Save')->getControlPrototype()->class[] = 'btn-primary';
     $form->addSubmit('cancel', 'Cancel')->setValidationScope(false);
     return $form;
 }
Exemple #3
0
 /**
  * @param string $provider
  * @param mixed|null $parameters
  */
 private function authenticate($provider, $parameters = null)
 {
     $login = $this->securityManager->getLoginProviderByName($provider);
     try {
         if ($parameters) {
             $login->setAuthenticationParameters($parameters);
         }
         $identity = $login->authenticate(array());
         $this->presenter->user->login($identity);
     } catch (AuthenticationException $e) {
         $this->onError($this, $e->getMessage());
     }
     $this->redirect('this');
 }
Exemple #4
0
 /**
  * @param string $name
  */
 public function handleLoad($name)
 {
     /** @var $loginProvider \Venne\Security\ILoginProvider */
     $loginProvider = $this->securityManager->getLoginProviderByName($name);
     $identity = null;
     try {
         $identity = $loginProvider->authenticate(array());
     } catch (AuthenticationException $e) {
     }
     if ($identity) {
         $this->onError($this, 'The user is already registered');
     }
     $this->authorizatorFactory->clearPermissionSession();
     $formFactory = $this->securityManager->getUserTypeByClass($this->userType)->getRegistrationFormFactory();
     if (!$formFactory instanceof IRegistrationFormFactory) {
         throw new InvalidArgumentException("Form factory '" . get_class($formFactory) . "' is not istance of \\Venne\\System\\Content\\IRegistrationFormFactory");
     }
     $formFactory->connectWithLoginProvider($this['form'], $loginProvider);
     /** @var $form \Venne\Forms\Form */
     $form = $this['form'];
     $form->onSuccess = null;
     if ($this->loginProviderMode === 'load&save') {
         $form->setSubmittedBy($form->getSaveButton());
         $form->fireEvents();
         if ($form->isValid()) {
             $loginProvider->connectWithUser($form->getData()->user);
             $identity = $loginProvider->authenticate(array());
             if ($identity) {
                 $this->presenter->user->login($identity);
                 $this->redirect('this');
             }
         }
     } elseif ($this->loginProviderMode === 'load') {
         $this->onLoad($this);
     }
 }