Autouserinfo.php
11.4 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
use Action\WebAction;
use LibModels\Web\Passport\RegData;
use LibModels\Web\Passport\BindData;
use Passport\PassportModel as PassportModel;
use WebPlugin\Helpers;
use Configs\ReturnCodeConfig;
class AutouserinfoController extends WebAction
{
/**
* 第三方登录完善个人信息(旧)
* 绑定手机号
*/
public function indexAction()
{
$this->setTitle('联合登录补全信息');
$this->setSimpleHeader();
// $nickname = $this->get('nickname');
$openId = trim($this->get('openId'));
$sourceType = trim($this->get('sourceType'));
//登录后跳转页面
$refer = rawurldecode($this->getCookie('refer'));
$isRedirectHome = PassportModel::redirectHome($refer);
if (empty($refer) || $isRedirectHome) {
$refer = SITE_MAIN;
}
$cover = PassportModel::getLeftBanner(PassportModel::AUTOUSERINFO_LEFT_BANNER_CODE);
//整合
$data = array(
'thirdPage' => true,
'passport' => array(
'actionUrl' => Helpers::url('/passport/autouserinfo/bind'),
'region' => RegData::getAreasData(),
'location' => '+86',
'captchaUrl' => Helpers::url('/passport/images?t=' . time()),
'itemUrl' => Helpers::url('/help/?category_id=9'),
'referUrl' => $refer,
'skipUrl' => SITE_MAIN,
'coverHref' => $cover['url'],
'coverImg' => !empty($cover['img']) ? $cover['img'] : 'http://img12.static.yhbimg.com/yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190',
'regBtnText' => '完善信息',
'openId' => $openId,
'sourceType' => $sourceType
)
);
$this->_view->display('index', $data);
}
/**
* 完善信息页面(邮箱登录,手机绑定流程中间页)
*/
public function userInfoAction()
{
$cover = PassportModel::getLeftBanner(PassportModel::AUTOUSERINFO_LEFT_BANNER_CODE);
//整合
$data = array(
'passport' => array(
'coverHref' => $cover['url'],
'coverImg' => !empty($cover['img']) ? $cover['img'] : 'http://img12.static.yhbimg.com/yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190',
'goShoppingUrl' => SITE_MAIN,
'completeInfoUrl' => Helpers::url('/passport/emailbind/index'),
),
);
$this->setSimpleHeader();
$this->_view->display('userinfo', $data);
}
/**
* 绑定前手机号校验
* 若已注册,则查询用户头像,昵称信息
*
*/
public function bindCheckAction()
{
$data = array('code' => ReturnCodeConfig::INITERROR_CODE, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$mobile = trim($this->post('mobile'));
$openId = trim($this->post('openId'));
$area = trim($this->post('area', '86'));
$sourceType = trim($this->post('sourceType'));
if (!is_numeric($mobile) || !$openId || !$area || !$sourceType) {
break;
}
$res = BindData::bindCheck($mobile, $openId, $sourceType, $area);
if (!isset($res['code'])) {
break;
}
//绑定流程:code=200 未注册,可绑定
if ($res['code'] == 200 && $res['data']['is_register'] == 0) {
$next = Helpers::url('/passport/thirdlogin/noregist');
$data = array('code' => ReturnCodeConfig::SUCCESS_CODE, 'message' => $res['message'], 'data' => array('next' => $next));
}
//绑定流程:code=201 已注册 绑定过其他第三方
elseif ($res['code'] == 200 && $res['data']['is_register'] == 1) {
$user = PassportModel::getUserInfo($area, $mobile);
$data = array('code' => ReturnCodeConfig::BIND_CODE, 'message' => $res['message'], 'data' => array('user' => $user));
}
//关联流程
elseif ($res['code'] == 200 && $res['data']['is_register'] == 3) {
$next = Helpers::url('/passport/thirdlogin/relate');
$data = array('code' => ReturnCodeConfig::RELATE_CODE, 'message' => $res['message'], 'data' => array('next' => $next));
}
//异常 505 506首次登录且手机号无法绑定 弹出更换手机号的弹窗
elseif ($res['code'] == 506 || $res['code'] == 505) {
$user = PassportModel::getUserInfo($area, $mobile);
$data = array('code' => ReturnCodeConfig::BINDERROR_CODE, 'message' => $res['message'], 'data' => array('user'=>$user));
}
//异常情况 505 506 提示message
else {
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => isset($res['data']) ? $res['data'] : '');
}
}
while (false);
$this->echoJson($data);
}
/**
* 发送验证码
*/
public function sendBindMsgAction()
{
$data = array('code' => ReturnCodeConfig::INITERROR_CODE, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$mobile = trim($this->post('mobile'));
$area = trim($this->post('area'));
//校验手机号格式
if (!is_numeric($mobile) || !is_numeric($area)) {
$data['code'] = ReturnCodeConfig::PARAMERROR_CODE;
$data['message'] = '手机号码格式不正确';
break;
}
$data = BindData::sendBindMsg($area, $mobile);
if (!isset($data['code'])) {
break;
}
}
while (false);
$this->echoJson($data);
}
/**
* 校验短信验证码
*/
public function checkBindMsgAction()
{
$data = array('code' => ReturnCodeConfig::INITERROR_CODE, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$mobile = trim($this->post('mobile'));
$area = trim($this->post('area'));
$code = trim($this->post('code')); //短信验证码
//校验手机号格式
if (!is_numeric($mobile) || !is_numeric($area)) {
$data['code'] = ReturnCodeConfig::PARAMERROR_CODE;
$data['message'] = '手机号码格式不正确';
break;
}
$data = BindData::checkBindCode($area, $mobile, $code);
if (!isset($data['code'])) {
break;
}
}
while (false);
$this->echoJson($data);
}
/**
* 绑定手机号
*/
public function bindMobileAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$mobile = trim($this->post('mobile'));
$area = trim($this->post('area', '86'));
$openId = trim($this->post('openId'));
$sourceType = trim($this->post('sourceType'));
$code = trim($this->post('code')); //短信验证码
$password = trim($this->post('password'));
$password = empty($password) ? '' : $password;
//校验手机号格式
if (!is_numeric($mobile) || !is_numeric($area)) {
$data['code'] = ReturnCodeConfig::PARAMERROR_CODE;
$data['message'] = '手机号码格式不正确';
break;
}
//校验手机验证码
$bindMsgFlag = BindData::checkBindCode($area, $mobile, $code);
if (isset($bindMsgFlag['code']) && $bindMsgFlag['code'] != 200) {
$data['code'] = ReturnCodeConfig::SMSERROR_CODE;
$data['message'] = '短信验证码不正确';
break;
}
//绑定手机号
$res = BindData::bindMobile($openId, $sourceType, $mobile, $area, $password);
if (!isset($res['code'])) {
break;
}
//绑定成功,跳转页面
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
$this->syncUserSession($res['data']['uid']);
$refer = Helpers::url('/passport/thirdlogin/bindsuccess', array('sourceType' => $sourceType . '_bind'));
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
}
else {
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => ''));
}
}
while (false);
$this->echoJson($data);
}
/**
* 关联手机号
*/
public function relateMobileAction()
{
$data = array('code' => ReturnCodeConfig::INITERROR_CODE, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$mobile = trim($this->post('mobile'));
$area = trim($this->post('area', '86'));
$openId = trim($this->post('openId'));
$sourceType = trim($this->post('sourceType'));
$code = trim($this->post('code')); //短信验证码
//校验手机号格式
if (!is_numeric($mobile) || !is_numeric($area)) {
$data['code'] = ReturnCodeConfig::PARAMERROR_CODE;
$data['message'] = '手机号码格式不正确';
break;
}
//校验手机验证码
$relateMsgFlag = BindData::checkBindCode($area, $mobile, $code);
if (isset($relateMsgFlag['code']) && $relateMsgFlag['code'] != 200) {
$data['code'] = ReturnCodeConfig::SMSERROR_CODE;
$data['message'] = '短信验证码不正确';
break;
}
//关联手机号
$res = BindData::relateMobile($openId, $sourceType, $mobile, $area);
if (!isset($res['code'])) {
break;
}
//绑定成功,跳转页面
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
$this->syncUserSession($res['data']['uid']);
$refer = Helpers::url('/passport/thirdlogin/bindsuccess', array('sourceType' => $sourceType . '_relate'));
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
}
else {
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => ''));
}
}
while (false);
$this->echoJson($data);
}
}