Back.php
10.9 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
<?php
use Action\WebAction;
use LibModels\Web\Passport\RegData;
use Passport\PassportModel;
use WebPlugin\Helpers;
use LibModels\Web\Passport\BackData;
use WebPlugin\AuthCode;
class BackController extends WebAction {
/**
* 找回密码
*/
public function indexAction() {
$banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);
$data = array (
'simpleHeader' => PassportModel::getSimpleHeader(false),
'backPage' => true,
'back' => array (
'coverHref' => $banner ['url'],
'coverImg' => $banner ['img'],
'countryCode' => '86',
'countryName' => '中国',
'captchaUrl' => SITE_MAIN.'/passport/images?t=1449799445',
'countryList' => RegData::getAreasData()
)
);
$this->_view->display ( 'index', $data );
}
/**
* 校验验证码
*/
public function authcodeAction()
{
$phoneNum = $this->post('phoneNum', '');
$area = intval($this->post('area', '86'));
$verifyCode = $this->post('verifyCode', '');//图形验证码
$data = array(
'code' => 200,
'message' => '验证成功'
);
if (PassportModel::verifyCode($verifyCode)) {
if (Helpers::verifyEmail($phoneNum)) {
$ret = PassportModel::getUserInfoByEmail($phoneNum);
if (empty($ret)) {
$data['message'] = '该邮件账户不存在';
$data['code'] = 401;
}
} else if (Helpers::verifyMobile($phoneNum)) {
$ret = PassportModel::getUserInfoByMobile($area, $phoneNum);
if (empty($ret)) {
$data['message'] = '该手机号不存在';
$data['code'] = 402;
}
}
} else {
$data['message'] = '验证失败';
$data['code'] = 400;
}
echo $this->echoJson($data);
}
/**
* 邮箱
*/
public function emailAction() {
$phoneNum = $this->post ('phoneNum', '');
$area = intval ($this->post('area', '86'));
$verifyCode = $this->post('verifyCode', '');//图形验证码
if (Helpers::verifyEmail($phoneNum)) { // 验证邮箱
$email = $phoneNum;
$data = BackData::sendCodeToEmail($email);
if ($data ['code'] == 200) {
$this->setSession('email', $email);
$this->redirect ('sendemail');
} else {
$this->redirect ('index');
}
} else if (Helpers::verifyMobile($phoneNum)) { // 验证手机号
$mobile = $phoneNum;
$data = BackData::sendCodeToMobile($mobile, $area);
if ($data['code'] == 200) {
$this->setSession ('mobile', $mobile );
$this->setSession ('area', $area );
$this->setSession ('verifyCode', $verifyCode );
$this->redirect ('verification');
} else {
$this->redirect ('index');
}
}
}
/**
* 发送找回手机号短信
*
* @return json
*/
public function sendbackmobileAction()
{
$mobile = $this->post ('mobile', '');
$area = intval ($this->post( 'area', '86' ));
$verifyCode = $this->post ('verifyCode', '');//图形验证码
$data = array('code' => 400, 'message' =>'验证失败');
if(Helpers::verifyMobile($mobile) && PassportModel::verifyCode($verifyCode)) { // 验证手机号
$data = BackData::sendCodeToMobile($mobile, $area);
}
echo $this->echoJson($data);
}
/**
* 发送邮件页面
*/
public function sendemailAction() {
$email = $this->getSession ('email');
if (empty ( $email )) {
$this->redirect ('index');
}
$banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);
$emailArr = explode('@', $email);
$emailUrl = '';//邮箱地址
$emailUrls = array('yoho.cn' =>'http://smail.yoho.cn');
if(in_array($emailArr[1], $emailUrls)){
$emailUrl = $emailUrls[$emailArr[1]];//邮箱后缀
} else {
$emailUrl = 'http://mail.'.$emailArr[1];
}
$data = array (
'simpleHeader' => PassportModel::getSimpleHeader(false),
'sendEmail' => array (
'coverHref' => $banner ['url'],
'coverImg' => $banner ['img'],
'countrys' => array (),
'email' => $emailUrl
)
);
$this->_view->display('send-email', $data);
}
/**
* 重置密码页面
*/
public function backcodeAction()
{
$code = $this->get('code');//加密code兼容以前参数
$info = $this->checkCode($code);
$verifyState = false;//验证状态
$ret = array();
if (!empty ( $info )) {
$verifyState = true;
if(isset($info['uid'])) { //老版修改邮箱密码
$verifyState = false;//重新找回密码
}
} else {
$ret = BackData::checkEmailCode($code);
if(isset($ret['data']) && $ret['code'] == 200) {
$verifyState = true;
}
}
//验证失败
if(!$verifyState)
{
$this->redirect ('index');
}
$banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);
$data = array (
'simpleHeader' => PassportModel::getSimpleHeader(false),
'resetPage' => true,
'resetPwd' => array (
'coverHref' => $banner ['url'],
'coverImg' => $banner ['img'],
'countrys' => array(),
'code' => $code
)
);
$this->_view->display('reset-pwd', $data);
}
/**
* 更新密码接口
*/
public function updateAction()
{
$code = $this->post('code');//加密code兼容以前参数
$password = $this->post('pwd');
$info = $this->checkCode($code);
if (Helpers::verifyPassword ($password)) {
if(!empty($info)) { //手机号找回
// 修改密码
if (isset ( $info ['mobile'] )) { // 手机号修改密码
$mobile = $info ['mobile'];
$token = $info ['token'];
$area = $info ['area'];
$data = BackData::modifyPasswordByMobile($mobile, $token, $password, $area);
if ($data ['code'] == 200) {
$this->redirect ( 'resetSuccess' );
}
} else if (isset ($info ['uid'])) { //其他方式修改密码,跳到找回密码首页
$this->redirect ( '/index' );
}
} else { //新版邮箱修改接口
$data = BackData::modifyPasswordByEmailCode($code, $password);
if ($data ['code'] == 200) {
$this->redirect ( 'resetSuccess' );
}
}
}
// 跳转错误页面
$this->redirect('/index');
}
/**
* 重置密码成功
*/
public function resetSuccessAction()
{
$banner = PassportModel::getLeftBanner ( PassportModel::BACK_LFFT_BANNER_CODE );
$data = array (
'simpleHeader' => PassportModel::getSimpleHeader ( false ),
'resetSuccess' => array (
'coverHref' => $banner ['url'],
'coverImg' => $banner ['img'],
'countrys' => array ()
)
);
$this->_view->display ( 'reset-success', $data );
}
/**
* 手机验证页面
*/
public function verificationAction()
{
$mobile = $this->getSession ('mobile');
$area = $this->getSession ('area');
$verifyCode = $this->getSession ('verifyCode');//图形验证码
if (empty ($mobile)) {
$this->redirect ('index');
}
$banner = PassportModel::getLeftBanner (PassportModel::BACK_LFFT_BANNER_CODE);
$data = array (
'simpleHeader' => PassportModel::getSimpleHeader ( false ),
'vertificationPage' => true,
'verification' => array (
'coverHref' => $banner ['url'],
'coverImg' => $banner ['img'],
'mobile' => $mobile,
'area' => $area,
'verifyCode' => $verifyCode,
'countrys' => array ()
)
);
$this->_view->display ('verification', $data);
}
/**
* 手机找回密码验证
*/
public function backmobileAction()
{
$mobile = $this->post ( 'mobile' );
$area = $this->post ( 'area' );
$verifyCode = $this->post ( 'verifyCode' );//图形验证码
$code = $this->post ( 'code' ); //手机验证码
$data = array('code'=> 400, 'message' => '验证码错误!','data' => SITE_MAIN.'/passport/back/index');
if ($this->getSession ( 'mobile' ) == $mobile && $this->getSession ( 'area' ) == $area && ! empty($code)) {
$result = BackData::validateMobileCode ( $mobile, $code, $area );
if ($result ['code'] == 200) {
$str = json_encode ( array (
'mobile' => $mobile,
'area' => $area,
'token' => $result ['data'] ['token'],
'create_time' => time ()
) );
$code = AuthCode::encode ( $str, PassportModel::BACK_FIND_SECRET_KEY );
$url = '/passport/back/backcode?code=' . base64_encode ( $code );
$data ['code'] = 200;
$data['message'] = '验证成功';
$data['data'] = SITE_MAIN . $url;
}
}
$this->echoJson($data);
}
/**
* 检查code
*
* @param string $code
* @return boolean
*/
private function checkCode($code)
{
$code = base64_decode ( $code );
$info = json_decode ( AuthCode::decode ( $code, PassportModel::BACK_FIND_SECRET_KEY ), true );
if ($info ['create_time'] < 1 || (time () - $info ['create_time']) > 86400) {
return array ();
}
return $info;
}
}