Method for publishing and unpublishing entity
@param integer $id
@param User $userEntity
@throws ItemNotSelectedException
167399
public function publishUnpublish($id,
        User $userEntity
    )
    {
        if ($id === null) {
            throw new ItemNotSelectedException;
        }
        $entity = $this->getById($id);
        $entity->published = !$entity->published;
        $entity->modifiedOn = new DateTime();
        $entity->modifiedBy = $userEntity;
        $this->repository->saveItem($entity);
    }
431455
public function edit($id)
    {
        if (!$this->request->is(['get', 'put'])) {
            throw new MethodNotAllowedException();
        }

        /** @var User $user */
        $user = $this->Users->getUserAndGroups($id);

        if ($this->request->is('put')) {
            $user = $this->Users->patchEntity($user, $this->request->data, ['associated' => 'Groups']);
            $userActivated = ($user->dirty('active') && $user->active);
            if ($userActivated) {
                // do not allow a user to be activated if his email address is not verified
                if (!$user->verified) {
                    $user->active = false;
                    $userActivated = false;
                } else {
                    $user->activate();
                }
            }
            $userDeactivated = ($user->dirty('active') && !$user->active);
            if ($userDeactivated) {
                // do not allow a user to deactivate his own account
                if ($user->id === Wasabi::user()->id) {
                    $user->active = true;
                    $userDeactivated = false;
                } else {
                    $user->deactivate();
                }
            }
            if ($this->Users->save($user, ['associated' => 'Groups'])) {
                if ($user->id === Wasabi::user()->id) {
                    $updateUser = $this->Users->get($user->id);
                    $updateUser->group_id = $this->Users->UsersGroups->getGroupIds($updateUser->id);
                    $this->Auth->setUser($updateUser->toArray());
                    Wasabi::user($updateUser);
                }
                if ($userActivated && $user->verified) {
                    $this->getMailer('Wasabi/Core.User')->send('activatedEmail', [$user]);
                }
                if ($userDeactivated && $user->verified) {
                    $this->getMailer('Wasabi/Core.User')->send('deactivatedEmail', [$user]);
                }
                $this->Flash->success(__d('pb', 'The user <strong>{0}</strong> has been updated.', $user->fullName()));
                $this->redirect($this->Filter->getBacklink(['action' => 'index'], $this->request));
                return;
            } else {
                $this->Flash->error($this->formErrorMessage);
            }
        }

        $groups = $this->Users->Groups->find('list')->order('id ASC');

        // users that are no admin, may not select the admin group
        if (Wasabi::user()->hasAccessLevel(Permission::OWN)) {
            $groups->where(['id <>' => 1]);
        }

        $this->set([
            'user' => $user,
            'groups' => $groups,
            'languages' => Hash::map(Configure::read('languages.backend'), '{n}', function ($language) {
                return [
                    'value' => $language->id,
                    'text' => $language->name
                ];
            })
        ]);

        $this->render('add');
    }
252014
public function set($entity, $entity_id, $created, $user_id = null)
    {
        if (!isset($user_id)) {
            $user_id = $this->user->getId(); // Current user
        }

        if ($this->exists($entity, $entity_id, $user_id)) {
            return true;
        }

        if ((GC_TIME - $created) >= $this->getLifespan()) {
            return true; // Expired and was removed
        }

        $data = array(
            'entity' => $entity,
            'user_id' => $user_id,
            'entity_id' => $entity_id
        );

        return $this->add($data);
    }
1103525
public function deleteAction(Request $request, $id)
        {

            /** @var Customer $oCustomer */
            $oCustomer = CustomerQuery::create()->findOneById($id);

            if ($oCustomer === null) {
                throw $this->createNotFoundException('Unable to find Customer entity.');

            }
            $oCustomer->delete();

            return $this->redirect($this->generateUrl('backend_system_customer'));
        }
880467
public function deleteAction(Request $request, $userId)
    {
        $successorUserId = $request->request->get('successor');

        $userManager = $this->get('phlexible_user.user_manager');

        $successorUser = $userManager->find($successorUserId);
        $user = $userManager->find($userId);

        $userManager->deleteUserWithSuccessor($user, $successorUser);

        $this->get('phlexible_message.message_poster')
            ->post(UsersMessage::create('User "'.$user->getUsername().'" deleted.'));

        return new ResultResponse(true);
    }
