A server-side session-handling is also available.
Available functions
Check Login-Status
/**
* @return bool true if user is logged in, else false
*/
Example
{% set loggedIn = hublify.session().loggedIn() %}
{% if loggedIn %}
// User is logged in
{% endif %}
Get data for current User
/**
* @return null|array
* [login] int|bool
* [userid] int internal id for this user, e.g. 1234
* [username] string
* [useremail] string
* [usergrp] array list of usergroups the user belongs to
* [<usergro-id>] string the name of the Usergroup
* [data] array additional data - details depend on the User-Adaptor used in this H-CMS Session
* [firstname] string
* [lastname] string
* ...
*/
Example
{% set user = hublify.session().getUser() %}
Hallo {{ user.username }}!
User-Login
/**
* @param array $loginFields
* [username] string (must) Username
* [userpwd] string (must) Passwort
*
* @return array
* [status] bool true on success, else false
* [msg] array|null msg-stack if relevant
*/
Example
{% set loginResult = hublify.session().login({"username": "MyUserName", "userpwd": "MyPwd"}) %}
{% if loginResult.status == true %}
// Login successful!
{% elseif (loginResult.msg is not empty) %}
// show messages
{% endif %}
User-Logout
/**
* @param ?array $params
* [logout_done_redirect] bool (optional, default: false) Request redirect after successful logout
* [logout_done_page] string (optional, default: none) page-label for the target of the redirect
*
* @return array
* [status] bool true on success, else false
*/
Example
{% set logoutResult = hublify.session().logout() %}
{% if logoutResult.status == true%}
// Logout success!
{% endif %}
Session variables
You can save own variables and values into the user's session.
setVar(...)
To save a value into a session-variable you can use this function.
setVar(string $varName, $value)
Example
{% set dontCare = hublify.session().setVar('myVar', { 'foo': 'bar' } ) %}
getVar(...)
Gets the value of a previously stored session-variable.
getVar(string $varName)
Example
{% set x = hublify.session().getVar('myVar') %}