Login.php
6.11 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
<?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()
{
$this->setTitle('登录');
$data = array(
'loginIndex' => true,
'backUrl' => '/',
'showHeaderImg' => true,
'isPassportPage' => true,
'registerUrl' => '/reg.html',
'interationalUrl' => '/login.html',
'phoneRetriveUrl' => '',
'emailRetriveUrl' => '',
);
$this->_view->display('index', $data);
}
/**
* 国际账号登录页
*/
public function interationalAction()
{
$this->setTitle('国际账号登录');
$data = array();
$data['loginInterational'] = true;
$data['backUrl'] = '/';
$data['headerText'] = '登录';
$data['isPassportPage'] = true;
$data['countryCode'] = '+86';
// 获取地区数据列表
$area = RegData::getAreasData();
// 有数据
if (!empty($area['data'])) {
$build = array();
foreach ($area['data'] as $value) {
$build = array();
$build['areaCode'] = '+' . $value['area'];
$build['selected'] = $value['area'] === '86';
$build['name'] = $value['name'];
$data['countrys'][] = $build;
}
}
// 没数据
else {
$data['countrys'][0] = array();
$data['countrys'][0]['areaCode'] = '+86';
$data['countrys'][0]['selected'] = true;
$data['countrys'][0]['name'] = '中国';
}
$this->_view->display('interational', $data);
$data = array();
$area = array();
}
/**
* 登录操作
*
* @param string area 地区编号, 不需要+号
* @param string profile 账号(邮箱或手机号)
* @param string password 密码
* @return json
*/
public function authAction()
{
$data = array('code' => 400, 'message' => '账号或密码不正确', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断参数是否传递 */
$area = $this->post('area', '86');
$profile = $this->post('profile');
$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);
} 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()
{
header('Location:' . Factory::create('sinaweibo')->getAuthorizeUrl());
exit();
}
/**
* 支付宝账号登录:回调方法
*/
public function alipaycallbackAction()
{
$nickname = '';
$alipay = Factory::create('alipay');
$access = $alipay->getAccessToken();
if (!isset($_GET['real_name']))
{
/* 获取支付宝用户的详细信息 */
$userInfo = $alipay->getUserInfo($access);
if ($userInfo && $userInfo['is_success'] === 'T' && isset($userInfo['response']['user_info']['user_name']))
{
$nickname = $userInfo['response']['user_info']['user_name'];
$alipayEmail = $userInfo['response']['user_info']['email'];
}
var_dump($userInfo);
}
else
{
$nickname = $_GET['real_name'];
$alipayEmail = isset($_GET['email']) ? $_GET['email'] : '';
}
var_dump($access);
$result = LoginData::signinByOpenID($nickname, $access['user_id'], 'qq');
if($result['code'] == 200)
{
echo '登陆成功';
}
}
/**
* QQ账号登录:回调方法
*/
public function qqcallbackAction()
{
$qqconnect = Factory::create('qqconnect');
$access = $qqconnect->getAccessToken();
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $qqconnect->getUserInfo($access);
var_dump($access, $partnerInfo);
if ($partnerInfo && is_array($partnerInfo))
{
$result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq');
if($result['code'] == 200)
{
echo '登陆成功';
}
}
}
/**
* 新浪微博账号登录:回调方法
*/
public function sinacallbackAction()
{
$sina = Factory::create('sina');
$access = $sina->getAccessToken();
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $sina->getUserInfo($access);
var_dump($access, $partnerInfo);
if ($partnerInfo && is_array($partnerInfo))
{
$result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina');
if($result['code'] == 200)
{
echo '登陆成功';
}
}
}
}