public function login($roleName) { $identity = new User(); $identity->id = 0; $identity->email = '*****@*****.**'; $identity->name = 'Name'; $identity->surname = 'Surname'; $identity->active = TRUE; $identity->registered = new DateTime(); $identity->lastLogin = new DateTime(); $identity->lang = 'cs'; switch ($roleName) { case 'admin': $identity->id = 1; $role = new Role(); $role->id = 1; $role->name = 'administrator'; $identity->addRole($role); break; default: $role = new Role(); $role->id = 1; $role->name = $roleName; $identity->addRole($role); } $this->user->login($identity); }
protected function checkLoggedIn($element) { if ($element->hasAnnotation('loggedIn')) { return $element->getAnnotation('loggedIn') == $this->user->isLoggedIn(); } return true; }
public function __construct(DbTable\Oznam_ucast $oznam_ucast, DbTable\Oznam_volba $oznam_volba, Nette\Security\User $user) { parent::__construct(); $this->oznam_ucast = $oznam_ucast; $this->oznam_volba = $oznam_volba; $this->id_user_profiles = $user->getId(); }
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()); }
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'); }
/** * Callback for Account Settings Form onSuccess event. * @param Form $form * @param ArrayHash $values */ public function formSucceeded(Form $form, $values) { if (!$this->userManager->checkPassword($this->user->getId(), $values->current)) { $form->addError("Invalid current password"); } $this->userManager->setNewPassword($this->user->getId(), $values->new); }
/** * @inheritdoc */ public function authorize($resource, $action, $parameters = NULL) { if (!$this->user->isLoggedIn()) { throw new AuthorizationException('User is not logged in.'); } return TRUE; }
*/ class EditCategoriFormFactory { /** @var DbTable\User_categories */ private $user_categories; /** @var array */ private $urovneReg; /** @var int */
/** * @return mixed */ public function __invoke() { if ($this->user->isLoggedIn()) { return $this->user->getId(); } return NULL; }
/** * Add menu item * @param string $title Text in anchor * @param string $module destination module * @param string $presenter destination presenter * @param string $action destination action * @param string $auth resource for authorizator * @param boolean $clickable is anchor clickable? * @return void */ public function addItem($title, $module, $presenter, $action, $auth, $clickable = true) { if ($this->user->isAllowed($auth, "view")) { $this->items[] = array("title" => $title, "module" => $module, "presenter" => $presenter, "action" => $action, "clickable" => $clickable); } return; }
/** * Callback for SignInForm onSuccess event. * @param Form $form * @param ArrayHash $values */ public function formSucceeded(Form $form, $values) { try { $this->user->login($values->email, $values->password); } catch (Nette\Security\AuthenticationException $e) { $form->addError($e->getMessage()); } }
/** * @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; }
private function extractRoles() { $userRoles = $this->user->getRoles(); if ($this->roleHierarchy) { return $this->roleHierarchy->getReachableRoles($userRoles); } return $userRoles; }
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; }
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); } }
protected function startup() { parent::startup(); if (!$this->user->isLoggedIn()) { $this->flashMessage('To enter the section please log in.'); $this->redirect(':Front:Home:Homepage:'); } }
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'); }
/** * @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 onSuccessLoginForm() { if ($this->user->isLoggedIn()) { $this->user->logout(true); } else { $this->user->login($this->identity); } $this->redirect("this"); }
public function formSucceeded($form, $values) { $this->user->setExpiration('15 hours', false); try { $this->user->login($values->username, $values->password); } catch (Nette\Security\AuthenticationException $e) { $form->addError($e->getMessage()); } }
/** * @param Method $element * @throws \Flame\Rest\Security\ForbiddenRequestException */ public function authenticate(Method $element) { $user = (array) $element->getAnnotation('User'); if (in_array('loggedIn', $user)) { if (!$this->user->isLoggedIn()) { throw new ForbiddenRequestException('Please sign in.'); } } }
public function handleSave(Form $form) { if ($this->user->isLoggedIn()) { $form->data->route->author = $this->user->identity; } else { $form->data->author = $form['author']->getValue(); } parent::handleSave($form); }
public function __construct(array $config, Nette\Security\User $user) { parent::__construct($config); $this->processPattern(function ($value, $key) { return $value === NULL; }, function ($value, $key) use($user) { return $user->isAllowed('WebContent', 'Edit'); }); }
public function startup() { parent::startup(); if ($this->user->isLoggedIn()) { if ($this->getParameter('id') != $this->user->getId()) { $this->redirect('Sign:in'); } } }
public function getDefaultQuota(Nette\Security\User $user) { $quota = '100G'; if ($user->isInRole('SO') || $user->isInRole('ZSO') || $user->isInRole('VV')) { $quota = '3T'; } $quotaNumeric = ByteHelper::humanToBytes($quota); return $quotaNumeric; }
public function onSuccess(Nette\Application\UI\Form $form) { $values = $form->getValues(); try { $this->user->login($values->username, $values->password); } catch (Nette\Security\AuthenticationException $e) { $form->addError($e->getMessage()); return; } }
/** * {@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); }
/** * @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); }
/** 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); } }
/** * Add menu item * @param string $title Text in anchor * @param string $module destination module * @param string $presenter destination presenter * @param string $action destination action * @param string $auth resource for authorizator * @param boolean $clickable is anchor clickable? * @return void */ public function addItem($title, $module, $presenter, $action, $auth, $clickable = true, $params = null) { if ($this->user->isAllowed($auth, "view")) { if ($params != null) { $this->items[] = array("title" => _($title), "module" => $module, "presenter" => $presenter, "action" => $action, "clickable" => $clickable, "params" => $params); } else { $this->items[] = array("title" => _($title), "module" => $module, "presenter" => $presenter, "action" => $action, "clickable" => $clickable); } } return; }