Authored by xiaowei

同步登陆 wap4.3->develop/wap

@@ -17,6 +17,7 @@ use Yaf\Dispatcher; @@ -17,6 +17,7 @@ use Yaf\Dispatcher;
17 use Plugin\Cache; 17 use Plugin\Cache;
18 use Plugin\Helpers; 18 use Plugin\Helpers;
19 use Hood\Session; 19 use Hood\Session;
  20 +use LibModels\Wap\Passport\LoginData;
20 21
21 class AbstractAction extends Controller_Abstract 22 class AbstractAction extends Controller_Abstract
22 { 23 {
@@ -317,6 +318,22 @@ class AbstractAction extends Controller_Abstract @@ -317,6 +318,22 @@ class AbstractAction extends Controller_Abstract
317 } 318 }
318 } 319 }
319 320
  321 + /**
  322 + * 登录完成后置cookie-_UID,session
  323 + */
  324 + protected function syncUserSession($uid)
  325 + {
  326 + $userInfo = LoginData::profile($uid);
  327 + $token = Helpers::makeToken($uid);
  328 + if (isset($userInfo['data']) && $userInfo['data']) {
  329 + $uidCookie = $userInfo['data']['profile_name'] . '::' . $userInfo['data']['uid'] . '::' . $userInfo['data']['vip_info']['title'] . '::' . $token;
  330 + $this->setCookie('_UID', $uidCookie);
  331 + }
  332 + $this->setSession('_TOKEN', $token);
  333 + $this->setSession('_LOGIN_UID', $uid);
  334 + $this->setCookie('_TOKEN', $token);
  335 + }
  336 +
