1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/app/Model/UserSession.php

146 lines
3.3 KiB
PHP
Raw Normal View History

2015-01-16 14:23:05 +01:00
<?php
namespace Model;
use Core\Translator;
/**
* User Session
*
* @package model
* @author Frederic Guillot
*/
class UserSession extends Base
{
/**
* Update user session information
*
* @access public
* @param array $user User data
*/
public function refresh(array $user = array())
{
if (empty($user)) {
$user = $this->user->getById($this->userSession->getId());
}
if (isset($user['password'])) {
unset($user['password']);
}
2015-04-21 17:56:16 +02:00
if (isset($user['twofactor_secret'])) {
unset($user['twofactor_secret']);
}
2015-01-16 14:23:05 +01:00
$user['id'] = (int) $user['id'];
$user['is_admin'] = (bool) $user['is_admin'];
$user['is_ldap_user'] = (bool) $user['is_ldap_user'];
2015-04-21 17:56:16 +02:00
$user['twofactor_activated'] = (bool) $user['twofactor_activated'];
2015-01-16 14:23:05 +01:00
$this->session['user'] = $user;
}
2015-04-21 17:56:16 +02:00
/**
* Return true if the user has validated the 2FA key
*
* @access public
* @return bool
*/
public function check2FA()
{
return isset($this->session['2fa_validated']) && $this->session['2fa_validated'] === true;
}
/**
* Return true if the user has 2FA enabled
*
* @access public
* @return bool
*/
public function has2FA()
{
return isset($this->session['user']['twofactor_activated']) && $this->session['user']['twofactor_activated'] === true;
}
2015-01-16 14:23:05 +01:00
/**
* Return true if the logged user is admin
*
* @access public
* @return bool
*/
public function isAdmin()
{
return isset($this->session['user']['is_admin']) && $this->session['user']['is_admin'] === true;
}
/**
* Get the connected user id
*
* @access public
* @return integer
*/
public function getId()
{
return isset($this->session['user']['id']) ? (int) $this->session['user']['id'] : 0;
}
/**
2015-08-16 17:04:56 +02:00
* Check is the user is connected
2015-01-16 14:23:05 +01:00
*
2015-08-16 17:04:56 +02:00
* @access public
* @return bool
2015-01-16 14:23:05 +01:00
*/
2015-08-16 17:04:56 +02:00
public function isLogged()
2015-01-16 14:23:05 +01:00
{
2015-08-16 17:04:56 +02:00
return ! empty($this->session['user']);
2015-01-16 14:23:05 +01:00
}
/**
2015-08-16 17:04:56 +02:00
* Get project filters from the session
2015-01-16 14:23:05 +01:00
*
* @access public
2015-08-16 17:04:56 +02:00
* @param integer $project_id
* @return string
2015-01-16 14:23:05 +01:00
*/
2015-08-16 17:04:56 +02:00
public function getFilters($project_id)
2015-01-16 14:23:05 +01:00
{
2015-08-16 17:04:56 +02:00
return ! empty($_SESSION['filters'][$project_id]) ? $_SESSION['filters'][$project_id] : 'status:open';
2015-01-16 14:23:05 +01:00
}
/**
2015-08-16 17:04:56 +02:00
* Save project filters in the session
2015-01-16 14:23:05 +01:00
*
* @access public
2015-08-16 17:04:56 +02:00
* @param integer $project_id
* @param string $filters
2015-01-16 14:23:05 +01:00
*/
2015-08-16 17:04:56 +02:00
public function setFilters($project_id, $filters)
2015-01-16 14:23:05 +01:00
{
2015-08-16 17:04:56 +02:00
$_SESSION['filters'][$project_id] = $filters;
2015-01-16 14:23:05 +01:00
}
/**
2015-08-16 17:04:56 +02:00
* Is board collapsed or expanded
2015-01-16 14:23:05 +01:00
*
* @access public
2015-08-16 17:04:56 +02:00
* @param integer $project_id
* @return boolean
2015-01-16 14:23:05 +01:00
*/
2015-08-16 17:04:56 +02:00
public function isBoardCollapsed($project_id)
2015-01-16 14:23:05 +01:00
{
2015-08-16 17:04:56 +02:00
return ! empty($_SESSION['board_collapsed'][$project_id]) ? $_SESSION['board_collapsed'][$project_id] : false;
2015-01-16 14:23:05 +01:00
}
/**
2015-08-16 17:04:56 +02:00
* Set board display mode
2015-01-16 14:23:05 +01:00
*
* @access public
2015-08-16 17:04:56 +02:00
* @param integer $project_id
* @param boolean $collapsed
2015-01-16 14:23:05 +01:00
*/
2015-08-16 17:04:56 +02:00
public function setBoardDisplayMode($project_id, $collapsed)
2015-01-16 14:23:05 +01:00
{
2015-08-16 17:04:56 +02:00
$_SESSION['board_collapsed'][$project_id] = $collapsed;
2015-01-16 14:23:05 +01:00
}
}