Account.php
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
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
<?php
namespace Home;
use LibModels\Web\Home\AccountData;
use LibModels\Web\Home\UserData;
use WebPlugin\Helpers;
/**
* 个人中心-账号安全
*/
class AccountModel
{
/**
* 账户安全首页
* @param type $uid
* @return type
*/
public static function getAccountInfo($uid)
{
$result = array(
array(
'icon' => 'ok',
'type' => '登录密码',
'tip' => '互联网帐号存在被盗风险,建议您定期更改密码以保护帐号安全。',
'red' => 'true',
'url' => Helpers::url('/home/account/userpwd'),
'isValid' => true
),
array(
'icon' => 'warning',
'type' => '邮箱验证',
'tip' => '验证后,可用于找回登录密码。',
'url' => Helpers::url('/home/account/email')
),
array(
'icon' => 'warning',
'type' => '手机验证',
'tip' => '验证后,可用于找回登录密码。',
'url' => Helpers::url('/home/account/mobile')
)
);
$res = AccountData::getVerifyInfo($uid);
if (isset($res['data']) && $res['data']) {
$data = $res['data'];
$result[1]['icon'] = ($data['emailVerify'] == 'N') ? 'warning' : 'ok';
$result[1]['tip'] = ($data['emailVerify'] == 'N') ? '验证后,可用于找回登录密码。' : '您验证的邮箱:' . substr_replace($data['email'], '****', 2, 4);
$result[1]['isValid'] = ($data['emailVerify'] == 'N') ? false : true;
$result[2]['icon'] = ($data['mobileVerify'] == 'N') ? 'warning' : 'ok';
$result[2]['isValid'] = ($data['mobileVerify'] == 'N') ? false : true;
$result[2]['tip'] = ($data['mobileVerify'] == 'N') ? '验证后,可用于找回登录密码。' : '您验证的手机:' . substr_replace($data['mobile'], '****', 3, 4);
}
return $result;
}
/**
* 校验当前输入手机号是否为本人的
* @param type $uid
* @param type $area
* @param type $mobile
* @return boolean
*/
public static function checkMobileStep1($uid, $area, $mobile)
{
$check = false;
$userInfo = UserData::getUserInfoByMobile($area, $mobile);
$userId = isset($userInfo['data']['uid']) ? $userInfo['data']['uid'] : 0;
if ($uid == $userId) {
$check = true;
}
return $check;
}
/**
* 个人中心-判断身份验证状态
* @param type $uid
* @param type $checkType
* @param type $step page步骤
* @return type
*/
public static function auditCheckStatus($uid, $checkType = 'userpwd', $step = 1)
{
$ret = array();
$res = AccountData::getVerifyInfo($uid);
if (isset($res['data']) && $res['data']) {
$data = $res['data'];
$ischeckMobile = ($data['mobileVerify'] == 'N') ? false : true;
$ischeckEmail = ($data['emailVerify'] == 'N') ? false : true;
//优先验证标识
$firstCheck = '';
if ($ischeckMobile && $ischeckEmail) {
$firstCheck = (strtotime($data['mobileVerifyTime']) <= strtotime($data['emailVerifyTime'])) ? 'mobile' : 'email';
}
$titleInfo = self::getTitles($ischeckMobile, $ischeckEmail, $checkType);
$formData = array();
$verifyType = 1;
$checkEmailFlag = false;
$checkMobileFlag = false;
if ($step == 1) {
$formData = self::getFormDataStep1($data, $ischeckMobile, $ischeckEmail, $firstCheck);
$verifyType = $formData['verifyType'];
$checkEmailFlag = $formData['checkEmailFlag'];
$checkMobileFlag = $formData['checkMobileFlag'];
unset($formData['verifyType']);
unset($formData['checkEmailFlag']);
unset($formData['checkMobileFlag']);
}
else if ($step == 2) {
$formData = self::getFormDataStep2($ischeckEmail, $ischeckMobile, $checkType);
}
$ret = array(
'ischeckMobile' => $ischeckMobile,
'ischeckEmail' => $ischeckEmail,
'email' => $data['email'],
'mobile' => $data['mobile'],
'subTitle' => $titleInfo['subTitle'],
'enTitle' => $titleInfo['enTitle'],
'pageKey' => $titleInfo['pageKey'],
'formData' => $formData,
'verifyType' => $verifyType,
'checkEmailFlag' => $checkEmailFlag,
'checkMobileFlag' => $checkMobileFlag
);
}
return $ret;
}
/**
* 获得标题文案
* @param type $ischeckMobile
* @param type $ischeckEmail
* @param type $checkType
*/
public static function getTitles($ischeckMobile, $ischeckEmail, $checkType = 'userpwd')
{
if ($checkType == 'mobile') {
$subTitle = $ischeckMobile ? '修改手机' : '验证手机';
$enTitle = $ischeckMobile ? 'CHANGE TELEPHONE' : 'VERIFICATION TELEPHONE';
$pageKey = 'mobile';
}
elseif ($checkType == 'userpwd') {
$subTitle = '修改密码';
$enTitle = 'CHANGE PASSWORD';
$pageKey = 'userpwd';
}
else {
$subTitle = $ischeckEmail ? '修改邮箱' : '验证邮箱';
$enTitle = $ischeckEmail ? 'CHANGE EMAIL' : 'VERIFICATION EMAIL';
$pageKey = 'email';
}
return array('subTitle' => $subTitle, 'enTitle' => $enTitle, 'pageKey' => $pageKey);
}
/**
* 第一部页面form结构-step1
* @param type $data 用户验证相关信息
* @param type $ischeckMobile
* @param type $ischeckEmail
* @param type $firstCheck
* @return string
*/
protected static function getFormDataStep1($data, $ischeckMobile, $ischeckEmail, $firstCheck)
{
//都没验证
$formData1 = array(
'inputTxt' => '请输入登录密码',
'key' => 'password',
'type' => 'password',
'name' => 'password'
);
//只验证手机号
$formData2 = array(
'inputTxt' => '已验证的手机号',
'isVerify' => true,
'verifyAccount' => substr_replace($data['mobile'], '****', 3, 4),
'realAccount' => $data['mobile']
);
//只验证邮箱
$formData3 = array(
'inputTxt' => '已验证邮箱',
'isVerify' => true,
'verifyAccount' => substr_replace($data['email'], '****', 2, 4),
'realAccount' => $data['email']
);
//只验证手机号
if ($ischeckMobile && !$ischeckEmail) {
$formData = $formData2;
$verifyType = 3;
$checkEmailFlag = false;
$checkMobileFlag = true;
}
//只验证邮箱
else if ($ischeckEmail && !$ischeckMobile) {
$formData = $formData3;
$verifyType = 2;
$checkEmailFlag = true;
$checkMobileFlag = false;
}
//都验证
else if ($ischeckMobile && $ischeckEmail) {
$formData = ($firstCheck == 'mobile') ? $formData2 : $formData3;
$verifyType = ($firstCheck == 'mobile') ? 3 : 2;
$checkEmailFlag = ($firstCheck == 'mobile') ? false : true;
$checkMobileFlag = ($firstCheck == 'mobile') ? true : false;
}
//没有验证
else {
$formData = $formData1;
$verifyType = 1;
$checkEmailFlag = false;
$checkMobileFlag = false;
}
return array($formData, 'verifyType' => $verifyType, 'checkEmailFlag' => $checkEmailFlag, 'checkMobileFlag' => $checkMobileFlag);
}
/**
* 第二步-formData
* @param type $ischeckEmail
* @param type $ischeckMobile
* @param type $checkType
* @return array
*/
protected static function getFormDataStep2($ischeckEmail, $ischeckMobile, $checkType)
{
switch ($checkType) {
case 'userpwd':
$formData = array(
array(
'inputTxt' => '输入新密码',
'key' => 'newPwd',
'type' => 'password',
'name' => 'newPwd'
),
array(
'inputTxt' => '确认新密码',
'key' => 'confirm_password',
'type' => 'password',
'name' => 'confirm_password'
)
);
break;
case 'email':
$formData = array(
array(
'inputTxt' => $ischeckEmail ? '新的邮箱' : '我的邮箱',
'key' => 'email',
'type' => 'text',
'name' => 'email'
)
);
break;
case 'mobile':
$formData = array(
array(
'inputTxt' => $ischeckMobile ? '输入新的手机号码' : '请输入手机号码',
'key' => 'mobilevalue',
'type' => 'text',
'name' => 'mobile'
)
);
break;
default:
$formData = array();
break;
}
return $formData;
}
/**
* 加密
* @param type $data
* @param type $key
* @return type
*/
public static function encrypt($data, $key = 'yoho520')
{
$prepCode = serialize($data);
$block = mcrypt_get_block_size('des', 'ecb');
if (($pad = $block - (strlen($prepCode) % $block)) < $block) {
$prepCode .= str_repeat(chr($pad), $pad);
}
$encrypt = mcrypt_encrypt(MCRYPT_DES, $key, $prepCode, MCRYPT_MODE_ECB);
return base64_encode($encrypt);
}
/**
* 解密
* @param type $str
* @param type $key
* @return type
*/
public static function decrypt($data, $key = 'yoho520')
{
$strCode = base64_decode($data);
$str = mcrypt_decrypt(MCRYPT_DES, $key, $strCode, MCRYPT_MODE_ECB);
$block = mcrypt_get_block_size('des', 'ecb');
$pad = ord($str[($len = strlen($str)) - 1]);
if ($pad && $pad < $block && preg_match('/' . chr($pad) . '{' . $pad . '}$/', $str)) {
$str = substr($str, 0, strlen($str) - $pad);
}
return unserialize($str);
}
}