getIdentity() public method

Returns current user identity, if any.
public getIdentity ( ) : Nette\Security\IIdentity | null
return Nette\Security\IIdentity | null
Ejemplo n.º 1
0
 public function onSuccessCommentRemoval(Comment $comment, $id)
 {
     /** @var \Users\User $user */
     $user = $this->user->getIdentity();
     $pageLink = $this->linkGenerator->link('Pages:Front:Page:show', ['internal_id' => $comment->getPageId()]);
     $this->appEventLogger->saveLog(sprintf('User [%s#%s] <b>has REMOVED</b> the Comment [%s#] of Author [%s] on the <a href="%s">Page [%s#%s]</a>', $user->getId(), $user->getUsername(), $id, $comment->getAuthor(), $pageLink, $comment->getPageId(), $comment->getPageTitle()), 'page_comment_release', $user->getId());
 }
Ejemplo n.º 2
0
 /** 
  * Panel prihlaseneho uzivatela
  * @param string $baseUrl
  * @param string $log_out
  * @return \App\FrontModule\Components\User\MenuItem */
 private function _panelPrihlaseny($baseUrl, $log_out)
 {
     $menu_user = [];
     $udata = $this->user->getIdentity();
     if ($this->nastavenie['view_avatar']) {
         $obb = Html::el('img class="avatar"');
         if ($udata->avatar_25 && is_file('www/' . $udata->avatar_25)) {
             $obb = $obb->src($baseUrl . '/www/' . $udata->avatar_25)->alt('avatar');
         } else {
             $obb = $obb->src($baseUrl . '/www/ikonky/64/figurky_64.png')->alt('bez avatara');
         }
     } else {
         $obb = "";
     }
     $menu_user[] = new MenuItem(['odkaz' => 'UserLog:', 'nazov' => $obb . " " . $udata->meno . ' ' . $udata->priezvisko, 'title' => $udata->meno . ' ' . $udata->priezvisko]);
     if ($this->user->isAllowed('admin', 'enter')) {
         $menu_user[] = new MenuItem(['odkaz' => ':Admin:Homepage:', 'title' => 'Administrácia', 'ikonka' => $this->nastavenie['admin_link'] & 1 ? 'pencil' : '', 'nazov' => $this->nastavenie['admin_link'] & 2 ? $this->texty['base_AdminLink_name'] : '']);
     }
     if ($this->user->isInRole('admin')) {
         $hl_m_db_info = $this->lang->getDBInfo();
         $menu_user[] = new MenuItem(['abs_link' => $baseUrl . "/www/adminer/?server=" . $hl_m_db_info['host'] . "&db=" . $hl_m_db_info['dbname'], 'title' => 'Adminer', 'target' => '_blank', 'nazov' => Html::el('img')->src($baseUrl . '/www/ikonky/16/graf_16.png')->alt('Adminer')]);
     }
     $menu_user[] = new MenuItem(['odkaz' => 'signOut!', 'ikonka' => "sign-out", 'nazov' => $log_out]);
     return $menu_user;
 }
 public function processCreateInvitation(Form $form)
 {
     $value = $form->getValues();
     $invitation = new Invitation($value['email'], $this->user->getIdentity());
     try {
         /** @var EntityResultObject $resultObject */
         $resultObject = $this->invitationsFacade->createInvitation($invitation);
         $this->flashMessage('Registrační pozvánka byla vytvořena.', 'success');
         if (!$resultObject->hasNoErrors()) {
             $error = $resultObject->getFirstError();
             $this->flashMessage($error['message'], $error['type']);
         }
     } catch (InvitationCreationAttemptException $ca) {
         $this->flashMessage('Pozvánku nebyla vytvořena. Zkuste akci opakovat později.', 'error');
     } catch (UserAlreadyExistsException $uae) {
         $form->addError('Pozvánku nelze odeslat. Uživatel s E-Mailem ' . $value['email'] . ' je již zaregistrován.');
         return;
     } catch (InvitationAlreadyExistsException $iae) {
         $form->addError('Někdo jiný již odeslal pozvánku uživateli s E-mailem ' . $value['email']);
         return;
     } catch (DBALException $e) {
         $this->flashMessage('Při vytváření pozvánky došlo k chybě. Zkuste akci opakovat později.', 'error');
     }
     $this->redirect('this');
 }
