Authored by 王水玲

Merge branch 'develop/wap' of http://git.dev.yoho.cn/web/yohobuy into develop/wap

... ... @@ -17,6 +17,7 @@ use Yaf\Dispatcher;
use Plugin\Cache;
use Plugin\Helpers;
use Hood\Session;
use LibModels\Wap\Passport\LoginData;
class AbstractAction extends Controller_Abstract
{
... ... @@ -317,6 +318,22 @@ class AbstractAction extends Controller_Abstract
}
}
/**
* 登录完成后置cookie-_UID,session
*/
protected function syncUserSession($uid)
{
$userInfo = LoginData::profile($uid);
$token = Helpers::makeToken($uid);
if (isset($userInfo['data']) && $userInfo['data']) {
$uidCookie = $userInfo['data']['profile_name'] . '::' . $userInfo['data']['uid'] . '::' . $userInfo['data']['vip_info']['title'] . '::' . $token;
$this->setCookie('_UID', $uidCookie);
}
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $uid);
$this->setCookie('_TOKEN', $token);
}
/**
* 获取当前登录的用户ID
*
... ...
... ... @@ -804,70 +804,6 @@ class Helpers
}
/**
* 同步用户的会话
*
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
*
* @param int $uid 用户ID
* @param string $refer 访问来源
* @param string $callback 回调方法名
* @return string
*/
public static function syncUserSession($uid, $refer = '', $callback = 'call')
{
$url = '';
switch (APPLICATION_ENV) {
case 'production':
$url = 'https://login.m.yohobuy.com'; //$url = 'http://mapi.yohobuy.com';
break;
case 'preview':
$url = 'https://login.m.yohobuy.com';
break;
case 'testing':
$url = 'http://m1.yohobuy.com';
break;
default:
$url = 'http://m1.yohobuy.com';
break;
}
$url .= '/Passport/session/index?callback=' . $callback . '&sign=' . md5(md5($uid . 'Js8Yn0!EwPM45-ws')) . '&uid=' . $uid . '&go=' . $refer;
return $url;
}
/**
* 退出清除用户的会话
*
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
*
* @param int $token 用户ID
* @param string $refer 访问来源
* @param string $callback 回调方法名
* @return string
*/
public static function logoutSession($token, $refer = '', $callback = 'call')
{
$url = '';
switch (APPLICATION_ENV) {
case 'production':
$url = 'http://mapi.yohobuy.com';
break;
case 'preview':
$url = 'http://mapi.yohobuy.com';
break;
case 'testing':
$url = 'http://m1.yohobuy.com';
break;
default:
$url = 'http://m1.yohobuy.com';
break;
}
$url .= '/Passport/session/logout?callback=' . $callback . '&sign=' . md5(md5('Js8Yn0!EwPM45-ws')) . '&token=' . $token . '&go=' . $refer;
return $url;
}
/**
* 根据skc获取商品链接
* @param unknown $productSkc
* @return string
... ...
... ... @@ -162,7 +162,7 @@ function reMarginFooter(fixedElement) {
$op.prepend(
'<span>Hi,</span>' +
'<a class="user-name" href="http://m.yohobuy.com/home?tmp=' + Math.random() + '">' + user[0] + '</a>' +
'<a href="http://m.yohobuy.com/passport/signout/index?token=' + user[3] + '">退出</a>'
'<a href="http://m.yohobuy.com/passport/signout/index">退出</a>'
);
}
... ...
... ... @@ -254,11 +254,7 @@ class BindController extends AbstractAction
$refer = empty($refer) ? rawurldecode(Helpers::url('', array(), 'default')) : rawurldecode($refer);
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
$token = Helpers::makeToken($res['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $res['data']['uid']);
$this->setCookie('_TOKEN', $token);
$refer = Helpers::syncUserSession($res['data']['uid'], $refer);
$this->syncUserSession($res['data']['uid']);
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
}
else {
... ... @@ -305,13 +301,9 @@ class BindController extends AbstractAction
}
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
$token = Helpers::makeToken($res['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $res['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->syncUserSession($res['data']['uid']);
$successUrl = Helpers::url('/passport/bind/success', array('sourceType' => $sourceType));
$refer = Helpers::syncUserSession($res['data']['uid'], $successUrl);
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $successUrl));
}
else {
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => '');
... ...
... ... @@ -91,11 +91,6 @@ class LoginController extends AbstractAction
$this->setCookie('_SPK', '');
$refer = $this->server('HTTP_REFERER', SITE_MAIN);
$token = $this->get('token');
if (!empty($token)) {
$this->go(Helpers::logoutSession($token, $refer));
}
$this->go($refer);
}
... ... @@ -155,13 +150,9 @@ class LoginController extends AbstractAction
else {
$refer = rawurldecode($refer);
}
$data['data']['session'] = Helpers::syncUserSession($data['data']['uid']);
$this->syncUserSession($data['data']['uid']);
$data['data']['session'] = $refer;
$data['data']['href'] = $refer;
$token = Helpers::makeToken($data['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $data['data']['uid']);
}
while (false);
... ... @@ -231,15 +222,9 @@ class LoginController extends AbstractAction
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
}
else {
$this->go($refer);
$this->syncUserSession($result['data']['uid']);
}
$this->go($refer);
}
/**
... ... @@ -271,15 +256,9 @@ class LoginController extends AbstractAction
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
}
else {
$this->go($refer);
$this->syncUserSession($result['data']['uid']);
}
$this->go($refer);
}
/**
... ...
... ... @@ -294,13 +294,9 @@ class RegController extends AbstractAction
} else {
$refer = rawurldecode($refer);
}
$data['data']['session'] = Helpers::syncUserSession($data['data']['uid']);
$this->syncUserSession($data['data']['uid']);
$data['data']['session'] = $refer;
$data['data']['href'] = $refer;
$token = Helpers::makeToken($data['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $data['data']['uid']);
} while (false);
$this->echoJson($data);
... ...