Register.php
6.06 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
<?php
use Action\WebAction;
use LibModels\Web\Passport\RegData;
use Passport\RegModel;
use Plugin\Helpers;
use Plugin\Cache;
use Passport\PassportModel;
class RegisterController extends WebAction
{
/**
* 注册页
*/
public function indexAction()
{
$refer = $this->get('refer', SITE_MAIN);
$cover = PassportModel::getLeftBanner(PassportModel::REGISTER_LEFT_BANNER_CODE);
$data = array(
'registerPage' => true,
'passport' => array(
'actionUrl' => '/passport/register/mobileregister',
'region' => RegData::getAreasData(),
'location' => '+86',
'captchaUrl' => 'http://web.dev.yohobuy.com/passport/images?t=1449799445',
'itemUrl' => '##',
'referUrl' => $refer,
'loginUrl' => '/signin.html?refer='.$refer,
'coverHref' => $cover['url'],
'coverImg' => $cover['img']
)
);
$this->setCookie('refer', $refer);
$this->_view->display('index', $data);
}
/**
*
*/
public function checkmobileAction()
{
$mobile = trim($this->post('mobile'), ' ');
$area = intval(trim($this->post('area'), ' '));
$ip = Helpers::getClientIp();
$data = array('code' => 400, 'message' => '', 'data' => '');
$ip_key = md5('ip_checkmobile_' . $ip);
$ip_times = Cache::increment($ip_key);
do{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断参数是否合法 */
if (!is_numeric($mobile) || !is_numeric($area)) {
$data['message'] = '手机号码格式不正确';
break;
}
if ($ip_times >= 1000) {
$data['message'] = '由于你IP受限无法注册';
break;
}
if(!empty(PassportModel::getUserInfoByMobile($area, $mobile))) {
$data['message'] = '手机号码已经存在';
break;
}
$data['code'] = 200;
} while(false);
$this->echoJson($data);
}
/**
* 校验并发送验证码
*
* @return json
*/
public function piccaptchaAction()
{
$mobile = trim($this->post('mobile'), ' ');
$area = intval(trim($this->post('area'), ' '));
$verifyCode = strtolower(trim($this->post('code'),' '));
$data = array('code' => 400, 'message' => '', 'data' => '');
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断参数是否合法 */
if (!is_numeric($mobile) || !is_numeric($area)) {
$code = 400;
$data['message'] = '手机号码格式不正确';
break;
}
//检测验证码不正确
if(!PassportModel::verifyCode($verifyCode)) {
$data['message'] = '验证码不正确';
break;
}
/* 向手机发送注册验证码 */
$data = RegData::sendCodeToMobile($area, $mobile);
if (!isset($data['code'])) {
break;
}
}
while(false);
$this->echoJson($data);
}
public function msgcaptchaAction()
{
$this->echoJson(array('code'=>200));
}
/**
* 手机注册
*
*/
public function mobileregisterAction()
{
$mobile = trim($this->post('phoneNum'), ' ');//mobile
$area = intval(trim($this->post('region'), ' '));//area
$verifyCode = strtolower(trim($this->post('captcha'),' '));//captcha
$code = trim($this->post('msgCaptcha'),'');//code
$password = $this->post('pwd');
$url = '/passport/register/index';
$refer = $this->getCookie('refer');
$data = array('code' => 400, 'message' => '', 'data' => '');
if(!empty($refer)) {
$refer = $url.'?refer='.$refer;
}
do
{
/* 判断参数是否合法 */
if (!is_numeric($mobile) || !is_numeric($area)) {
$data['message'] = '手机号码格式不正确';
break;
}
//检测验证码不正确
if(!PassportModel::verifyCode($verifyCode)) {
$data['message'] = '验证码不正确';
break;
}
/* 判断密码是否符合规则 */
if (!Helpers::verifyPassword($password)) {
$data['message'] = '密码不正确';
break;
}
/* 验证注册的标识码是否有效 */
$data = RegData::validMobileCode($area, $mobile, $code);
if (!isset($data['code']) || $data['code'] != 200) {
$data['message'] = '验证码错误';
break;
}
/*手机注册*/
$data = RegData::regMobile($area, $mobile, $password);
if (!isset($data['code']) || $data['code'] != 200) {
break;
}
/* 返回跳转到来源页面 */
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN;
} else {
$refer = rawurldecode($refer);
}
// $data['data']['href'] = $refer;
// $data['data']['session'] = Helpers::syncUserSession($data['data']['uid']);
$token = Helpers::makeToken($data['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $data['data']['uid']);
//$this->setSession('session_key', $data['data']['session_key']);
}while(false);
$this->go($refer);
}
}