本文整理汇总了PHP中Nette\Security\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
public function login($roleName)
{
$identity = new User();
$identity->id = 0;
$identity->email = 'admin@bargency.com';
$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);
}
示例2: __construct
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();
}
示例3: onSuccessCommentRemoval
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());
}
示例4: processCreateInvitation
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');
}
示例5: authorize
/**
* @inheritdoc
*/
public function authorize($resource, $action, $parameters = NULL)
{
if (!$this->user->isLoggedIn()) {
throw new AuthorizationException('User is not logged in.');
}
return TRUE;
}
示例6:
*/
class EditCategoriFormFactory
{
/** @var DbTable\User_categories */
private $user_categories;
/** @var array */
private $urovneReg;
/** @var int */
示例7: getUserSection
/**
* @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;
}
示例8: onLoggedOut
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);
}
}
示例9: checkLoggedIn
protected function checkLoggedIn($element)
{
if ($element->hasAnnotation('loggedIn')) {
return $element->getAnnotation('loggedIn') == $this->user->isLoggedIn();
}
return true;
}
示例10: formSucceeded
/**
* 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);
}
示例11: __invoke
/**
* @return mixed
*/
public function __invoke()
{
if ($this->user->isLoggedIn()) {
return $this->user->getId();
}
return NULL;
}
示例12: addItem
/**
* 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;
}
示例13: formSucceeded
/**
* 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());
}
}
示例14: extractRoles
private function extractRoles()
{
$userRoles = $this->user->getRoles();
if ($this->roleHierarchy) {
return $this->roleHierarchy->getReachableRoles($userRoles);
}
return $userRoles;
}
示例15: 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;
}