Authored by Rock Zhang

修改第三方登录有关

@@ -96,7 +96,7 @@ class AbstractAction extends Controller_Abstract @@ -96,7 +96,7 @@ class AbstractAction extends Controller_Abstract
96 { 96 {
97 $json = json_encode($json); 97 $json = json_encode($json);
98 } 98 }
99 - 99 +
100 echo $json; 100 echo $json;
101 } 101 }
102 102
@@ -137,4 +137,30 @@ class AbstractAction extends Controller_Abstract @@ -137,4 +137,30 @@ class AbstractAction extends Controller_Abstract
137 exit; 137 exit;
138 } 138 }
139 139
  140 + /**
  141 + * 设置Cookie
  142 + *
  143 + * @param string $name cookie的名字
  144 + * @param string $value cookie的值
  145 + * @param integer $expire cookie过期时间
  146 + * @param integer $path cookie可用的路径
  147 + * @param string $domain cookie可用域名
  148 + */
  149 + protected function setCookie($name, $value, $expire = 0, $path = '/',$domain = 'yohobuy.com')
  150 + {
  151 + setcookie('alipay_redirect', $value, $expire, $path, $domain);
  152 + }
  153 +
  154 + /**
  155 + * 返回Cookie变量
  156 + *
  157 + * @param string $name cookie名称
  158 + * @param string $default 未获取到返回的默认值
  159 + * @return string 获取到的cookie值
  160 + */
  161 + protected function getCookie($name, $default = '')
  162 + {
  163 + return $this->request->getCookie($name, $default);
  164 + }
  165 +
140 } 166 }
@@ -50,6 +50,11 @@ class LoginController extends AbstractAction @@ -50,6 +50,11 @@ class LoginController extends AbstractAction
50 */ 50 */
51 public function alipayAction() 51 public function alipayAction()
52 { 52 {
  53 + $redirect = $this->_request->getServer('HTTP_REFERER', '');
  54 + if($redirect != '')
  55 + {
  56 + $this->setCookie('alipay_redirect', $redirect);
  57 + }
53 Factory::create('alipay')->getAuthorizeUrl(); 58 Factory::create('alipay')->getAuthorizeUrl();
54 59
55 exit(); 60 exit();
@@ -61,6 +66,11 @@ class LoginController extends AbstractAction @@ -61,6 +66,11 @@ class LoginController extends AbstractAction
61 */ 66 */
62 public function qqAction() 67 public function qqAction()
63 { 68 {
  69 + $redirect = $this->_request->getServer('HTTP_REFERER', '');
  70 + if($redirect != '')
  71 + {
  72 + $this->setCookie('qq_redirect', $redirect);
  73 + }
64 Factory::create('qqconnect')->getAuthorizeUrl(); 74 Factory::create('qqconnect')->getAuthorizeUrl();
65 75
66 exit(); 76 exit();
@@ -72,6 +82,11 @@ class LoginController extends AbstractAction @@ -72,6 +82,11 @@ class LoginController extends AbstractAction
72 */ 82 */
73 public function sinaAction() 83 public function sinaAction()
74 { 84 {
  85 + $redirect = $this->_request->getServer('HTTP_REFERER', '');
  86 + if($redirect != '')
  87 + {
  88 + $this->setCookie('sina_redirect', $redirect);
  89 + }
75 header('Location:' . Factory::create('sinaweibo')->getAuthorizeUrl()); 90 header('Location:' . Factory::create('sinaweibo')->getAuthorizeUrl());
76 91
77 exit(); 92 exit();
@@ -108,8 +123,11 @@ class LoginController extends AbstractAction @@ -108,8 +123,11 @@ class LoginController extends AbstractAction
108 123
109 if($result['code'] == 200) 124 if($result['code'] == 200)
110 { 125 {
111 - echo '登陆成功'; 126 + $redirect = $this->_request->getCookie('alipay_redirect');
  127 + $redirect && $this->redirect($redirect);
112 } 128 }
  129 +
  130 + $this->redirect('/');
113 } 131 }
114 132
115 /** 133 /**
@@ -121,7 +139,6 @@ class LoginController extends AbstractAction @@ -121,7 +139,6 @@ class LoginController extends AbstractAction
121 $access = $qqconnect->getAccessToken(); 139 $access = $qqconnect->getAccessToken();
122 /* 获取QQ腾讯用户的详细信息 */ 140 /* 获取QQ腾讯用户的详细信息 */
123 $partnerInfo = $qqconnect->getUserInfo($access); 141 $partnerInfo = $qqconnect->getUserInfo($access);
124 - var_dump($access, $partnerInfo);  
125 142
126 if ($partnerInfo && is_array($partnerInfo)) 143 if ($partnerInfo && is_array($partnerInfo))
127 { 144 {
@@ -129,9 +146,12 @@ class LoginController extends AbstractAction @@ -129,9 +146,12 @@ class LoginController extends AbstractAction
129 146
130 if($result['code'] == 200) 147 if($result['code'] == 200)
131 { 148 {
132 - echo '登陆成功'; 149 + $redirect = $this->_request->getCookie('qq_redirect');
  150 + $redirect && $this->redirect($redirect);
133 } 151 }
134 - } 152 + }
  153 +
  154 + $this->redirect('/');
135 } 155 }
136 156
137 /** 157 /**
@@ -143,7 +163,6 @@ class LoginController extends AbstractAction @@ -143,7 +163,6 @@ class LoginController extends AbstractAction
143 $access = $sina->getAccessToken(); 163 $access = $sina->getAccessToken();
144 /* 获取QQ腾讯用户的详细信息 */ 164 /* 获取QQ腾讯用户的详细信息 */
145 $partnerInfo = $sina->getUserInfo($access); 165 $partnerInfo = $sina->getUserInfo($access);
146 - var_dump($access, $partnerInfo);  
147 166
148 if ($partnerInfo && is_array($partnerInfo)) 167 if ($partnerInfo && is_array($partnerInfo))
149 { 168 {
@@ -151,8 +170,11 @@ class LoginController extends AbstractAction @@ -151,8 +170,11 @@ class LoginController extends AbstractAction
151 170
152 if($result['code'] == 200) 171 if($result['code'] == 200)
153 { 172 {
154 - echo '登陆成功'; 173 + $redirect = $this->_request->getCookie('sina_redirect');
  174 + $redirect && $this->redirect($redirect);
155 } 175 }
156 - } 176 + }
  177 +
  178 + $this->redirect('/');
157 } 179 }
158 } 180 }