Ejemplo n.º 4
0
 public function createComponentShipmentForm()
 {
     $form = $this->shipmentFormFactory->create($this->currentCartService->getCurrentCart()->getShipment(), $this->user->isLoggedIn() ? $this->user->getIdentity() : null);
     $form->onSuccess[] = function (ShipmentForm $form) {
         $this->updateShipment($form);
     };
     return $form;
 }
 /**
  * @return \Nette\Database\Table\Selection
  */
 protected function getData()
 {
     $selection = $this->sectionFacade->all();
     if (!$this->user->getIdentity()->super) {
         $this->sectionFilter->filterId($selection, $this->user->getIdentity()->sections);
     }
     return $selection;
 }
 public function getData()
 {
     $selection = $this->sectionFacade->all();
     if (!$this->user->getIdentity()->super) {
         $this->sectionFilter->filterId($selection, $this->user->getIdentity()->sections);
     }
     return $selection->fetchPairs('id', 'id');
 }
Ejemplo n.º 7
0
 protected $user;
 /** @var DbTable\Lang */
 public $lang;
 /** @var array Hodnoty id=>nazov pre formulare z tabulky registracia */
 protected $urovneReg;
 /** @var array Hodnoty id=>nazov pre formulare z tabulky hlavicka */
 protected $hlavickaForm;
 /** @var array Hodnoty id=>nazov pre formulare z tabulky dlzka_novinky */
 public $dlzkaNovinkyForm;
Ejemplo n.º 8
0
 /**
  * @return \Nette\Database\Table\Selection
  */
 public function getUserSection()
 {
     $selection = $this->sectionFacade->all();
     if (!$this->user->getIdentity()->super) {
         $this->sectionFilter->filterId($selection, $this->user->getIdentity()->sections);
     }
     return $selection;
 }
Ejemplo n.º 9
0
 /**
  * @param Form $form
  */
 public function Submit(Form $form)
 {
     $json = new \stdClass();
     $json->result = "success";
     $values = $form->getValues();
     $result = false;
     if (!empty($values['userID'])) {
         $userEntity = $this->userRepository->get($values['userID']);
         if ($userEntity) {
             if ($this->user->isAllowed("user_management", "edit")) {
                 $userEntity->setLogin($values['login']);
                 if (!empty($values['password1'])) {
                     $userEntity->setPassword($values['password1']);
                 }
                 if ($userEntity->getLogin() !== "root" && $userEntity->getUserID() !== $this->user->getId()) {
                     $userEntity->setActive($values['active']);
                     if ($userEntity->getRole()->getAclRoleID() != $this->user->getIdentity()->data['aclRoleID']) {
                         $userEntity->setAclRoleID($values['role']);
                     }
                 }
                 try {
                     $result = $this->userRepository->save();
                 } catch (\PDOException $e) {
                     $result = $e->getMessage();
                 }
             } else {
                 $result = UserForm::PERMISSION;
             }
         }
     } else {
         if ($this->user->isAllowed("user_management", "add")) {
             $userEntity = new UserEntity();
             $userEntity->setLogin($values['login'])->setPassword($values['password1'])->setActive($values['active'])->setAclRoleID($values['role']);
             try {
                 $result = $this->userRepository->push($userEntity)->save();
             } catch (\PDOException $e) {
                 $result = $e->getMessage();
                 if (preg_match("/Duplicate entry/", $result)) {
                     $result = "Nick <strong>" . $values['login'] . "</strong> již existuje. Zvolte prosím jiný login.";
                 }
             }
             if ($result instanceof UserEntity || $result === TRUE) {
                 $result = TRUE;
             }
         } else {
             $result = UserForm::PERMISSION;
         }
     }
     if ($result === TRUE) {
         $json->result = "success";
     } else {
         $json->result = "error";
         $json->message = $result;
     }
     $response = new JsonResponse($json);
     $this->getPresenter()->sendResponse($response);
 }
Ejemplo n.º 10
0
 public static function loadFromSession(\Nette\Security\User $user)
 {
     $instance = new User();
     $instance->setId($user->getIdentity()->id);
     $instance->setRole($user->getRoles()[0]);
     $instance->setEmail($user->getIdentity()->email);
     $instance->setFirstName($user->getIdentity()->firstName);
     $instance->setLastName($user->getIdentity()->lastName);
     return $instance;
 }
