Changeset 1554


Ignore:
Timestamp:
Oct 4, 2006, 10:50:20 PM (18 years ago)
Author:
nikrou
Message:

Fix bug 451: Auto login does not work properly
svn merge r1492:1493 from trunk
svn merge r1510:1511 from trunk
svn merge r1521:1522 from trunk
svn merge r1523:1524 from trunk
svn merge r1525:1526 from trunk
auto_login key add to users table:

  • add update script
  • update upgrade_1.5.0.php script

(related to svn:1553)

Location:
branches/branch-1_6
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_6/identification.php

    r1082 r1554  
    6464      $remember_me = true;
    6565    }
    66     log_user( $row['id'], $remember_me);
     66    log_user($row['id'], $remember_me);
    6767    redirect(empty($redirect_to) ? make_index_url() : $redirect_to);
    6868  }
     
    7171    array_push( $errors, $lang['invalid_pwd'] );
    7272  }
     73}
     74elseif (!empty($_COOKIE[$conf['remember_me_name']]))
     75{
     76  auto_login();
    7377}
    7478//----------------------------------------------------- template initialization
  • branches/branch-1_6/include/config_default.inc.php

    r1530 r1554  
    319319$conf['authorize_remembering'] = true;
    320320
     321// remember_me_name: specifies the name of the cookie used to stay logged
     322$conf['remember_me_name'] = 'pwg_remember';
     323
    321324// remember_me_length : time of validity for "remember me" cookies, in
    322325// seconds.
    323326$conf['remember_me_length'] = 31536000;
    324 
    325 // session_length : time of validity for normal session, in seconds.
    326 $conf['session_length'] = 3600;
    327327
    328328// +-----------------------------------------------------------------------+
  • branches/branch-1_6/include/functions_session.inc.php

    r1443 r1554  
    7272    ini_set('session.use_trans_sid', intval($conf['session_use_trans_sid']));
    7373  }
    74   session_name( $conf['session_name'] );
    75   session_set_cookie_params(
    76       ini_get('session.cookie_lifetime'),
    77       cookie_path()
    78     );
     74  session_name($conf['session_name']);
     75  session_set_cookie_params(0, cookie_path());
    7976}
    8077
  • branches/branch-1_6/include/functions_user.inc.php

    r1463 r1554  
    551551function log_user($user_id, $remember_me)
    552552{
    553   global $conf;
    554   $session_length = $conf['session_length'];
     553  global $conf, $user;
     554
    555555  if ($remember_me)
    556556  {
    557     $session_length = $conf['remember_me_length'];
    558   }
    559   session_set_cookie_params($session_length);
     557    // search for an existing auto_login_key
     558    $query = '
     559SELECT auto_login_key
     560  FROM '.USERS_TABLE.'
     561  WHERE '.$conf['user_fields']['id'].' = '.$user_id.'
     562;';
     563 
     564    $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
     565    if (empty($auto_login_key))
     566    {
     567      $auto_login_key = base64_encode(md5(uniqid(rand(), true)));
     568      $query = '
     569UPDATE '.USERS_TABLE.'
     570  SET auto_login_key=\''.$auto_login_key.'\'
     571  WHERE '.$conf['user_fields']['id'].' = '.$user_id.'
     572;';
     573      pwg_query($query);
     574    }
     575    $cookie = array('id' => $user_id, 'key' => $auto_login_key);
     576    setcookie($conf['remember_me_name'],
     577              serialize($cookie),
     578              time()+$conf['remember_me_length'],
     579              cookie_path()
     580              );
     581  }
    560582  session_start();
    561583  $_SESSION['pwg_uid'] = $user_id;
     584
     585  $user['id'] = $_SESSION['pwg_uid'];
     586  $user['is_the_guest'] = false;
     587}
     588
     589/*
     590 * Performs auto-connexion when cookie remember_me exists
     591 * @return void
     592*/
     593function auto_login() {
     594  global $conf;
     595
     596  // must remove slash added in include/common.inc.php
     597  $cookie = unserialize(stripslashes($_COOKIE[$conf['remember_me_name']]));
     598
     599  $query = '
     600SELECT auto_login_key
     601  FROM '.USERS_TABLE.'
     602  WHERE '.$conf['user_fields']['id'].' = '.$cookie['id'].'
     603;';
     604
     605  $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
     606  if ($auto_login_key == $cookie['key'])
     607  {
     608    log_user($cookie['id'], false);
     609    redirect(make_index_url());
     610  }
     611  else
     612  {
     613    setcookie($conf['remember_me_name'], '', 0, cookie_path());
     614    redirect(make_index_url());
     615  }
    562616}
    563617
  • branches/branch-1_6/include/menubar.inc.php

    r1504 r1554  
    4545    'U_REGISTER' => get_root_url().'register.php',
    4646    'U_LOST_PASSWORD' => get_root_url().'password.php',
    47     'U_LOGOUT' => add_url_params(make_index_url(), array('act'=>'logout') ),
     47    'U_LOGOUT' => get_root_url().'?act=logout',
    4848    'U_ADMIN'=> get_root_url().'admin.php',
    4949    'U_PROFILE'=> get_root_url().'profile.php',
  • branches/branch-1_6/include/user.inc.php

    r1230 r1554  
    2626// +-----------------------------------------------------------------------+
    2727
    28 // retrieving connected user informations
    2928if (isset($_COOKIE[session_name()]))
    3029{
    31  session_start();
    32  if (isset($_SESSION['pwg_uid']))
    33  {
    34    $user['id'] = $_SESSION['pwg_uid'];
    35    $user['is_the_guest'] = false;
    36  }
    37  else
    38  {
    39    // session timeout
    40    $user['id'] = $conf['guest_id'];
    41    $user['is_the_guest'] = true;
    42  }
     30  session_start();
     31  if (isset($_GET['act']) and $_GET['act'] == 'logout')
     32  {
     33    // logout
     34    $_SESSION = array();
     35    session_unset();
     36    session_destroy();
     37    setcookie(session_name(),'',0,
     38              ini_get('session.cookie_path'),
     39              ini_get('session.cookie_domain')
     40              );
     41    setcookie($conf['remember_me_name'], '', 0, cookie_path());
     42    redirect(make_index_url());
     43  }
     44  elseif (empty($_SESSION['pwg_uid']))
     45  {
     46    // timeout
     47    setcookie(session_name(),'',0,
     48              ini_get('session.cookie_path'),
     49              ini_get('session.cookie_domain')
     50              );
     51  }
     52  else
     53  {
     54    $user['id'] = $_SESSION['pwg_uid'];
     55    $user['is_the_guest'] = false;
     56  }
     57}
     58elseif (!empty($_COOKIE[$conf['remember_me_name']]))
     59{
     60  auto_login();
    4361}
    44 else 
     62else
    4563{
    46  $user['id'] = $conf['guest_id'];
    47  $user['is_the_guest'] = true;
     64  $user['id'] = $conf['guest_id'];
     65  $user['is_the_guest'] = true;
     66}
     67
     68if ($user['is_the_guest'] and !$conf['guest_access']
     69    and (basename($_SERVER['PHP_SELF'])!='identification.php')
     70    and (basename($_SERVER['PHP_SELF'])!='password.php')
     71    and (basename($_SERVER['PHP_SELF'])!='register.php'))
     72{
     73  redirect (get_root_url().'identification.php');
    4874}
    4975
     
    5985  $user['is_the_guest'] = false;
    6086}
     87
    6188$user = array_merge(
    6289  $user,
  • branches/branch-1_6/install/phpwebgallery_structure.sql

    r1496 r1554  
    1 -- MySQL dump 9.11
     11-- MySQL dump 9.11
    22--
    33-- Host: localhost    Database: pwg-1_6
     
    346346  `password` varchar(32) default NULL,
    347347  `mail_address` varchar(255) default NULL,
     348  `auto_login_key` varchar(64) default NULL,
    348349  PRIMARY KEY  (`id`),
    349350  UNIQUE KEY `users_ui1` (`username`)
  • branches/branch-1_6/install/upgrade_1.5.0.php

    r1437 r1554  
    469469}
    470470
     471$query = '
     472ALTER TABLE '.PREFIX_TABLE.'users
     473  ADD auto_login_key varchar(64) NOT NULL
     474;';
     475pwg_query($query);
    471476?>
Note: See TracChangeset for help on using the changeset viewer.