Esempio n. 1
0
 /**
  * @param Form $form
  */
 protected function configure(Form $form)
 {
     $presenters = $this->administrationManager->getAdministrationPages();
     /** @var $permissions \Nette\Security\Permission */
     $permissions = $this->authorizatorFactory->getPermissionsByRoles(array($form->data->name));
     foreach ($this->scanResources() as $resource => $privileges) {
         $presenter = $this->presenterFactory->unformatPresenterClass($resource);
         $container = $form->addContainer($this->formatName($resource));
         $container->setCurrentGroup($form->addGroup(isset($presenters[$presenter . ':']) ? $presenters[$presenter . ':']['name'] : $resource));
         $val = $permissions->isAllowed($form->data->name, $resource);
         $container->addCheckbox('all', 'All')->setDefaultValue($val);
         $privilegeContainer = $container->addContainer('privileges');
         foreach ($privileges as $privilege) {
             /** @var $checkbox \Nette\Forms\Controls\Checkbox */
             $checkbox = $privilegeContainer->addCheckbox($privilege, $privilege);
             $checkbox->setDefaultValue($permissions->isAllowed($form->data->name, $resource, $privilege));
             if ($val) {
                 $checkbox->disabled = TRUE;
             }
         }
     }
     $form->setCurrentGroup();
     $form->addSaveButton('Save');
 }
Esempio n. 2
0
 public function handleLoad($name)
 {
     /** @var $loginProvider \CmsModule\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 \\CmsModule\\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');
             }
         }
     } else {
         if ($this->loginProviderMode === 'load') {
             $this->onLoad($this);
         }
     }
 }