Ejemplo n.º 11
0
 /**
  * @param \Nette\Application\UI\Form $form
  */
 public function processForm(Form $form)
 {
     $values = $form->values;
     $event = $this->event ? $this->event : new Entity\Event($this->securityUser->getIdentity());
     $event->name = $values->name;
     $event->date = DateTime::from($values->date);
     $event->place = $values->place;
     $event->note = $values->note;
     $this->eventFacade->save($event);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function isGranted($attributes, $object = null)
 {
     if (!is_array($attributes)) {
         $attributes = array($attributes);
     }
     if (!$this->user->isLoggedIn() || ($identity = $this->user->getIdentity()) === null) {
         $identity = new GuestIdentity();
     }
     return $this->decisionManager->decide($identity, $attributes, $object);
 }
Ejemplo n.º 13
0
 /** Funkce pro zápis zprávy
  * 
  * @param string $message
  */
 public function log($message)
 {
     if (is_string($message) && !empty($message)) {
         $record = array('timestamp' => new DateTime(), 'message' => $message, 'ip' => $_SERVER["REMOTE_ADDR"]);
         if ($this->user && $this->user->isLoggedIn()) {
             $record['userID'] = $this->user->getIdentity()->userID;
         }
         $this->database->table(SQLLogger::DB_TABLE)->insert($record);
     }
 }
Ejemplo n.º 14
0
 /**
  * Callback method, that is called once form is successfully submitted, without validation errors.
  *
  * @param Form $form
  * @param Nette\Utils\ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if ($this->pad === NULL) {
         $this->em->persist($pad = new Pad($this->user->getIdentity()));
     } else {
         $pad = $this->pad;
     }
     $pad->setName($values->name);
     $this->em->flush($pad);
     $this->onSuccess($this, $pad);
 }
Ejemplo n.º 15
0
 /**
  * Callback method, that is called once form is successfully submitted, without validation errors.
  *
  * @param Form $form
  * @param Nette\Utils\ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     /** @var User $user */
     $user = $this->user->getIdentity();
     try {
         $user->changePassword($values->current, $values->password);
         $this->em->flush();
         $this->onSuccess($this);
     } catch (InvalidPasswordException $e) {
         $form['current']->addError('Invalid current password');
     }
 }