320 /** 337 /**
321 * 获取当前登录的用户ID 338 * 获取当前登录的用户ID
322 * 339 *
@@ -804,70 +804,6 @@ class Helpers @@ -804,70 +804,6 @@ class Helpers
804 } 804 }
805 805
806 /** 806 /**
807 - * 同步用户的会话  
808 - *  
809 - * 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION  
810 - *  
811 - * @param int $uid 用户ID  
812 - * @param string $refer 访问来源  
813 - * @param string $callback 回调方法名  
814 - * @return string  
815 - */  
816 - public static function syncUserSession($uid, $refer = '', $callback = 'call')  
817 - {  
818 - $url = '';  
819 - switch (APPLICATION_ENV) {  
820 - case 'production':  
821 - $url = 'https://login.m.yohobuy.com'; //$url = 'http://mapi.yohobuy.com';  
822 - break;  
823 - case 'preview':  
824 - $url = 'https://login.m.yohobuy.com';  
825 - break;  
826 - case 'testing':  
827 - $url = 'http://m1.yohobuy.com';  
828 - break;  
829 - default:  
830 - $url = 'http://m1.yohobuy.com';  
831 - break;  
832 - }  
833 - $url .= '/Passport/session/index?callback=' . $callback . '&sign=' . md5(md5($uid . 'Js8Yn0!EwPM45-ws')) . '&uid=' . $uid . '&go=' . $refer;  
834 -  
835 - return $url;  
836 - }  
837 -  
838 - /**  
839 - * 退出清除用户的会话  
840 - *  
841 - * 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION  
842 - *  
843 - * @param int $token 用户ID  
844 - * @param string $refer 访问来源  
845 - * @param string $callback 回调方法名  
846 - * @return string  
847 - */  
848 - public static function logoutSession($token, $refer = '', $callback = 'call')  
849 - {  
850 - $url = '';  
851 - switch (APPLICATION_ENV) {  
852 - case 'production':  
853 - $url = 'http://mapi.yohobuy.com';  
854 - break;  
855 - case 'preview':  
856 - $url = 'http://mapi.yohobuy.com';  
857 - break;  
858 - case 'testing':  
859 - $url = 'http://m1.yohobuy.com';  
860 - break;  
861 - default:  
862 - $url = 'http://m1.yohobuy.com';  
863 - break;  
864 - }  
865 - $url .= '/Passport/session/logout?callback=' . $callback . '&sign=' . md5(md5('Js8Yn0!EwPM45-ws')) . '&token=' . $token . '&go=' . $refer;  
866 -  
867 - return $url;  
868 - }  
869 -  
870 - /**  
871 * 根据skc获取商品链接 807 * 根据skc获取商品链接
872 * @param unknown $productSkc 808 * @param unknown $productSkc
873 * @return string 809 * @return string
@@ -162,7 +162,7 @@ function reMarginFooter(fixedElement) { @@ -162,7 +162,7 @@ function reMarginFooter(fixedElement) {
162 $op.prepend( 162 $op.prepend(
163 '<span>Hi,</span>' + 163 '<span>Hi,</span>' +
164 '<a class="user-name" href="http://m.yohobuy.com/home?tmp=' + Math.random() + '">' + user[0] + '</a>' + 164 '<a class="user-name" href="http://m.yohobuy.com/home?tmp=' + Math.random() + '">' + user[0] + '</a>' +
165 - '<a href="http://m.yohobuy.com/passport/signout/index?token=' + user[3] + '">退出</a>' 165 + '<a href="http://m.yohobuy.com/passport/signout/index">退出</a>'
166 ); 166 );
167 } 167 }
168 168
@@ -254,11 +254,7 @@ class BindController extends AbstractAction @@ -254,11 +254,7 @@ class BindController extends AbstractAction
254 $refer = empty($refer) ? rawurldecode(Helpers::url('', array(), 'default')) : rawurldecode($refer); 254 $refer = empty($refer) ? rawurldecode(Helpers::url('', array(), 'default')) : rawurldecode($refer);
255 255
256 if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) { 256 if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
257 - $token = Helpers::makeToken($res['data']['uid']);  
258 - $this->setSession('_TOKEN', $token);  
259 - $this->setSession('_LOGIN_UID', $res['data']['uid']);  
260 - $this->setCookie('_TOKEN', $token);  
261 - $refer = Helpers::syncUserSession($res['data']['uid'], $refer); 257 + $this->syncUserSession($res['data']['uid']);
262 $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer)); 258 $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
263 } 259 }
264 else { 260 else {
@@ -305,13 +301,9 @@ class BindController extends AbstractAction @@ -305,13 +301,9 @@ class BindController extends AbstractAction
305 } 301 }
306 302
307 if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) { 303 if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
308 - $token = Helpers::makeToken($res['data']['uid']);  
309 - $this->setSession('_TOKEN', $token);  
310 - $this->setSession('_LOGIN_UID', $res['data']['uid']);  
311 - $this->setCookie('_TOKEN', $token); 304 + $this->syncUserSession($res['data']['uid']);
312 $successUrl = Helpers::url('/passport/bind/success', array('sourceType' => $sourceType)); 305 $successUrl = Helpers::url('/passport/bind/success', array('sourceType' => $sourceType));
313 - $refer = Helpers::syncUserSession($res['data']['uid'], $successUrl);  
314 - $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer)); 306 + $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $successUrl));
315 } 307 }
316 else { 308 else {
317 $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => ''); 309 $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => '');
@@ -91,11 +91,6 @@ class LoginController extends AbstractAction @@ -91,11 +91,6 @@ class LoginController extends AbstractAction
91 $this->setCookie('_SPK', ''); 91 $this->setCookie('_SPK', '');
92 92
93 $refer = $this->server('HTTP_REFERER', SITE_MAIN); 93 $refer = $this->server('HTTP_REFERER', SITE_MAIN);
94 - $token = $this->get('token');  
95 - if (!empty($token)) {  
96 - $this->go(Helpers::logoutSession($token, $refer));  
97 - }  
98 -  
99 $this->go($refer); 94 $this->go($refer);
100 } 95 }
101 96
@@ -155,13 +150,9 @@ class LoginController extends AbstractAction @@ -155,13 +150,9 @@ class LoginController extends AbstractAction
155 else { 150 else {
156 $refer = rawurldecode($refer); 151 $refer = rawurldecode($refer);
157 } 152 }
158 - $data['data']['session'] = Helpers::syncUserSession($data['data']['uid']); 153 + $this->syncUserSession($data['data']['uid']);
  154 + $data['data']['session'] = $refer;
159 $data['data']['href'] = $refer; 155 $data['data']['href'] = $refer;
160 -  
161 - $token = Helpers::makeToken($data['data']['uid']);  
162 - $this->setCookie('_TOKEN', $token);  
163 - $this->setSession('_TOKEN', $token);  
164 - $this->setSession('_LOGIN_UID', $data['data']['uid']);  
165 } 156 }
166 while (false); 157 while (false);
167 158
@@ -231,15 +222,9 @@ class LoginController extends AbstractAction @@ -231,15 +222,9 @@ class LoginController extends AbstractAction
231 } 222 }
232 223
233 if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) { 224 if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
234 - $token = Helpers::makeToken($result['data']['uid']);  
235 - $this->setSession('_TOKEN', $token);  
236 - $this->setSession('_LOGIN_UID', $result['data']['uid']);  
237 - $this->setCookie('_TOKEN', $token);  
238 - $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));  
239 - }  
240 - else {  
241 - $this->go($refer); 225 + $this->syncUserSession($result['data']['uid']);
242 } 226 }
  227 + $this->go($refer);
243 } 228 }
244 229
245 /** 230 /**
@@ -271,15 +256,9 @@ class LoginController extends AbstractAction @@ -271,15 +256,9 @@ class LoginController extends AbstractAction
271 } 256 }
272 257
273 if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) { 258 if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
274 - $token = Helpers::makeToken($result['data']['uid']);  
275 - $this->setSession('_TOKEN', $token);  
276 - $this->setSession('_LOGIN_UID', $result['data']['uid']);  
277 - $this->setCookie('_TOKEN', $token);  
278 - $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));  
279 - }  
280 - else {  
281 - $this->go($refer); 259 + $this->syncUserSession($result['data']['uid']);
282 } 260 }
  261 + $this->go($refer);
283 } 262 }
284 263
285 /** 264 /**
@@ -294,13 +294,9 @@ class RegController extends AbstractAction @@ -294,13 +294,9 @@ class RegController extends AbstractAction
294 } else { 294 } else {
295 $refer = rawurldecode($refer); 295 $refer = rawurldecode($refer);
296 } 296 }
297 - $data['data']['session'] = Helpers::syncUserSession($data['data']['uid']); 297 + $this->syncUserSession($data['data']['uid']);
  298 + $data['data']['session'] = $refer;
298 $data['data']['href'] = $refer; 299 $data['data']['href'] = $refer;
299 -  
300 - $token = Helpers::makeToken($data['data']['uid']);  
301 - $this->setCookie('_TOKEN', $token);  
302 - $this->setSession('_TOKEN', $token);  
303 - $this->setSession('_LOGIN_UID', $data['data']['uid']);  
304 } while (false); 300 } while (false);
305 301
306 $this->echoJson($data); 302 $this->echoJson($data);