1、用户登录
app fontend.base.php 中login方法
$user_id = $ms->user->auth($user_name, $password);
$this->_do_login($user_id);
/* 同步登陆外部系统 */
$synlogin = $ms->user->synlogin($user_id);
function _do_login($user_id)
{
$mod_user = &m('member');
$user_info = $mod_user->get(array(
'conditions' => "member.user_id = '{$user_id}'",
'join' => 'has_store,has_rencai', // 关联查找看看是否有店铺
'fields' => 'member.user_id, user_name, reg_time, last_login, last_ip, store_id,rencai_id, dengji'
));
/* 店铺ID */
$my_store = empty($user_info ['store_id']) ? 0 : $user_info ['store_id'];
/* 保证基础数据整洁 */
// unset($user_info['store_id']);
/* 分派身份 */
$this->visitor->assign($user_info);
/* 更新用户登录信息 */
$mod_user->edit("user_id = '{$user_id}'", "last_login = '" . gmtime() . "', last_ip = '" . real_ip() . "', logins = logins + 1");
/* 更新购物车中的数据 */
$mod_cart = &m('cart');
$mod_cart->edit("(user_id = '{$user_id}' OR session_id = '" . SESS_ID . "') AND store_id <> '{$my_store}'", array(
'user_id' => $user_id,
'session_id' => SESS_ID
));
/* 去掉重复的项 */
$cart_items = $mod_cart->find(array(
'conditions' => "user_id='{$user_id}' GROUP BY spec_id",
'fields' => 'COUNT(spec_id) as spec_count, spec_id, rec_id'
));
if (!empty($cart_items)) {
foreach ($cart_items as $rec_id => $cart_item) {
if ($cart_item ['spec_count'] > 1) {
$mod_cart->drop("user_id='{$user_id}' AND spec_id='{$cart_item['spec_id']}' AND rec_id <> {$cart_item['rec_id']}");
}
}
}
}
2、执行 includes 中passports中uc.passport.php
function auth($user_name, $password)
{
register_shutdown_function('restore_error_handler'); // 恢复PHP系统默认的错误处理
$result = outer_call('uc_user_login', array($user_name, $password));
if ($result[0] < 0)
{
switch ($result[0])
{
case -1:
$this->_error('no_such_user');
break;
case -2:
$this->_error('password_error');
break;
case -3:
$this->_error('answer_error');
break;
default:
$this->_error('unknow_error');
break;
}
return false;
}
/* 同步到本地 */
$this->_local_sync($result[0], $result[1], $result[3]);
/* 返回用户ID */
return $result[0];
}
function synlogin($user_id)
{
return outer_call('uc_user_synlogin', array($user_id));
}
3、同步登陆代码:
加在了frontend.base.php中
if($_GET['act']=="logout"||$_GET['act']=="synlogout"){
setcookie("Example_auth","",time()-1);
}
if(!empty($_COOKIE['Example_auth'])&&$_SESSION['user_info']["user_id"]=="") {
list($Example_uid, $Example_username) = explode("\t", uc_authcode($_COOKIE['Example_auth'], 'DECODE'));
$mod_user =& m('member');
$user_info = $mod_user->get(array(
'conditions' => $Example_uid,
'join' => 'manage_mall',
'fields' => 'this.user_id, user_name, reg_time, last_login, last_ip, privs'
));
$_SESSION['user_info']= $user_info;
echo "<script>location.reload();</script>";
}