257944
protected function updateAuthToken(Entity\Users $userEntity)
    {
        $userName = $userEntity->getUsername();
        $cookieLifetime = (int) $this->cookieOptions['lifetime'];
        $repo = $this->getRepositoryAuthtoken();
        try {
            $tokenEntity = $repo->getUserToken($userEntity->getId(), $this->getClientIp(), $this->getClientUserAgent());
        } catch (DriverException $e) {
            /** @deprecated workaround until v4 */
            if (strpos('no such column: user_id', $e->getMessage()) !== false) {
                throw $e;
            }
            $tokenEntity = false;
        }

        if ($tokenEntity) {
            $token = $tokenEntity->getToken();
        } else {
            $salt = $this->randomGenerator->generateString(32);
            $token = $this->getAuthToken($userEntity->getId(), $salt);

            $tokenEntity = new Entity\Authtoken();
            $tokenEntity->setUserId($userEntity->getId());
            $tokenEntity->setToken($token);
            $tokenEntity->setSalt($salt);
        }

        $tokenEntity->setValidity(Carbon::create()->addSeconds($cookieLifetime));
        $tokenEntity->setIp($this->getClientIp());
        $tokenEntity->setLastseen(Carbon::now());
        $tokenEntity->setUseragent($this->getClientUserAgent());

        try {
            $this->getRepositoryAuthtoken()->save($tokenEntity);
        } catch (DriverException $e) {
            /** @deprecated workaround until v4 */
            if (strpos('no such column: user_id', $e->getMessage()) !== false) {
                throw $e;
            }
        }

        $this->systemLogger->debug("Saving new login token '$token' for user ID '$userName'", ['event' => 'authentication']);

        return $tokenEntity;
    }
329641
public function remove_submission($userid) {
        global $USER;

        if (!$this->can_edit_submission($userid, $USER->id)) {
            print_error('nopermission');
        }

        if ($this->get_instance()->teamsubmission) {
            $submission = $this->get_group_submission($userid, 0, false);
        } else {
            $submission = $this->get_user_submission($userid, false);
        }

        if (!$submission) {
            return false;
        }

        // Tell each submission plugin we were saved with no data.
        $plugins = $this->get_submission_plugins();
        foreach ($plugins as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                $plugin->remove($submission);
            }
        }

        if ($submission->userid != 0) {
            \mod_assign\event\submission_status_updated::create_from_submission($this, $submission)->trigger();
        }
        return true;
    }
1115201
public function updateItem(ItemInterface $item, $itemData, $locale, $userId)
    {
        return $this->itemManager->save($itemData, $locale, $userId, $item);
    }
624485
public function deleteAction(Request $request, $id)
        {
            /** @var User $oUser */
            $oUser = UserQuery::create()->findOneById($id);

            if (count($oUser) === 0) {
                throw $this->createNotFoundException('Unable to find User entity.');

            }
            $oUser->delete();

            return $this->redirect($this->generateUrl('backend_system_user'));
        }
695792
public function getUserEntityByIdentifier(string $userIdentifier): UserEntity
    {
        return new UserEntity(Member::get()->filter(['Email' => $userIdentifier])->first());
    }
780221
protected function createEntityVersionLock(User $user, LockableEntity $entity)
    {
        /** @var EntityVersionLock $lock */
        $lock = $this->objectManager->getRepository('KunstmaanAdminListBundle:EntityVersionLock')->findOneBy([
            'owner' => $user->getUsername(),
            'lockableEntity' => $entity,
        ]);
        if (!$lock) {
            $lock = new EntityVersionLock();
        }
        $lock->setOwner($user->getUsername());
        $lock->setLockableEntity($entity);
        $lock->setCreatedAt(new \DateTime());
        $this->objectManager->persist($lock);
        $this->objectManager->flush();
    }
365816
private function addUserGroup(UserInterface $user, $userGroupData)
    {
        $group = $this->groupRepository->findGroupById($userGroupData['group']['id']);

        if (!$group) {
            throw new EntityNotFoundException($this->groupRepository->getClassName(), $userGroupData['group']['id']);
        }

        $userGroup = new UserGroup();
        $userGroup->setUser($user);
        $userGroup->setGroup($group);
        $userGroup->setLocale(json_encode($userGroupData['locales']));
        $this->em->persist($userGroup);

        $user->addUserGroup($userGroup);

        return true;
    }