Ejemplo n.º 16
0
 public function consolidateCurrentCartWithCurrentUser()
 {
     if ($this->user->isLoggedIn()) {
         /** @var User $identity */
         $identity = $this->user->getIdentity();
         if ($this->getCurrentCart()->hasItems()) {
             $this->getCurrentCart()->setUser($identity);
             $this->saveCurrentCart();
         } elseif ($identity->hasAnyCart()) {
             $this->setCurrentCart($identity->getLastCart());
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * Startup method
  * @return void
  */
 public function startup()
 {
     parent::startup();
     $this->lang = $this->translator->setLanguage($this->lang);
     $this->answers[0] = _("No");
     $this->answers[1] = _("Yes");
     // load user to presenter
     $this->user = $this->getUser();
     // zkusi jestli je uzivatel prihlasen
     if (!$this->user->isLoggedIn()) {
         $this->redirect(":User:Authenticator:default", array('backlink' => $this->storeRequest()));
     }
     $this->lang = $this->user->getIdentity()->getData()["lang"];
     $this->user->setAuthorizator(new \UserModule\Authorizator());
     return;
 }
Ejemplo n.º 18
0
 /**
  * main action
  * @return void
  */
 public function actionDefault()
 {
     if ($this->user->isLoggedIn()) {
         $this->flashMessage(_("You are still logged in..."), "info");
         $this->restoreRequest($this->backlink);
         $this->redirect(":Data:Browser:");
     }
     // test of use valid SSL client certificate
     if ($this->ssl->verifyClient() == true) {
         $username = $this->ssl->getUsername();
         $serial = $this->ssl->getSerial();
         $this->user->setAuthenticator(new \UserModule\SSLAuthenticator($this->db));
         try {
             // pokud to vyjde je vse OK
             $this->user->login($username, $serial);
             $this->user->getIdentity()->isSSLlogin = true;
             $this->flashMessage(_("You are logged in by SSL Certificate", "success"));
             $this->restoreRequest($this->backlink);
             $this->redirect(":Data:Browser:");
         } catch (\Nette\Security\AuthenticationException $e) {
             // pokud to nevyjde dojdte k prihlaseni jmenem a heslem
             $this->flashMessage(_("You are not logged in by SSL Certificate because of: \n" . $e->getMessage(), "warning"));
             $this->redirect("login");
         }
     } else {
         $this->flashMessage(_("You have not valid SSL certificate, please fill username and password"), "info");
         $this->redirect("login");
     }
     return;
 }
Ejemplo n.º 19
0
 */
class EditCategoriFormFactory
{
    /** @var DbTable\User_categories */
    private $user_categories;
    /** @var array */
    private $urovneReg;
    /** @var int */
Ejemplo n.º 20
0
 public function onLoggedOut(Security $security)
 {
     // BUG: Nette\Security\User 2.1 fires onLoggedOut before clearing storage
     if ($user = $this->repository->find($security->getIdentity()->getId())) {
         $security->getStorage()->setAuthenticated(FALSE);
         $this->user->signOut($user);
     }
 }
Ejemplo n.º 21
0
 public function getIdentity()
 {
     $identity = parent::getIdentity();
     if ($identity !== null) {
         $identity = $this->userService->getById((int) $identity->getId());
     }
     return $identity;
 }
Ejemplo n.º 22
0
 public function log($media, $event, $message, $who = null)
 {
     //Prepare identity
     $user_id = null;
     if ($this->user->isLoggedIn()) {
         $identity = $this->user->getIdentity();
         if (!$who) {
             $who = $identity->username;
         }
         $user_id = $identity->getId();
     } elseif (!$who) {
         $who = self::USR_ANONYMOUS;
     }
     //Prepare message
     $message = str_replace('%user%', $who, $message);
     //Add a record
     $this->storage->addRecord($media, $event, $message, $who, $user_id);
 }
Ejemplo n.º 23
0
 /**
  * Make menu from config.neon
  * @return void
  */
 public function addItems()
 {
     foreach ($this->data as $data) {
         if ($data["module"] . ":" . $data["presenter"] == $this->currentPresenter && $data["action"] == $this->currentAction) {
             $clickable = false;
         } else {
             $clickable = true;
         }
         $this->addItem($data["title"], $data["module"], $data["presenter"], $data["action"], $data["auth"], $clickable);
     }
     if ($this->user->isAllowed("user", "view")) {
         if (!isset($this->user->getIdentity()->isSSLlogin) or $this->user->getIdentity()->isSSLlogin == false) {
             $this->addItem(_("Logout"), "User", "Authenticator", "logout", "user", true);
         } else {
             $this->addItem(_("SSL Login"), "User", "Authenticator", "logout", "user", false);
         }
     }
     return;
 }
Ejemplo n.º 24
0
 public function __construct(User $user)
 {
     $data = $user->getIdentity();
     if (isset($data->data)) {
         foreach ($data->data as $name => $value) {
             if (property_exists($this, $name)) {
                 $this->{$name} = $value;
             }
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * @param \Venne\Files\AjaxFileUploaderControl $control
  * @param string $fileName
  */
 public function fileUpload(AjaxFileUploaderControl $control, $fileName)
 {
     try {
         $file = new File();
         $file->setParent($this->dir);
         $file->setFile(new \SplFileInfo($control->getAjaxDir() . '/' . $fileName));
         $file->setAuthor($this->userRepository->find($this->netteUser->getIdentity()->getId()));
         $this->entityManager->persist($file);
         $this->entityManager->flush();
     } catch (\Exception $e) {
         Debugger::log($e);
     }
 }
Ejemplo n.º 26
0
 public function sendNotifications(Form $form, $values)
 {
     $messages = [];
     foreach ($this->newListings as $listing) {
         $message = $this->sharedListingNotification->getNotificationMessage($listing, $this->user->getIdentity()->username, $this->users[$listing->getOwnerID()]);
         $messages[$listing->getOwnerID()] = $message;
     }
     try {
         $this->messagesFacade->sendMessages($messages);
     } catch (\DibiException $e) {
         $this->presenter->flashMessage('Nepodařilo se odeslat upozornění příjemcům.', 'warning');
         $this->redirect('this');
     }
     $this->redirect('this');
 }
Ejemplo n.º 27
0
 /**
  * Callback method, that is called once form is successfully submitted, without validation errors.
  *
  * @param Form $form
  * @param Nette\Utils\ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if ($this->note === NULL) {
         $note = new Note($this->user->getIdentity());
         $this->em->persist($note);
     } else {
         $note = $this->note;
     }
     $note->setName($values->name);
     $note->setText($values->text);
     if ($values->pad === NULL) {
         $note->setPad(NULL);
     } else {
         $note->setPad($this->padRepository->find($values->pad));
     }
     $this->em->flush();
     $this->onSuccess($this);
 }
Ejemplo n.º 28
0
 /**
  * @return array
  */
 protected function getSections()
 {
     if (!$this->sections) {
         $selection = $this->filterSections($this->sectionFacade->all());
         if (!$this->user->getIdentity()->super) {
             $this->sectionFilter->filterId($selection, $this->user->getIdentity()->sections);
         }
         $this->sectionOrderer->order($selection, 'section');
         if ($this->moduleGroup) {
             $selection->select('section.id, module.name');
             $selection->group('section.module');
         } else {
             $selection->select('section.id,section.name');
         }
         $this->sections = $selection->fetchPairs('id', 'name');
     }
     return $this->sections;
 }
Ejemplo n.º 29
0
 public function __construct(AppEventLogger $appEventLogger, User $user)
 {
     $this->appEventLogger = $appEventLogger;
     $this->user = $user->getIdentity();
 }
Ejemplo n.º 30
0
 public function onSuccessOptionsSaving()
 {
     /** @var \Users\User $user */
     $user = $this->user->getIdentity();
     $this->appEventLogger->saveLog(sprintf('User [%s#%s] <b>has EDITED</b> web options', $user->getId(), $user->getUsername()), 'options_editing', $user->getId());
 }