/** * @inheritdoc */ public function authorize($resource, $action, $parameters = NULL) { if (!$this->user->isLoggedIn()) { throw new AuthorizationException('User is not logged in.'); } return TRUE; }
/** * @return mixed */ public function __invoke() { if ($this->user->isLoggedIn()) { return $this->user->getId(); } return NULL; }
/** * @param Utils\ArrayHash $element * * @return bool * * @throws Exceptions\InvalidArgumentException */ protected function checkUser(Utils\ArrayHash $element) { // Check if element has user parameter if ($element->offsetExists('user')) { // Get user parameter $user = $element->offsetGet('user'); // Parameter is single string if (is_string($user)) { // User have to be logged in and is not if ($user == 'loggedIn' && !$this->user->isLoggedIn()) { return FALSE; // User have to be logged out and is logged in } else { if ($user == 'guest' && $this->user->isLoggedIn()) { return FALSE; } } // Parameter have multiple definitions } else { throw new Exceptions\InvalidArgumentException('In parameter \'user\' are allowed only two strings: \'loggedIn\' & \'guest\''); } return TRUE; } return TRUE; }
/** * @param \Reflector $element * * @return bool * * @throws Exceptions\InvalidArgumentException */ protected function checkUser(\Reflector $element) { // Check if element has @Secured\User annotation if ($element->hasAnnotation('Secured\\User')) { // Get user annotation $user = $element->getAnnotation('Secured\\User'); // Annotation is single string if (is_string($user)) { // User have to be logged in and is not if ($user == 'loggedIn' && !$this->user->isLoggedIn()) { return FALSE; // User have to be logged out and is logged in } else { if ($user == 'guest' && $this->user->isLoggedIn()) { return FALSE; } } // Annotation have multiple definitions } else { throw new Exceptions\InvalidArgumentException('In @Security\\User annotation are allowed only two strings: \'loggedIn\' & \'guest\''); } return TRUE; } return TRUE; }
protected function checkLoggedIn($element) { if ($element->hasAnnotation('loggedIn')) { return $element->getAnnotation('loggedIn') == $this->user->isLoggedIn(); } return true; }
/** * Is user allowed to perform given action with given resource. * * @param mixed * @param string for example 'view', 'edit' * @return bool * @throws \NetteAddons\InvalidArgumentException */ public function isAllowed($resource, $action) { $moderator = $this->user->isInRole('administrators') || $this->user->isInRole('moderators'); if ($resource instanceof Addon) { $ownerId = $resource->userId; $resource = 'addon'; } elseif ($resource instanceof \Nette\Database\Table\ActiveRow) { $ownerId = $resource->user->id; $resource = 'addon'; } elseif ($resource == 'page' && $action == 'manage') { return $moderator; } elseif ($resource != 'addon') { throw new \NetteAddons\InvalidArgumentException(); } if ($resource === 'addon') { if ($action === 'delete' || $action === 'reports') { return $moderator; } if ($action === 'view') { return TRUE; } elseif ($action === 'manage') { return $this->user->isLoggedIn() && $ownerId === $this->user->getId() || $moderator; } elseif ($action === 'vote') { // you can't vote for your own addons return $this->user->isLoggedIn() && $ownerId !== $this->user->getId(); } elseif ($action === 'create') { return $this->user->isLoggedIn(); } } throw new \NetteAddons\InvalidArgumentException(); }
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;
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 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; }
/** * @param string|null $backlink */ public function actionDefault($backlink = null) { if ($this->user->isLoggedIn()) { $this->restoreRequest($backlink); $this->redirect(':Front:Home:Homepage:'); } $this->backlink = $backlink; }
public function onSuccessLoginForm() { if ($this->user->isLoggedIn()) { $this->user->logout(true); } else { $this->user->login($this->identity); } $this->redirect("this"); }
/** * @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 startup() { parent::startup(); if ($this->user->isLoggedIn()) { if ($this->getParameter('id') != $this->user->getId()) { $this->redirect('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); }
/** 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); } }
/** * {@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 User $user * @param callable|null $credentialsValidator */ public function __construct(User $user, callable $credentialsValidator = null) { $this->user = $user; $this->credentialsValidator = $credentialsValidator ?: function () { $this->user->logout(true); try { $this->user->login(...func_get_args()); } catch (\Exception $e) { } // Fail silently return $this->user->isLoggedIn() ? new UserEntity($this->user->getId()) : null; }; }
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()); } } }
/** * @Around("methodAnnotatedWith(Klimesf\Secured\Secured)") */ public function process(AroundMethod $m) { $secured = $this->getAnnotation($m); foreach ($secured->roles as $role) { if (!$this->user->isLoggedIn()) { break; } if (in_array($role, $this->user->getRoles())) { return $m->proceed(); } } $parentClass = $m->getTargetObjectReflection()->parentClass->name; $methodName = $m->getTargetReflection()->name; throw new AuthenticationException("User is not allowed to call " . $parentClass . '::' . $methodName . "()."); }
/** * Checks authorization. * @return void */ public function checkRequirements($element) { $user = (array) $element->getAnnotation('User'); if (in_array('loggedIn', $user, TRUE) && !$this->user->isLoggedIn()) { throw new Application\ForbiddenRequestException(); } }
/** * 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; }
*/ class EditCategoriFormFactory { /** @var DbTable\User_categories */ private $user_categories; /** @var array */ private $urovneReg; /** @var int */
/** * {@inheritdoc} */ public function vote(IIdentity $identity, array $attributes, $object) { $result = self::VOTE_ABSTAIN; foreach ($attributes as $attribute) { if (!$this->supportsAttribute($attribute)) { continue; } $result = self::VOTE_DENIED; if ($attribute === self::IS_ANONYMOUS && !$this->user->isLoggedIn()) { return self::VOTE_GRANTED; } if ($attribute === self::IS_AUTHENTICATED && $this->user->isLoggedIn()) { return self::VOTE_GRANTED; } } return $result; }
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); }
/** * login action * @return void */ public function actionLogin() { if ($this->user->isLoggedIn()) { $this->flashMessage(_("You are still logged in..."), "info"); $this->restoreRequest($this->backlink); $this->redirect(":Data:Browser:"); } return; }
public function __construct(RatingManager $ratingManager, User $user, Session $session, $forWhat, $forId, $mode, $points) { $this->ratingManager = $ratingManager; $this->userId = $user->isLoggedIn() ? $user->id : false; $this->session = $session; $this->mode = $mode; $this->points = $points; if ($mode == self::MODE_PLUS) { $this->from = -1; $this->points = 3; } $this->ratingManager->setManager($forWhat, $forId, $this->userId, $this->session); }
public function __construct(Application\Application $app, User $user, Request $httpRequest, SessionStorage $session, \SkautIS\SkautIS $client) { $this->app = $app; $this->httpRequest = $httpRequest; $this->session = $session; $this->client = $client; if ($user->isLoggedIn() && $this->isLoggedIn()) { $this->getClient()->getUser()->updateLogoutTime(); } // Po odhlaseni nette uzivatele odhlasit i skautis $user->onLoggedOut[] = function () { $this->destroySession(); $this->getClient()->getUser()->resetLoginData(); }; $this->tryProcessResponse(); // ToDo nastavit v extensne do AfterCopile - pak to bude mozna fungovat i v presenterech ktery nemaji tuhle tridu injectlou }
/** * @param Form $form */ public function LoginFormSubmitted(Form $form) { $values = $form->getValues(); $username = $values["nick"]; $password = $values["pass"]; // nastavíme expiraci $this->user->setExpiration('+ 15 minutes', TRUE, TRUE); if (!$this->user->isLoggedIn()) { try { // pokusíme se přihlásit uživatele... $this->user->login("db", $username, $password); // nastavíme expiraci if ($values['remember']) { $this->user->setExpiration('+ 365 day', TRUE); } else { $this->user->setExpiration('+ 15 minutes', TRUE); } // ...a v případě úspěchu presměrujeme na další stránku $this->notify("Uživatel se úspěšně přihlášil."); if ($this->getPresenter()->isAjax()) { $json = new \stdClass(); $json->isLogin = TRUE; $response = new JsonResponse($json); $this->getPresenter()->sendResponse($response); } else { $this->getPresenter()->redirect("Homepage:"); } } catch (AuthenticationException $e) { $this->notify("Uživateli " . $username . " se nepovedlo přihlásit."); $this->flashMessage($e->getMessage()); $this->getPresenter()->redirect("Homepage:"); } } elseif ($this->getPresenter()->isAjax()) { $json = new \stdClass(); $json->isLogin = TRUE; $response = new JsonResponse($json); $this->getPresenter()->sendResponse($response); } }
/** Vykreslenie komponenty */ public function render() { //Inicializacia $pthis = $this->presenter; $baseUrl = $this->template->baseUrl; if ($this->user->isLoggedIn()) { //Panel prihlaseneho uzivatela $menu_user = $this->_panelPrihlaseny($baseUrl, $pthis->udaje_webu['log_out']); } elseif (($vlnh = $this->nastavenie['view_log_in_link_in_header']) >= 0) { //Panel neprihlaseneho uzivatela $menu_user = $this->_panelNeprihlaseny($pthis->udaje_webu, $vlnh); } $lang_temp = $this->lang->findBy(['prijaty' => 1]); if ($lang_temp !== FALSE && count($lang_temp) > 1) { foreach ($lang_temp as $lm) { $menu_user[] = new MenuItem(['odkaz' => ['setLang!', $lm->skratka], 'title' => $lm->nazov . ", " . $lm->nazov_en, 'class' => $lm->skratka == $pthis->language ? "lang actual" : "lang", 'nazov' => Html::el('img')->src($baseUrl . '/www/ikonky/flags/' . $lm->skratka . '.png')->alt('Adminer')]); } } $this->template->menu_user = isset($menu_user) ? $menu_user : []; $this->template->language = $pthis->language; $this->template->setFile(__DIR__ . '/UserLangMenu.latte'); $this->template->render(); }
protected function createComponentModerateCommentForm() { return new Multiplier(function ($idsub) { $idsubArr = explode('q', $idsub); $id = (int) $idsubArr[0]; $sub = $idsubArr[1] === 'false' ? false : true; $form = new Form(); $comment = $this->commentsManager->getSingleComment($id, $sub); if (!(($comment->byUser && $comment->byUser === $this->user->getId() || $this->user->isAllowed('Comments', 'moderate')) && $this->user->isLoggedIn())) { return $form; } $form->getElementPrototype()->class('ajax'); if (!$comment->byUser) { $form->addText('unregName', 'Neregistrované jméno')->setRequired('Zadejte jméno')->setValue($comment->unregName); } $form->addTextArea('text', 'Text')->setRequired('Zadejte text')->setValue(preg_replace('$<p>\\d{1,2}.\\d{1,2}.\\d{4} \\d{1,2}:\\d{1,2} provedena poslední změna</p>$', '', $comment->text)); $form->addCheckbox('deleted', 'Smazaný')->setValue($comment->deleted); $form->addHidden('id', $id); $form->addHidden('sub', $sub ? 'true' : 'false'); $form->addSubmit('moderate', 'Změnit'); $form->onSuccess[] = [$this, 'moderateCommentFormSucceeded']; return $form; }); }