Login.php
7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
use Action\AbstractAction;
use LibModels\Wap\Passport\LoginData;
use LibModels\Wap\Passport\RegData;
use Plugin\Helpers;
use Plugin\Partner\Factory;
/**
* 登录的控制器
*/
class LoginController extends AbstractAction
{
/**
* 登录页
*/
public function indexAction()
{
$refer = $this->get('refer');
if (!empty($refer)) {
$this->setCookie('refer', $refer);
}
$this->setTitle('登录');
$data = array(
'loginIndex' => true, // 模板中使用JS的标识
'backUrl' => '/', // 返回的URL链接
'showHeaderImg' => true, // 控制显示头部图片
'isPassportPage' => true, // 模板中模块标识
'registerUrl' => '/reg.html', // 注册的URL链接
'aliLoginUrl' => '/passport/login/alipay', // 支付宝快捷登录的URL链接
'weiboLoginUrl' => '/passport/login/sina', // 微博登录的URL链接
'qqLoginUrl' => '/passport/login/qq', // 腾讯QQ登录的URL链接
'internationalUrl' => '/login.html', // 国际号登录的URL链接
'phoneRetriveUrl' => '/passport/back/mobile', // 通过手机号找回密码的URL链接
'emailRetriveUrl' => '/passport/back/email', // 通过邮箱找回密码的URL链接
);
// 渲染模板
$this->_view->display('index', $data);
}
/**
* 国际账号登录页
*/
public function internationalAction()
{
$refer = $this->get('refer');
if (!empty($refer)) {
$this->setCookie('refer', $refer);
}
$this->setTitle('国际账号登录');
$data = array();
$data['loginInternational'] = true; // 模板中使用JS的标识
$data['backUrl'] = '/'; // 返回的URL链接
$data['headerText'] = '登录'; // 头部信息
$data['isPassportPage'] = true; // 模板中模块标识
$data['areaCode'] = '+86'; // 默认区号
$data['countrys'] = RegData::getAreasData(); // 地区信息列表
// 渲染模板
$this->_view->display('international', $data);
}
/**
* 退出
*/
public function outAction()
{
// 清除客户端
$this->setCookie('_UID', '');
// 清除服务端会话
$this->setSession('_TOKEN', '');
$refer = $this->server('HTTP_REFERER', SITE_MAIN);
$token = $this->get('token');
if (!empty($token)) {
$this->go( Helpers::logoutSession($token, $refer) );
}
$this->go($refer);
}
/**
* 登录操作
*
* @param string areaCode 地区编号, 不需要+号
* @param string account 账号(邮箱或手机号)
* @param string password 密码
* @return json
*/
public function authAction()
{
$data = array('code' => 400, 'message' => '账号或密码不正确', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断参数是否传递 */
$area = $this->post('areaCode', '86');
$profile = $this->post('account');
$password = $this->post('password');
if (!is_numeric($area) || empty($profile) || empty($password)) {
break;
}
/* 判断参数是否有效 */
$verifyEmail = Helpers::verifyEmail($profile);
$verifyMobile = ($area === '86') ? Helpers::verifyMobile($profile) : Helpers::verifyAreaMobile($profile);
if (!$verifyEmail && !$verifyMobile) {
break;
}
/* 调用登录接口进行登录 */
$data = LoginData::signin($area, $profile, $password);
if ($data['code'] != 200 || !isset($data['data']['uid'])) {
break;
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
} else {
$refer = rawurldecode($refer);
}
$data['data']['session'] = Helpers::syncUserSession($data['data']['uid']);
$data['data']['href'] = $refer;
$this->setSession('_TOKEN', Helpers::makeToken($data['data']['uid']));
} while (false);
$this->echoJson($data);
}
/**
* 支付宝账号登录:授权页面
*/
public function alipayAction()
{
Factory::create('alipay')->getAuthorizeUrl();
exit();
}
/**
* QQ账号登录:授权页面
*/
public function qqAction()
{
Factory::create('qqconnect')->getAuthorizeUrl();
exit();
}
/**
* 新浪微博账号登录:授权页面
*/
public function sinaAction()
{
$this->go(Factory::create('sinaweibo')->getAuthorizeUrl());
}
/**
* 支付宝账号登录:回调方法
*/
public function alipaycallbackAction()
{
$realName = $this->_request->get('real_name');
$email = $this->_request->get('email');
$userId = $this->_request->get('user_id');
$result = array();
if (isset($realName, $email, $userId)) {
$result = LoginData::signinByOpenID($realName, $userId, 'alipay');
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
} else {
$refer = rawurldecode($refer);
}
if ($result['code'] == 200 && !empty($result['data']['uid'])) {
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
} else {
$this->go($refer);
}
}
/**
* QQ账号登录:回调方法
*/
public function qqcallbackAction()
{
$qqconnect = Factory::create('qqconnect');
$access = $qqconnect->getAccessToken();
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $qqconnect->getUserInfo($access);
$result = array();
if ($partnerInfo && is_array($partnerInfo)) {
$result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq');
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
} else {
$refer = rawurldecode($refer);
}
if ($result['code'] == 200 && !empty($result['data']['uid'])) {
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
} else {
$this->go($refer);
}
}
/**
* 新浪微博账号登录:回调方法
*/
public function sinacallbackAction()
{
$sina = Factory::create('sinaweibo');
$access = $sina->getAccessToken();
/* 获取用户的详细信息 */
$partnerInfo = $sina->getUserInfo($access);
$result = array();
if ($partnerInfo && is_array($partnerInfo)) {
$result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina');
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
} else {
$refer = rawurldecode($refer);
}
if ($result['code'] == 200 && !empty($result['data']['uid'])) {
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
} else {
$this->go($refer);
}
}
}