18 protected bool $ignore_access =
false;
22 protected bool $show_disabled_entities =
false;
24 protected bool $show_deleted_entities =
false;
52 return $this->ignore_access;
63 $prev = $this->ignore_access;
64 $this->ignore_access = $ignore;
75 return $this->show_disabled_entities;
86 $prev = $this->show_disabled_entities;
87 $this->show_disabled_entities = $show;
99 return $this->show_deleted_entities;
111 $prev = $this->show_deleted_entities;
112 $this->show_deleted_entities = $show;
129 $user = $this->getLoggedInUser();
132 if (!
$user instanceof \ElggUser) {
136 $this->session->set(
'__user_token', $this->generateUserToken(
$user));
149 $session_token = $this->session->get(
'__user_token');
150 $user_token = $this->generateUserToken($user);
152 if ($session_token !== $user_token) {
169 ],
'sha256', $user->password_hash);
171 return $hmac->getToken();
186 throw new LoginException($this->translator->translate(
'LoginException:BannedUser'));
190 $first_login = empty($user->last_login);
192 $this->events->triggerSequence(
'login',
'user', $user,
function(\
ElggUser $user) use (
$persistent) {
197 $this->setLoggedInUser($user,
true);
198 $this->setUserToken($user);
201 $this->translator->registerTranslations(\
Elgg\Project\
Paths::elgg() .
'languages/');
205 $this->persistent_login->makeLoginPersistent($user);
209 $this->session->migrate();
219 $this->removeLoggedInUser();
221 throw new LoginException($this->translator->translate(
'LoginException:DisabledUser'));
226 throw new LoginException($this->translator->translate(
'LoginException:Unknown'));
230 $this->events->trigger(
'login:first',
'user', $user);
231 $user->first_login = time();
242 $user = $this->getLoggedInUser();
247 if (!$this->events->triggerBefore(
'logout',
'user',
$user)) {
251 $this->persistent_login->removePersistentLogin();
254 $old_msg = $this->session->get(SystemMessagesService::SESSION_KEY, []);
255 $this->session->invalidate();
257 $this->logged_in_user = null;
259 $this->session->set(SystemMessagesService::SESSION_KEY, $old_msg);
261 $this->events->triggerAfter(
'logout',
'user',
$user);
276 $current_user = $this->getLoggedInUser();
277 if ($current_user != $user) {
278 if (!isset($migrate)) {
283 $this->session->migrate(
true);
286 $this->session->set(
'guid', $user->guid);
287 $this->logged_in_user =
$user;
288 $this->access_cache->clear();
289 $this->entity_cache->save($user->guid, $user);
290 $this->translator->setCurrentLanguage($user->language);
302 return $this->logged_in_user;
311 $user = $this->getLoggedInUser();
321 $user = $this->getLoggedInUser();
332 return (
bool) $this->getLoggedInUser();
342 $this->logged_in_user = null;
343 $this->session->remove(
'guid');
344 $this->access_cache->clear();
getLoggedInUser()
Gets the logged in user.
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Generic parent class for login exceptions.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
login(\ElggUser $user, bool $persistent=false)
Log in a user.
isAdminLoggedIn()
Returns whether or not the viewer is currently logged in and an admin user.
logout()
Log the current user out.
setLastLogin()
Sets the last logon time of the user to right now.
getDisabledEntityVisibility()
Are disabled entities shown?
removeLoggedInUser()
Remove the logged in user.
setUserToken(\ElggUser $user=null)
Set a user specific token in the session for the currently logged in user.
isLoggedIn()
Returns whether or not the user is currently logged in.
setDisabledEntityVisibility(bool $show=true)
Include disabled entities in queries.
getDeletedEntityVisibility()
Are deleted entities shown?
__construct(protected\ElggSession $session, protected EventsService $events, protected Translator $translator, protected PersistentLoginService $persistent_login, protected AccessCache $access_cache, protected EntityCache $entity_cache)
Constructor.
Throw when a Security Exception occurs.
if(empty($entity_guid)||empty($recipient)||empty($muted_settings)||empty($hmac_token)) $hmac
static isCli()
Is application running in CLI.
Volatile cache for entities.
validateUserToken(\ElggUser $user)
Validate the user token stored in the session.
setDeletedEntityVisibility(bool $show=true)
Include deleted entities in queries.
getLoggedInUserGuid()
Return the current logged in user by guid.
isEnabled()
Is this entity enabled?
if(isset($_COOKIE['elggperm'])) $session
setLoggedInUser(\ElggUser $user, bool $migrate=null)
Sets the logged in user.
setIgnoreAccess(bool $ignore=true)
Set ignore access.
_elgg_services()
Get the global service provider.
getIgnoreAccess()
Get current ignore access setting.
isBanned()
Is this user banned or not?
Login as the specified user.
generateUserToken(\ElggUser $user)
Generate a token for a specific user.