mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-28 04:09:56 +03:00
Fix bug 451: improvement
small problem with reconnexion after session timeout add auto-login function all staff for session (connexion, auto-login and logout) is now in include/user.inc.php git-svn-id: http://piwigo.org/svn/trunk@1511 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
f6c2f2b1b1
commit
1873dbd062
5 changed files with 73 additions and 54 deletions
|
@ -63,7 +63,7 @@ SELECT '.$conf['user_fields']['id'].' AS id,
|
||||||
{
|
{
|
||||||
$remember_me = true;
|
$remember_me = true;
|
||||||
}
|
}
|
||||||
log_user( $row['id'], $remember_me);
|
log_user($row['id'], $remember_me);
|
||||||
redirect(empty($redirect_to) ? make_index_url() : $redirect_to);
|
redirect(empty($redirect_to) ? make_index_url() : $redirect_to);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -73,24 +73,7 @@ SELECT '.$conf['user_fields']['id'].' AS id,
|
||||||
}
|
}
|
||||||
elseif (!empty($_COOKIE[$conf['remember_me_name']]))
|
elseif (!empty($_COOKIE[$conf['remember_me_name']]))
|
||||||
{
|
{
|
||||||
$cookie = unserialize(pwg_stripslashes($_COOKIE[$conf['remember_me_name']]));
|
auto_login();
|
||||||
$query = '
|
|
||||||
SELECT auto_login_key
|
|
||||||
FROM '.USERS_TABLE.'
|
|
||||||
WHERE '.$conf['user_fields']['id'].' = '.$cookie['id'].'
|
|
||||||
;';
|
|
||||||
|
|
||||||
$auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
|
|
||||||
if ($auto_login_key == $cookie['key'])
|
|
||||||
{
|
|
||||||
log_user($cookie['id'], false);
|
|
||||||
redirect(empty($redirect_to) ? make_index_url() : $redirect_to);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setcookie($conf['remember_me_name'], '', 0, cookie_path());
|
|
||||||
redirect(empty($redirect_to) ? make_index_url() : $redirect_to);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//----------------------------------------------------- template initialization
|
//----------------------------------------------------- template initialization
|
||||||
//
|
//
|
||||||
|
|
|
@ -550,7 +550,7 @@ function get_language_filepath($filename)
|
||||||
*/
|
*/
|
||||||
function log_user($user_id, $remember_me)
|
function log_user($user_id, $remember_me)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf, $user;
|
||||||
|
|
||||||
if ($remember_me)
|
if ($remember_me)
|
||||||
{
|
{
|
||||||
|
@ -581,6 +581,36 @@ UPDATE '.USERS_TABLE.'
|
||||||
}
|
}
|
||||||
session_start();
|
session_start();
|
||||||
$_SESSION['pwg_uid'] = $user_id;
|
$_SESSION['pwg_uid'] = $user_id;
|
||||||
|
|
||||||
|
$user['id'] = $_SESSION['pwg_uid'];
|
||||||
|
$user['is_the_guest'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Performs auto-connexion when cookie remember_me exists
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function auto_login() {
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$cookie = unserialize(pwg_stripslashes($_COOKIE[$conf['remember_me_name']]));
|
||||||
|
$query = '
|
||||||
|
SELECT auto_login_key
|
||||||
|
FROM '.USERS_TABLE.'
|
||||||
|
WHERE '.$conf['user_fields']['id'].' = '.$cookie['id'].'
|
||||||
|
;';
|
||||||
|
|
||||||
|
$auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
|
||||||
|
if ($auto_login_key == $cookie['key'])
|
||||||
|
{
|
||||||
|
log_user($cookie['id'], false);
|
||||||
|
redirect(make_index_url());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setcookie($conf['remember_me_name'], '', 0, cookie_path());
|
||||||
|
redirect(make_index_url());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -44,7 +44,7 @@ $template->assign_vars(
|
||||||
'U_HOME' => make_index_url(),
|
'U_HOME' => make_index_url(),
|
||||||
'U_REGISTER' => get_root_url().'register.php',
|
'U_REGISTER' => get_root_url().'register.php',
|
||||||
'U_LOST_PASSWORD' => get_root_url().'password.php',
|
'U_LOST_PASSWORD' => get_root_url().'password.php',
|
||||||
'U_LOGOUT' => add_url_params(make_index_url(), array('act'=>'logout') ),
|
'U_LOGOUT' => get_root_url().'?act=logout',
|
||||||
'U_ADMIN'=> get_root_url().'admin.php',
|
'U_ADMIN'=> get_root_url().'admin.php',
|
||||||
'U_PROFILE'=> get_root_url().'profile.php',
|
'U_PROFILE'=> get_root_url().'profile.php',
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,26 +25,49 @@
|
||||||
// | USA. |
|
// | USA. |
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
||||||
// retrieving connected user informations
|
|
||||||
if (isset($_COOKIE[session_name()]))
|
if (isset($_COOKIE[session_name()]))
|
||||||
{
|
{
|
||||||
session_start();
|
session_start();
|
||||||
if (isset($_SESSION['pwg_uid']))
|
if (isset($_GET['act']) and $_GET['act'] == 'logout')
|
||||||
{
|
{
|
||||||
$user['id'] = $_SESSION['pwg_uid'];
|
// logout
|
||||||
$user['is_the_guest'] = false;
|
$_SESSION = array();
|
||||||
}
|
session_unset();
|
||||||
else
|
session_destroy();
|
||||||
{
|
setcookie(session_name(),'',0,
|
||||||
// session timeout
|
ini_get('session.cookie_path'),
|
||||||
$user['id'] = $conf['guest_id'];
|
ini_get('session.cookie_domain')
|
||||||
$user['is_the_guest'] = true;
|
);
|
||||||
}
|
setcookie($conf['remember_me_name'], '', 0, cookie_path());
|
||||||
|
redirect(make_index_url());
|
||||||
|
}
|
||||||
|
elseif (empty($_SESSION['pwg_uid']))
|
||||||
|
{
|
||||||
|
// timeout
|
||||||
|
setcookie(session_name(),'',0,
|
||||||
|
ini_get('session.cookie_path'),
|
||||||
|
ini_get('session.cookie_domain')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$user['id'] = $_SESSION['pwg_uid'];
|
||||||
|
$user['is_the_guest'] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (!empty($_COOKIE[$conf['remember_me_name']]))
|
||||||
|
{
|
||||||
|
auto_login();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$user['id'] = $conf['guest_id'];
|
$user['id'] = $conf['guest_id'];
|
||||||
$user['is_the_guest'] = true;
|
$user['is_the_guest'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user['is_the_guest'] and !$conf['guest_access'])
|
||||||
|
{
|
||||||
|
redirect (get_root_url().'identification.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
// using Apache authentication override the above user search
|
// using Apache authentication override the above user search
|
||||||
|
@ -58,6 +81,7 @@ if ($conf['apache_authentication'] and isset($_SERVER['REMOTE_USER']))
|
||||||
|
|
||||||
$user['is_the_guest'] = false;
|
$user['is_the_guest'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = array_merge(
|
$user = array_merge(
|
||||||
$user,
|
$user,
|
||||||
getuserdata(
|
getuserdata(
|
||||||
|
|
18
index.php
18
index.php
|
@ -35,24 +35,6 @@ include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
check_status(ACCESS_GUEST);
|
check_status(ACCESS_GUEST);
|
||||||
|
|
||||||
//---------------------------------------------------------------------- logout
|
|
||||||
if ( isset( $_GET['act'] )
|
|
||||||
and $_GET['act'] == 'logout'
|
|
||||||
and isset( $_COOKIE[session_name()] ) )
|
|
||||||
{
|
|
||||||
// cookie deletion if exists
|
|
||||||
$_SESSION = array();
|
|
||||||
session_unset();
|
|
||||||
session_destroy();
|
|
||||||
setcookie(session_name(),'',0,
|
|
||||||
ini_get('session.cookie_path'), ini_get('session.cookie_domain') );
|
|
||||||
redirect( make_index_url() );
|
|
||||||
}
|
|
||||||
if ($user['is_the_guest'] and !$conf['guest_access'])
|
|
||||||
{
|
|
||||||
redirect (get_root_url().'identification.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------- change of image display order
|
//---------------------------------------------- change of image display order
|
||||||
if (isset($_GET['image_order']))
|
if (isset($_GET['image_order']))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue