Ignore:
Timestamp:
Apr 14, 2017 5:59:29 AM (7 years ago)
Author:
anonymous
Message:

Add notification to user if logged out because of shifting IP address. Minor bugs.

File:
1 edited

Legend:

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

    r582 r593  
    667667        } else if (isset($_SESSION['_auth_sql'][$this->_ns]['authenticated']) && true === $_SESSION['_auth_sql'][$this->_ns]['authenticated']) {
    668668            // User is authenticated, but login has expired.
    669             if (strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) > (time() - 43200)) {
    670                 // Only raise message if last session is less than 12 hours old.
    671                 $app->raiseMsg(sprintf(_("For your safety we logged you out after being idle for %s. Please log in again."), humanTime($this->_params['idle_timeout'], 'hour', '%01.0f')), MSG_NOTICE, __FILE__, __LINE__);
    672             }
    673669
    674670            // Log the reason for login expiration.
    675671            $expire_reasons = array();
     672            $user_notified = false;
    676673            if (!isset($_SESSION['_auth_sql'][$this->_ns]['username']) || empty($_SESSION['_auth_sql'][$this->_ns]['username'])) {
    677674                $expire_reasons[] = 'username not found';
     
    682679            if (!isset($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) || strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) <= (time() - $this->_params['idle_timeout'])) {
    683680                $expire_reasons[] = sprintf('idle_timeout expired (%s older than %s seconds ago)', $_SESSION['_auth_sql'][$this->_ns]['last_access_datetime'], $this->_params['idle_timeout']);
     681                if (strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) > (time() - 43200)) {
     682                    // Only raise message if last session is less than 12 hours old.
     683                    // Notify user why they were logged out if they haven't yet been given a reason.
     684                    $user_notified || $app->raiseMsg(sprintf(_("For your safety we logged you out after being idle for %s. Please log in again."), humanTime($this->_params['idle_timeout'], 'hour', '%01.0f')), MSG_NOTICE, __FILE__, __LINE__);
     685                    $user_notified = true;
     686                }
    684687            }
    685688            if (!isset($_SESSION['_auth_sql'][$this->_ns]['remote_ip']) || $_SESSION['_auth_sql'][$this->_ns]['remote_ip'] != getRemoteAddr()) {
     
    690693                    //   3. the user is connecting from a trusted network (their IP is listed in the trusted_networks)
    691694                    $expire_reasons[] = sprintf('remote_ip not matched (%s != %s)', $_SESSION['_auth_sql'][$this->_ns]['remote_ip'], getRemoteAddr());
     695                    // Notify user why they were logged out if they haven't yet been given a reason.
     696                    $user_notified || $app->raiseMsg(sprintf(_("For your safety we logged you out because your IP address has changed. Please log in again."), null), MSG_NOTICE, __FILE__, __LINE__);
     697                    $user_notified = true;
    692698                } else {
    693699                    $expire_reasons[] = sprintf('remote_ip not matched but user was exempt from this check (%s != %s)', $_SESSION['_auth_sql'][$this->_ns]['remote_ip'], getRemoteAddr());
Note: See TracChangeset for help on using the changeset viewer.