|
<?php |
|
|
|
namespace Kanboard\Core\User; |
|
|
|
use Kanboard\Core\Base; |
|
use Kanboard\Core\Security\Role; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserSession extends Base |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
public function refresh($user_id) |
|
{ |
|
if ($this->getId() == $user_id) { |
|
$this->initialize($this->userModel->getById($user_id)); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function initialize(array $user) |
|
{ |
|
foreach (array('password', 'is_admin', 'is_project_admin', 'twofactor_secret') as $column) { |
|
if (isset($user[$column])) { |
|
unset($user[$column]); |
|
} |
|
} |
|
|
|
$user['id'] = (int) $user['id']; |
|
$user['is_ldap_user'] = isset($user['is_ldap_user']) ? (bool) $user['is_ldap_user'] : false; |
|
$user['twofactor_activated'] = isset($user['twofactor_activated']) ? (bool) $user['twofactor_activated'] : false; |
|
|
|
if (session_status() === PHP_SESSION_ACTIVE) { |
|
|
|
session_regenerate_id(false); |
|
} |
|
|
|
session_set('user', $user); |
|
session_set('postAuthenticationValidated', false); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getAll() |
|
{ |
|
return session_get('user'); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getRole() |
|
{ |
|
if (! $this->isLogged()) { |
|
return ''; |
|
} |
|
|
|
return session_get('user')['role']; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function isPostAuthenticationValidated() |
|
{ |
|
return session_is_true('postAuthenticationValidated'); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
public function setPostAuthenticationAsValidated() |
|
{ |
|
session_set('postAuthenticationValidated', true); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function hasPostAuthentication() |
|
{ |
|
if (! $this->isLogged()) { |
|
return false; |
|
} |
|
|
|
return session_get('user')['twofactor_activated'] === true; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
public function disablePostAuthentication() |
|
{ |
|
session_merge('user', ['twofactor_activated' => false]); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function isAdmin() |
|
{ |
|
return $this->getRole() === Role::APP_ADMIN; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getId() |
|
{ |
|
if (! $this->isLogged()) { |
|
return 0; |
|
} |
|
|
|
return session_get('user')['id']; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getUsername() |
|
{ |
|
if (! $this->isLogged()) { |
|
return ''; |
|
} |
|
|
|
return session_get('user')['username']; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getLanguage() |
|
{ |
|
if (! $this->isLogged()) { |
|
return ''; |
|
} |
|
|
|
return session_get('user')['language']; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getTimezone() |
|
{ |
|
if (! $this->isLogged()) { |
|
return ''; |
|
} |
|
|
|
return session_get('user')['timezone']; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getTheme() |
|
{ |
|
if (! $this->isLogged()) { |
|
return 'light'; |
|
} |
|
|
|
$user_session = session_get('user'); |
|
|
|
if (array_key_exists('theme', $user_session)) { |
|
return $user_session['theme']; |
|
} |
|
|
|
return 'light'; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function hasSubtaskListActivated() |
|
{ |
|
return session_is_true('subtaskListToggle'); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function isLogged() |
|
{ |
|
return session_exists('user') && session_get('user') !== []; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getFilters($projectID) |
|
{ |
|
if (! session_exists('filters:'.$projectID)) { |
|
return session_get('user') ? session_get('user')['filter'] ?: 'status:open' : 'status:open'; |
|
} |
|
|
|
return session_get('filters:'.$projectID); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function setFilters($projectID, $filters) |
|
{ |
|
session_set('filters:'.$projectID, $filters); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getListOrder($projectID) |
|
{ |
|
$default = ['tasks.id', 'DESC']; |
|
|
|
if (! session_exists('listOrder:'.$projectID)) { |
|
return $default; |
|
} |
|
|
|
return session_get('listOrder:'.$projectID); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function setListOrder($projectID, $listOrder, $listDirection) |
|
{ |
|
session_set('listOrder:'.$projectID, [$listOrder, $listDirection]); |
|
} |
|
} |
|
|