diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 77549581..ffe6c1ad 100755 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -125,6 +125,22 @@ class helper { return ($fileName); } + /** + * Retourne true si le protocole est en TLS + * @return bool + */ + public static function isHttps() { + if( + (empty($_SERVER['HTTPS']) === false AND $_SERVER['HTTPS'] !== 'off') + OR $_SERVER['SERVER_PORT'] === 443 + ) { + return true; + } else { + return false; + } + } + + /** * Retourne l'URL de base du site * @param bool $queryString Affiche ou non le point d'interrogation @@ -132,16 +148,8 @@ class helper { * @return string */ public static function baseUrl($queryString = true, $host = true) { - // Protocol - if( - (empty($_SERVER['HTTPS']) === false AND $_SERVER['HTTPS'] !== 'off') - OR $_SERVER['SERVER_PORT'] === 443 - ) { - $protocol = 'https://'; - } - else { - $protocol = 'http://'; - } + // Protocole + $protocol = helper::isHttps() === true ? 'https://' : 'http://'; // Host if($host) { $host = $protocol . $_SERVER['HTTP_HOST']; diff --git a/core/module/user/user.php b/core/module/user/user.php index ee68ac38..ddbbd739 100755 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -386,17 +386,10 @@ class user extends common { AND password_verify($this->getInput('userLoginPassword', helper::FILTER_STRING_SHORT, true), $this->getData(['user', $userId, 'password'])) AND $this->getData(['user', $userId, 'group']) >= self::GROUP_MEMBER ) { - // Protocol - $secure = false; - if( - (empty($_SERVER['HTTPS']) === false AND $_SERVER['HTTPS'] !== 'off') - OR $_SERVER['SERVER_PORT'] === 443 - ) { - $secure = true; - } + // Expiration $expire = $this->getInput('userLoginLongTime') ? strtotime("+1 year") : 0; - setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false), '', $secure, true); - setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false), '', $secure, true); + setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false), '', helper::isHttps(), true); + setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false), '', helper::isHttps(), true); // Accès multiples avec le même compte $this->setData(['user',$userId,'accessCsrf',$_SESSION['csrf']]); // Valeurs en sortie lorsque le site est en maintenance et que l'utilisateur n'est pas administrateur