Changeset 745


Ignore:
Timestamp:
May 31, 2021 1:50:48 AM (3 years ago)
Author:
anonymous
Message:

Allow checking isLoggedIn() without incrementing last-access-datetime (to allow for session polling)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Auth_Simple.inc.php

    r708 r745  
    3535     * @param optional array $params  A hash containing parameters.
    3636     */
    37     function __construct($namespace='')
     37    public function __construct($namespace='')
    3838    {
    3939        $app =& App::getInstance();
     
    6060     * @return bool true on success, false on failure
    6161     */
    62     function setParam($params)
     62    public function setParam($params)
    6363    {
    6464        if (isset($params) && is_array($params)) {
     
    7575     * @return mixed               Configured parameter value.
    7676     */
    77     function getParam($param)
     77    public function getParam($param)
    7878    {
    7979        $app =& App::getInstance();
     
    9494     * @param mixed $val      Value to set variable to.
    9595     */
    96     function set($key, $val)
     96    public function set($key, $val)
    9797    {
    9898        if (!isset($_SESSION['_auth_simple'][$this->_ns]['user_data'])) {
     
    110110     * @return mixed          Value stored in session.
    111111     */
    112     function get($key, $default='')
     112    public function get($key, $default='')
    113113    {
    114114        if (isset($_SESSION['_auth_simple'][$this->_ns][$key])) {
     
    126126     * @access public
    127127     */
    128     function clear()
     128    public function clear()
    129129    {
    130130        $_SESSION['_auth_simple'][$this->_ns] = array('authenticated' => false);
     
    141141    * @since    04 Mar 2009 21:07:33
    142142    */
    143     function login($user_id, $password, $callback)
     143    public function login($user_id, $password, $callback)
    144144    {
    145145        global $acct;
     
    174174    * @since    04 Mar 2009 21:07:33
    175175    */
    176     function createSession($user_id)
     176    public function createSession($user_id)
    177177    {
    178178        $app =& App::getInstance();
     
    200200    * @since    04 Mar 2009 21:10:41
    201201    */
    202     function isLoggedIn()
     202    public function isLoggedIn($update_last_access_datetime=true)
    203203    {
    204204        $app =& App::getInstance();
     
    212212        ) {
    213213            // User is authenticated!
    214             $_SESSION['_auth_simple'][$this->_ns]['last_access_datetime'] = date('Y-m-d H:i:s');
    215             return true;
     214            if ($update_last_access_datetime) {
     215                $_SESSION['_auth_simple'][$this->_ns]['last_access_datetime'] = date('Y-m-d H:i:s');
     216            }
     217            $seconds_until_login_timeout = max(0, $this->_params['login_timeout'] - $result['seconds_since_last_login']);
     218            $seconds_until_idle_timeout = max(0, $this->_params['idle_timeout'] - $result['seconds_since_last_access']);
     219            $session_expiry_seconds = min($seconds_until_login_timeout, $seconds_until_idle_timeout);
     220            $app->logMsg(sprintf('Returning true login status for user_id %s (session expires in %s seconds)', $_SESSION['_auth_simple'][$this->_ns]['user_id'], $session_expiry_seconds), LOG_DEBUG, __FILE__, __LINE__);
     221            return $session_expiry_seconds;
    216222        } else if (isset($_SESSION['_auth_simple'][$this->_ns]['authenticated']) && true === $_SESSION['_auth_simple'][$this->_ns]['authenticated']) {
    217223            // User is authenticated, but login has expired.
     
    250256     * @access public
    251257     */
    252     function requireLogin($message='', $type=MSG_NOTICE, $file=null, $line=null)
     258    public function requireLogin($message='', $type=MSG_NOTICE, $file=null, $line=null)
    253259    {
    254260        $app =& App::getInstance();
     
    272278     * @return string   Empty string
    273279     */
    274     function getUsername($null=null)
     280    public function getUsername($null=null)
    275281    {
    276282        return '';
    277283    }
    278284}
    279 
    280 ?>
Note: See TracChangeset for help on using the changeset viewer.