Exemple #1
0
 /**
  * @secured
  * @param $usersID
  */
 public function handleDelete($usersID)
 {
     if (is_string($usersID)) {
         try {
             $usersID = (array) Json::decode($usersID);
             $usersID = array_values($usersID);
         } catch (JsonException $e) {
             $this['notification']->addError($e->getMessage());
             if ($this->isAjax()) {
                 $this['notification']->redrawControl('error');
             }
         }
     }
     $result = $this->userRepository->deactivate($usersID);
     if ($result === TRUE) {
         $this['notification']->addSuccess("Úspěšně deaktivováno...");
     } else {
         if (strpos("Integrity constraint violation", $result) != -1) {
             $this['notification']->addError("Uživatele se nepovedlo deaktivovat.");
         } else {
             $this['notification']->addError($result);
         }
     }
     if ($this->isAjax()) {
         $this['notification']->redrawControl('error');
         $this['notification']->redrawControl('success');
         $this['grid']->redrawControl();
     }
 }
Exemple #2
0
 /**
  * Performs an authentication
  * @param array $credentials
  * @return NS\Identity
  * @throws NS\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $userSel = $this->users->read();
     $userSel->where('login', $username)->where("active", TRUE);
     $user = $userSel->fetch();
     if (!$user) {
         throw new NS\AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
     }
     if ($user->getPassword() !== $user->calculateHash($password)) {
         throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
     }
     $user->setLastLogged(new DateTime());
     $user->setIp($_SERVER['REMOTE_ADDR']);
     $this->users->save();
     $data = $user->toArray();
     unset($data['password']);
     return new NS\Identity($user->getUserID(), $user->getRole()->getName(), $data);
 }
Exemple #3
0
 /** Vytvoření komponenty
  *
  * @return \Nette\Application\UI\Form
  */
 protected function createComponentForm()
 {
     $form = new Form();
     $form->addText("login", "Přihlašovací jméno:")->setAttribute("autocomplete", "off")->setRequired("Prosím zadejte přihlašovací jméno.");
     $form->addPassword("password1", "Heslo:")->setAttribute("class", "form-control")->setAttribute("autocomplete", "off");
     $form->addPassword("password2", "Heslo pro kontrolu:")->setAttribute("class", "form-control")->setAttribute("autocomplete", "off");
     $roles = $this->roleRepository->read()->where("name != ?", "root");
     if (!$this->user->isInRole("root")) {
         $roles->where("name NOT(?)", $this->user->getRoles());
     }
     $roles = $roles->fetchPairs("aclRoleID", "name");
     $form->addSelect("role", "Oprávnění:", $roles)->setAttribute("class", "form-control");
     $form->addCheckbox("active", "Aktivní");
     $form->addButton("cancel", "Storno")->setHtmlId("cancel");
     $form->addSubmit("sender", "Uložit změny")->setHtmlId("sender");
     $form->addHidden("userID");
     $form['password2']->addRule(Form::EQUAL, 'Hesla se neshodují', $form['password1']);
     if ($this->rsuserID) {
         $userEntity = $this->userRepository->get($this->rsuserID);
         if ($userEntity) {
             $form['login']->setValue($userEntity->login);
             $form['login']->setAttribute("readonly");
             $form['userID']->setValue($this->rsuserID);
             $form['active']->setValue($userEntity->getActive());
             if ($userEntity->getUserID() == $this->user->getId()) {
                 $form['role']->setDisabled();
             }
             if ($userEntity->getLogin() != "root" && $userEntity->getUserID() !== $this->user->getId()) {
                 $form['role']->setValue($userEntity->aclRoleID);
             }
         }
     } else {
         $form['password1']->setRequired("Prosím zadejte heslo.");
     }
     $form->onSuccess[] = callback($this, "Submit");
     $form->onError[] = callback($this, "FormError");
     return $form;
 }