Register.php
11.1 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
use Action\WebAction;
use LibModels\Web\Passport\RegData;
use WebPlugin\Helpers;
use WebPlugin\Cache;
use Passport\PassportModel;
use LibModels\Web\Passport\BindData;
/**
* 注册
*/
class RegisterController extends WebAction
{
/**
* 注册页
*/
public function indexAction()
{
$this->setTitle('新用户注册', true, ' | ');
$this->setSimpleHeader();
$this->setSession('effective_time', time() + 1800);
$referUrl = $this->get('refer', '');
$referCookie = $this->getCookie('refer', '');
$refer = (!$referUrl) ? $referCookie : $referUrl;
$refer = empty($refer) ? SITE_MAIN : rawurldecode($refer);
$cover = PassportModel::getLeftBanner(PassportModel::REGISTER_LEFT_BANNER_CODE);
$data = array(
'registerPage' => true,
'passport' => array(
'actionUrl' => Helpers::url('/passport/register/mobileregister'),
'region' => RegData::getAreasData(),
'location' => '+86',
'captchaUrl' => Helpers::url('/passport/images', array('t' => time())),
'itemUrl' => Helpers::url('/help/', array('category_id' => 9)),
'referUrl' => Helpers::getUrlSafe($refer),
'loginUrl' => Helpers::url('/signin.html', array('refer' => rawurlencode($refer))),
'coverHref' => Helpers::getUrlSafe($cover['url']),
'coverImg' => Helpers::getUrlSafe($cover['img']),
'regBtnText' => '立即注册'
)
);
$this->setCookie('refer', $refer);
$this->_view->display('index', $data);
}
/**
* 注册成功页
*/
public function successAction()
{
$this->setTitle('注册成功', true, ' | ');
$this->setSimpleHeader();
$goUrl = $this->get('next', SITE_MAIN);
$goShoppingUrl = $this->get('goShoppingUrl',SITE_MAIN);
$cover = PassportModel::getLeftBanner(PassportModel::REGISTER_LEFT_BANNER_CODE);
$data = array(
'registerPage' => true,
'passport' => array(
'goUrl' => $goUrl,
'goShoppong' => $goShoppingUrl,
'coverHref' => $cover['url'],
'coverImg' => $cover['img'],
),
'uid' => $this->getUid(false),
);
$this->_view->display('success', $data);
}
/**
* 检测手机号
*
* @return json
*/
public function checkmobileAction()
{
$data = array('code' => 400, '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['message'] = '手机号码格式不正确';
break;
}
/* 判断手机号是否检查超过指定次数 */
$makeMobile = Helpers::makeMobile($area, $mobile);
$key = 'checkmobilenum_' . $makeMobile;
$checkNum = intval(Cache::get($key));
if ($checkNum > 500) {
$data['message'] = '检查次数太多';
break;
}
Cache::set($key, ++$checkNum);
/* 判断用户是否存在 */
$area = intval($area);
$user = PassportModel::getUserInfoByMobile($area, $mobile);
if (!empty($user)) {
$data['message'] = '手机号码已经存在';
break;
}
$data['code'] = 200;
$this->setSession('checkmobile_' . $makeMobile, $makeMobile);
}
while (false);
$this->echoJson($data);
}
/**
* 校验图形验证码
*
* @return json
*/
public function piccaptchaAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$verifyCode = trim($this->post('verifyCode'));
$picFlag = PassportModel::verifyCode($verifyCode);
if ($picFlag) {
$data = array('code' => 200, 'message' => '验证码正确', 'data' => '');
}
else {
$data = array('code' => 400, 'message' => '验证码错误', 'data' => '');
}
}
while (false);
$this->echoJson($data);
}
/**
* 发送短信验证码
*/
public function sendBindMsgAction()
{
$data = array('code' => 400, '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'] = 400;
$data['message'] = '手机号码格式不正确';
break;
}
//校验是否发送过多
$sendCodeKey = 'send_code_' . $area . '_' . $mobile;
$sendCodeTimes = Cache::get($sendCodeKey);
if (!$sendCodeTimes) {
$sendCodeTimes = 0;
}
else {
$sendCodeTimes = intval($sendCodeTimes);
}
if ($sendCodeTimes >= 10) {
$data['message'] = '您已多次提交验证码,请尽快联系客服解决';
break;
}
//检测验证码不正确
$verifyCode = strtolower(trim($this->post('verifyCode')));
if (!PassportModel::verifyCode($verifyCode)) {
$data['code'] = 400;
$data['message'] = '图形验证码不正确';
break;
}
//检查是否检查过
$makeMobile = Helpers::makeMobile($area, $mobile);
if ($this->getSession('checkmobile_' . $makeMobile) != $makeMobile) {
$data['code'] = 400;
$data['message'] = '发送失败';
break;
}
if ($sendCodeTimes >= 5) {
$data['message'] = '您收到的验证码短信已超过本日限定最多次数,请您耐心等待';
}
/* 向手机发送注册验证码 */
$data = RegData::sendCodeToMobile($area, $mobile);
Cache::set($sendCodeKey, $sendCodeTimes + 1, 3600);
if (!isset($data['code'])) {
break;
}
}
while (false);
$this->echoJson($data);
}
/**
* 验证短信码是否正确
*/
public function msgcaptchaAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$phoneNum = trim($this->post('mobile'));
$areaCode = trim($this->post('area'));
$code = trim($this->post('code')); //短信验证码
//校验手机号格式
if (!is_numeric($phoneNum) || !is_numeric($areaCode)) {
$data['code'] = 401;
$data['message'] = '手机号码格式不正确';
break;
}
$data = BindData::checkBindCode($areaCode, $phoneNum, $code);
if (!isset($data['code'])) {
break;
}
}
while (false);
$this->echoJson($data);
}
/**
* 手机注册
*/
public function mobileregisterAction()
{
$data = array('code' => 400, '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['message'] = '手机号码格式不正确';
break;
}
/* 判断是否是有效的注册方式,防注册机刷 */
$effectiveTime = $this->getSession('effective_time');
if ($effectiveTime < time() || empty($effectiveTime)) {
$data['message'] = '注册超时';
break;
}
//检测验证码不正确
$verifyCode = strtolower(trim($this->post('verifyCode'))); //图形验证码
if (!PassportModel::verifyCode($verifyCode)) {
$data['message'] = '验证码不正确';
break;
}
/* 判断密码是否符合规则 */
$code = trim($this->post('code')); //手机验证码
$password = $this->post('password');
if (!Helpers::verifyPassword($password)) {
$data['message'] = '密码不正确';
break;
}
/* IP仅允许点击注册500次/时 */
$ip = Helpers::getClientIp();
$ipKey = 'ip_register_' . $ip;
$ipTimes = Cache::get($ipKey);
if (!$ipTimes) {
$ipTimes = 0;
}
else {
$ipTimes = intval($ipTimes);
}
if ($ipTimes >= 500) {
$data['message'] = '由于你IP受限无法注册';
break;
}
/* 验证注册的标识码是否有效 */
$data = RegData::validMobileCode($area, $mobile, $code);
if (!isset($data['code']) || $data['code'] != 200) {
$data['message'] = '验证码错误';
break;
}
/* 手机注册: 调用注册接口,ip限制计数 */
$data = RegData::regMobile($area, $mobile, $password);
Cache::set($ipKey, $ipTimes + 1, 3600);
if (!isset($data['code']) || $data['code'] != 200) {
break;
}
/* 返回跳转到来源页面,passport跳转至首页 */
$refer = rawurldecode($this->getCookie('refer'));
$isRedirectHome = PassportModel::redirectHome($refer);
if (empty($refer) || $isRedirectHome) {
$refer = SITE_MAIN;
}
$data['code'] = 200;
$this->syncUserSession($data['data']['uid']);
$data['data']['href'] = Helpers::url('/passport/register/success', array('next' => $refer, 'goShoppingUrl' => SITE_MAIN));
}
while (false);
$this->echoJson($data);
}
}