本文整理汇总了PHP中Nette\Security\User::isLoggedIn方法的典型用法代码示例。如果您正苦于以下问题:PHP User::isLoggedIn方法的具体用法?PHP User::isLoggedIn怎么用?PHP User::isLoggedIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Security\User
的用法示例。
在下文中一共展示了User::isLoggedIn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authorize
/**
* @inheritdoc
*/
public function authorize($resource, $action, $parameters = NULL)
{
if (!$this->user->isLoggedIn()) {
throw new AuthorizationException('User is not logged in.');
}
return TRUE;
}
示例2: __invoke
/**
* @return mixed
*/
public function __invoke()
{
if ($this->user->isLoggedIn()) {
return $this->user->getId();
}
return NULL;
}
示例3: checkUser
/**
* @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;
}
示例4: checkUser
/**
* @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;
}
示例5: checkLoggedIn
protected function checkLoggedIn($element)
{
if ($element->hasAnnotation('loggedIn')) {
return $element->getAnnotation('loggedIn') == $this->user->isLoggedIn();
}
return true;
}
示例6: isAllowed
/**
* 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();
}
示例7: startup
protected function startup()
{
parent::startup();
if (!$this->user->isLoggedIn()) {
$this->flashMessage('To enter the section please log in.');
$this->redirect(':Front:Home:Homepage:');
}
}
示例8: createComponentShipmentForm
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;
}
示例9: actionDefault
/**
* @param string|null $backlink
*/
public function actionDefault($backlink = null)
{
if ($this->user->isLoggedIn()) {
$this->restoreRequest($backlink);
$this->redirect(':Front:Home:Homepage:');
}
$this->backlink = $backlink;
}
示例10: onSuccessLoginForm
public function onSuccessLoginForm()
{
if ($this->user->isLoggedIn()) {
$this->user->logout(true);
} else {
$this->user->login($this->identity);
}
$this->redirect("this");
}
示例11: authenticate
/**
* @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.');
}
}
}
示例12: startup
public function startup()
{
parent::startup();
if ($this->user->isLoggedIn()) {
if ($this->getParameter('id') != $this->user->getId()) {
$this->redirect('Sign:in');
}
}
}
示例13: handleSave
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);
}
示例14: log
/** 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);
}
}
示例15: isGranted
/**
* {@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);
}