opensupports/server/models/Session.php
Guillermo Giuliana 92a96c276b
Mandatory Login BE and Ruby tests (#757)
* Mandatory Login BE and Ruby tests

* registration handle and remove user-system setting

* create specific paths to mandatory login changing

* BE logic not allow turn off mandatory login without registratrion

* fix github issues

* Delete config['user-system-enabled'].

* Add some tabulations.

* Create MandatoryLoginReducer.

* Replace 'user-system' to 'mandatory-login'.

* Replace user-system toggle to mandatory-login checbox.

* Add some button in the header.

* Change onChange function mandatory login name.

* Disabled checkbox when you should not change it.

* Delete consolelog and some irrelevant lines.

* Change name of mandatory login reducer.

* Change style button in install step 1

* Change style button in install step 2

* Fix loading bug in submmit button.

* Change style button in install step 5

* Change style button in install step 6

* Delete UserSystemEnabled in ticket viewer component.

* Delete UserSystemEnabled in some files.

* Delete onRetriveFail function in main view ticket page.

* Replace user-system-enabled to mandatory-login in some files.

* replace user-system-enabled to mandatory-login in install steps.

* Fix style in dashboard-[Ccreate-ticket-page and dashboard-list-article-page.

* Fix mandatory login issues

Co-authored-by: LautaroCesso <lautaro_cesso@hotmail.com>
Co-authored-by: Ivan Diaz <ivan@opensupports.com>
2020-05-12 19:22:51 -03:00

95 lines
2.3 KiB
PHP
Executable File

<?php
class Session {
use SingletonTrait;
private $sessionPrefix = '';
private function __construct() {
$this->initSession();
}
public function initSession() {
session_cache_limiter(false);
session_start();
}
public function closeSession() {
session_destroy();
}
public function clearSessionData() {
$this->store('userId', null);
$this->store('staff', null);
$this->store('token', null);
$this->store('ticketNumber', null);
}
public function setSessionData($data) {
foreach($data as $key => $value)
$this->store($key, $value);
}
public function createSession($userId, $staff = false, $ticketNumber = null) {
$this->store('userId', $userId);
$this->store('staff', $staff);
$this->store('ticketNumber', $ticketNumber);
$this->store('token', Hashing::generateRandomToken());
}
public function isTicketSession() {
return $this->getStoredData('ticketNumber') && $this->getStoredData('token');
}
public function getTicketNumber() {
return $this->getStoredData('ticketNumber');
}
public function getUserId() {
return $this->getStoredData('userId');
}
public function getToken() {
return $this->getStoredData('token');
}
public function sessionExists() {
return !!$this->getToken();
}
public function isStaffLogged() {
return $this->getStoredData('staff');
}
public function checkAuthentication($data) {
$userId = $this->getStoredData('userId');
$token = $this->getStoredData('token');
return $userId && $token &&
$userId === $data['userId'] &&
$token === $data['token'];
}
public function store($key, $value) {
$_SESSION[$this->sessionPrefix . $key] = $value;
}
private function getStoredData($key) {
$storedValue = null;
if (array_key_exists($this->sessionPrefix . $key, $_SESSION)) {
$storedValue = $_SESSION[$this->sessionPrefix . $key];
}
return $storedValue;
}
public function isLoggedWithId($userId) {
return ($this->getStoredData('userId') === $userId);
}
public function setSessionPrefix($prefix) {
$this->sessionPrefix = $prefix;
}
}