1314241
public function handleEvent(Event $event, UserNotificationEventHandler $service)
    {
        // If our event is the wrong type, just do a null/void return
        if (!$event instanceof DeactivateUser) {
            return;
        }

        $entity = $event->getUserEntity();

        if ($entity) {
            $service->deactivated($event);
        }
    }
48445
public function Invitations($UserReference = '', $Username = '', $UserID = '') {
      $this->Permission('Garden.SignIn.Allow');
      $this->EditMode(FALSE);
      $this->GetUserInfo($UserReference, $Username, $UserID, $this->Form->AuthenticatedPostBack());
      $this->SetTabView('Invitations');
      
      $InvitationModel = new InvitationModel();
      $this->Form->SetModel($InvitationModel);
      if ($this->Form->AuthenticatedPostBack()) {
         // Send the invitation
         if ($this->Form->Save($this->UserModel)) {
            $this->InformMessage(T('Your invitation has been sent.'));
            $this->Form->ClearInputs();
         }
      }
      $Session = Gdn::Session();
      $this->InvitationCount = $this->UserModel->GetInvitationCount($Session->UserID);
      $this->InvitationData = $InvitationModel->GetByUserID($Session->UserID);

      $this->Render();
   }
116074
public function handleRemove(int $userId) : void
    {
        if ($this->presenter->isAjax())
        {
            $this->userEntity = $this->userRepository->findOneById($userId);

            $allowRemove = (
                (
                    !$this->userEntity->isInRole(UserAuthorizator::ROLE_ADMIN)
                    || $this->presenter->user->isAllowed(UserAuthorizator::RES_EDIT_ADMINS)
                )
                && $this->presenter->user->isAllowed(UserAuthorizator::RES_REMOVE_HANDLE)
                && $userId !== $this->presenter->user->getId()
            );

            if (!$allowRemove)
            {
                throw new ForbiddenRequestException;
            }

            $this->userManager->delete($this->userEntity);

            $this->presenter->notificationAjax(
                'Uživatel odstaněn.',
                "Uživatel {$this->userEntity->getEmail()} byl úspěšně odstaněn.",
                    'info',
                    FALSE
                );

            $this->presenter->handleModalToggle('hide', '#wakers_user_remove_modal', FALSE);

            $this->onRemove();
        }
    }
848238
static public function publishUserContentObject( $userID )
    {
        $object = eZContentObject::fetch( $userID );
        if( $object->attribute( 'current_version' ) !== '1' )
        {
            eZDebug::writeError( 'Current version is wrong for the user object. User ID: ' . $userID , 'user/register' );
            return array( 'status' => eZModuleOperationInfo::STATUS_CANCELLED );
        }
        eZDebugSetting::writeNotice( 'kernel-user' , 'publishing user object', 'user register' );
        // if the object is already published, continue the operation
        if( $object->attribute( 'status' ) )
        {
            eZDebugSetting::writeNotice( 'kernel-user', 'User object publish is published.', 'user register' );
            return array( 'status' => eZModuleOperationInfo::STATUS_CONTINUE );
        }
        $result = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $userID, 'version' => 1 ) );
        if( $result['status'] === eZModuleOperationInfo::STATUS_HALTED )
        {
            eZDebugSetting::writeNotice( 'kernel-user', 'User object publish is in pending.', 'user register' );
            return array( 'status' => eZModuleOperationInfo::STATUS_HALTED );
        }
        return $result;
    }
214256
public function actionChange($id, $user_id, $add)
    {
        $authItem = AuthItem::findOne($id);
        if ($add) {
            Yii::$app->authManager->assign($authItem, $user_id);
        } else {
            $rootCount = AuthAssignment::find()->where(['item_name' => $id])->count();
            if ($id == 'root' && ! $rootCount < 2) {
                throw new HttpException(403, Yii::t('access', 'only_root_remove_denied'));
            }
            Yii::$app->authManager->revoke($authItem, $user_id);
        }
    }