commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 注册 |
|
5 |
*/ |
|
6 |
define('IN_ECS', true); |
|
7 |
|
|
8 |
require (dirname(__FILE__) . '/includes/init.php'); |
|
9 |
|
|
10 |
/* 载入语言文件 */ |
|
11 |
require_once (ROOT_PATH . 'languages/' . $_CFG['lang'] . '/user.php'); |
|
12 |
|
|
13 |
$action = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default'; |
|
14 |
|
|
15 |
$affiliate = unserialize($GLOBALS['_CFG']['affiliate']); |
|
16 |
$smarty->assign('affiliate', $affiliate); |
|
17 |
$back_act = ''; |
|
18 |
|
|
19 |
/* 如果是显示页面,对页面进行相应赋值 */ |
|
20 |
if(true) |
|
21 |
{ |
|
22 |
assign_template(); |
|
23 |
$position = assign_ur_here(0, $_LANG['user_center']); |
|
24 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
25 |
$smarty->assign('ur_here', $position['ur_here']); |
|
26 |
$sql = "SELECT value FROM " . $ecs->table('shop_config') . " WHERE id = 419"; |
|
27 |
$row = $db->getRow($sql); |
|
28 |
$car_off = $row['value']; |
|
29 |
$smarty->assign('car_off', $car_off); |
|
30 |
/* 是否显示积分兑换 */ |
|
31 |
if(! empty($_CFG['points_rule']) && unserialize($_CFG['points_rule'])) |
|
32 |
{ |
|
33 |
$smarty->assign('show_transform_points', 1); |
|
34 |
} |
|
35 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
36 |
$smarty->assign('data_dir', DATA_DIR); // 数据目录 |
|
37 |
$smarty->assign('action', $action); |
|
38 |
$smarty->assign('lang', $_LANG); |
|
39 |
} |
|
40 |
|
|
41 |
/* 路由 */ |
|
42 |
|
|
43 |
$function_name = 'action_' . $action; |
|
44 |
|
|
45 |
if(! function_exists($function_name)) |
|
46 |
{ |
|
47 |
$function_name = "action_default"; |
|
48 |
} |
|
49 |
|
|
50 |
call_user_func($function_name); |
|
51 |
|
|
52 |
/* 路由 */ |
|
53 |
|
|
54 |
/* 发送注册邮箱验证码到邮箱 */ |
|
55 |
function action_send_email_code () |
|
56 |
{ |
|
57 |
// 获取全局变量 |
|
58 |
$user = $GLOBALS['user']; |
|
59 |
$_CFG = $GLOBALS['_CFG']; |
|
60 |
$_LANG = $GLOBALS['_LANG']; |
|
61 |
$smarty = $GLOBALS['smarty']; |
|
62 |
$db = $GLOBALS['db']; |
|
63 |
$ecs = $GLOBALS['ecs']; |
|
64 |
$user_id = $_SESSION['user_id']; |
|
65 |
|
|
66 |
/* 载入语言文件 */ |
|
67 |
require_once (ROOT_PATH . 'languages/' . $_CFG['lang'] . '/user.php'); |
|
68 |
|
|
69 |
require_once (ROOT_PATH . 'includes/lib_validate_record.php'); |
|
70 |
|
|
71 |
$email = trim($_REQUEST['email']); |
|
72 |
|
|
73 |
/* 验证码检查 */ |
|
74 |
if((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0) |
|
75 |
{ |
|
76 |
if(empty($_POST['captcha'])) |
|
77 |
{ |
|
78 |
exit($_LANG['invalid_captcha']); |
|
79 |
return; |
|
80 |
} |
|
81 |
|
|
82 |
/* 检查验证码 */ |
|
83 |
include_once ('includes/cls_captcha.php'); |
|
84 |
|
|
85 |
$captcha = new captcha(); |
|
86 |
|
|
87 |
if(! $captcha->check_word(trim($_POST['captcha']))) |
|
88 |
{ |
|
89 |
exit($_LANG['invalid_captcha']); |
|
90 |
return; |
|
91 |
} |
|
92 |
|
|
93 |
//清空验证码 |
|
94 |
unset($_SESSION[$captcha->session_word]); |
|
95 |
} |
|
96 |
|
|
97 |
if(empty($email)) |
|
98 |
{ |
|
99 |
exit("邮箱不能为空"); |
|
100 |
return; |
|
101 |
} |
|
102 |
else if(! is_email($email)) |
|
103 |
{ |
|
104 |
exit("邮箱格式不正确"); |
|
105 |
return; |
|
106 |
} |
|
107 |
else if(check_validate_record_exist($email)) |
|
108 |
{ |
|
109 |
|
|
110 |
$record = get_validate_record($email); |
|
111 |
|
|
112 |
/** |
|
113 |
* 检查是过了限制发送邮件的时间 |
|
114 |
*/ |
|
115 |
if(time() - $record['last_send_time'] < 60) |
|
116 |
{ |
|
117 |
echo ("每60秒内只能发送一次注册邮箱验证码,请稍候重试"); |
|
118 |
return; |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
require_once (ROOT_PATH . 'includes/lib_passport.php'); |
|
123 |
|
|
124 |
/* 设置验证邮件模板所需要的内容信息 */ |
|
125 |
$template = get_mail_template('reg_email_code'); |
|
126 |
// 生成邮箱验证码 |
|
127 |
$email_code = rand_number(6); |
|
128 |
|
|
129 |
$GLOBALS['smarty']->assign('email_code', $email_code); |
|
130 |
$GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']); |
|
131 |
$GLOBALS['smarty']->assign('send_date', date($GLOBALS['_CFG']['date_format'])); |
|
132 |
|
|
133 |
$content = $GLOBALS['smarty']->fetch('str:' . $template['template_content']); |
|
134 |
|
|
135 |
/* 发送激活验证邮件 */ |
|
136 |
$result = send_mail($email, $email, $template['template_subject'], $content, $template['is_html']); |
|
137 |
if($result) |
|
138 |
{ |
|
139 |
// 保存验证码到Session中 |
|
140 |
$_SESSION[VT_EMAIL_REGISTER] = $email; |
|
141 |
// 保存验证记录 |
|
142 |
save_validate_record($email, $email_code, VT_EMAIL_REGISTER, time(), time() + 30 * 60); |
|
143 |
|
|
144 |
echo 'ok'; |
|
145 |
} |
|
146 |
else |
|
147 |
{ |
|
148 |
echo '注册邮箱验证码发送失败'; |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
/* 发送注册邮箱验证码到邮箱 */ |
|
153 |
function action_send_mobile_code () |
|
154 |
{ |
|
155 |
|
|
156 |
// 获取全局变量 |
|
157 |
$user = $GLOBALS['user']; |
|
158 |
$_CFG = $GLOBALS['_CFG']; |
|
159 |
$_LANG = $GLOBALS['_LANG']; |
|
160 |
$smarty = $GLOBALS['smarty']; |
|
161 |
$db = $GLOBALS['db']; |
|
162 |
$ecs = $GLOBALS['ecs']; |
|
163 |
$user_id = $_SESSION['user_id']; |
|
164 |
|
|
165 |
/* 载入语言文件 */ |
|
166 |
require_once (ROOT_PATH . 'languages/' . $_CFG['lang'] . '/user.php'); |
|
167 |
|
|
168 |
require_once (ROOT_PATH . 'includes/lib_validate_record.php'); |
|
169 |
|
|
170 |
$mobile_phone = trim($_REQUEST['mobile_phone']); |
|
171 |
|
|
172 |
/* 验证码检查 */ |
|
173 |
if((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0) |
|
174 |
{ |
|
175 |
if(empty($_POST['captcha'])) |
|
176 |
{ |
|
177 |
exit($_LANG['invalid_captcha']); |
|
178 |
return; |
|
179 |
} |
|
180 |
|
|
181 |
/* 检查验证码 */ |
|
182 |
include_once ('includes/cls_captcha.php'); |
|
183 |
|
|
184 |
$captcha = new captcha(); |
|
185 |
|
|
186 |
if(! $captcha->check_word(trim($_POST['captcha']))) |
|
187 |
{ |
|
188 |
exit($_LANG['invalid_captcha']); |
|
189 |
return; |
|
190 |
} |
|
191 |
|
|
192 |
//清空验证码 |
|
193 |
unset($_SESSION[$captcha->session_word]); |
|
194 |
} |
|
195 |
|
|
196 |
if(empty($mobile_phone)) |
|
197 |
{ |
|
198 |
exit("手机号不能为空"); |
|
199 |
return; |
|
200 |
} |
|
201 |
else if(! is_mobile_phone($mobile_phone)) |
|
202 |
{ |
|
203 |
exit("手机号格式不正确"); |
|
204 |
return; |
|
205 |
} |
|
206 |
else if(check_validate_record_exist($mobile_phone)) |
|
207 |
{ |
|
208 |
// 获取数据库中的验证记录 |
|
209 |
$record = get_validate_record($mobile_phone); |
|
210 |
|
|
211 |
/** |
|
212 |
* 检查是过了限制发送短信的时间 |
|
213 |
*/ |
|
214 |
$last_send_time = $record['last_send_time']; |
|
215 |
$expired_time = $record['expired_time']; |
|
216 |
$create_time = $record['create_time']; |
|
217 |
$count = $record['count']; |
|
218 |
|
|
219 |
// 每天每个手机号最多发送的验证码数量 |
|
220 |
$max_sms_count = 10; |
|
221 |
// 发送最多验证码数量的限制时间,默认为24小时 |
|
222 |
$max_sms_count_time = 60 * 60 * 24; |
|
223 |
|
|
224 |
if((time() - $last_send_time) < 60) |
|
225 |
{ |
|
226 |
echo ("每60秒内只能发送一次短信验证码,请稍候重试"); |
|
227 |
return; |
|
228 |
} |
|
229 |
else if(time() - $create_time < $max_sms_count_time && $record['count'] > $max_sms_count) |
|
230 |
{ |
|
231 |
echo ("您发送验证码太过于频繁,请稍后重试!"); |
|
232 |
return; |
|
233 |
} |
|
234 |
else |
|
235 |
{ |
|
236 |
$count ++; |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
require_once (ROOT_PATH . 'includes/lib_passport.php'); |
|
241 |
|
|
242 |
// 设置为空 |
|
243 |
$_SESSION['mobile_register'] = array(); |
|
244 |
|
|
245 |
//require_once (ROOT_PATH . 'sms/sms.php'); |
|
246 |
//changed by Jarod qi 20180517 |
|
247 |
include_once('includes/cls_json.php'); |
|
248 |
require(ROOT_PATH . 'includes/lib_sms.php'); |
|
249 |
// 生成6位短信验证码 |
|
250 |
$mobile_code = rand_number(6); |
|
251 |
// 短信内容 |
|
252 |
$content = sprintf($GLOBALS['_CFG']['sms_register_tpl'],$mobile_code,$GLOBALS['_CFG']['shop_name']); |
|
253 |
|
|
254 |
/* 发送激活验证邮件 */ |
|
255 |
// $result = true; |
|
256 |
//$result = sendSMS($mobile_phone, $content); |
|
257 |
$result = sendsms($mobile_phone, $content); |
|
258 |
//$result=false; |
|
259 |
if($result) |
|
260 |
{ |
|
261 |
|
|
262 |
if(! isset($count)) |
|
263 |
{ |
|
264 |
$ext_info = array( |
|
265 |
"count" => 1 |
|
266 |
); |
|
267 |
} |
|
268 |
else |
|
269 |
{ |
|
270 |
$ext_info = array( |
|
271 |
"count" => $count |
|
272 |
); |
|
273 |
} |
|
274 |
|
|
275 |
// 保存手机号码到SESSION中 |
|
276 |
$_SESSION[VT_MOBILE_REGISTER] = $mobile_phone; |
|
277 |
// 保存验证信息 |
|
278 |
save_validate_record($mobile_phone, $mobile_code, VT_MOBILE_REGISTER, time(), time() + 30 * 60, $ext_info); |
|
279 |
echo 'ok'; |
|
280 |
} |
|
281 |
else |
|
282 |
{ |
|
283 |
echo '短信验证码发送失败'; |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* 验证邮箱是否可以注册,true-已存在,不能注册 false-不存在可以注册 |
|
289 |
*/ |
|
290 |
function action_check_email_exist () |
|
291 |
{ |
|
292 |
$_LANG = $GLOBALS['_LANG']; |
|
293 |
$_CFG = $GLOBALS['_CFG']; |
|
294 |
$smarty = $GLOBALS['smarty']; |
|
295 |
$db = $GLOBALS['db']; |
|
296 |
$ecs = $GLOBALS['ecs']; |
|
297 |
|
|
298 |
$email = empty($_POST['email']) ? '' : $_POST['email']; |
|
299 |
|
|
300 |
$user = $GLOBALS['user']; |
|
301 |
|
|
302 |
if($user->check_email($email)) |
|
303 |
{ |
|
304 |
echo 'true'; |
|
305 |
} |
|
306 |
else |
|
307 |
{ |
|
308 |
echo 'false'; |
|
309 |
} |
|
310 |
} |
|
311 |
|
|
312 |
function action_check_mobile_exist () |
|
313 |
{ |
|
314 |
$_LANG = $GLOBALS['_LANG']; |
|
315 |
$_CFG = $GLOBALS['_CFG']; |
|
316 |
$smarty = $GLOBALS['smarty']; |
|
317 |
$db = $GLOBALS['db']; |
|
318 |
$ecs = $GLOBALS['ecs']; |
|
319 |
|
|
320 |
$mobile = empty($_POST['mobile']) ? '' : $_POST['mobile']; |
|
321 |
|
|
322 |
$user = $GLOBALS['user']; |
|
323 |
|
|
324 |
if($user->check_mobile_phone($mobile)) |
|
325 |
{ |
|
326 |
echo 'true'; |
|
327 |
} |
|
328 |
else |
|
329 |
{ |
|
330 |
echo 'false'; |
|
331 |
} |
|
332 |
} |
|
333 |
|
|
334 |
/** |
|
335 |
* 显示会员注册界面 |
|
336 |
*/ |
|
337 |
function action_default () |
|
338 |
{ |
|
339 |
|
|
340 |
// 获取全局变量 |
|
341 |
$_CFG = $GLOBALS['_CFG']; |
|
342 |
$_LANG = $GLOBALS['_LANG']; |
|
343 |
$smarty = $GLOBALS['smarty']; |
|
344 |
$db = $GLOBALS['db']; |
|
345 |
$ecs = $GLOBALS['ecs']; |
|
346 |
$back_act = trim($_REQUEST['back_act']); |
|
347 |
if((! isset($back_act) || empty($back_act)) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])) |
|
348 |
{ |
|
349 |
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER']; |
|
350 |
} |
|
351 |
|
|
352 |
/* 取出注册扩展字段 */ |
|
353 |
$sql = 'SELECT * FROM ' . $ecs->table('reg_fields') . ' WHERE type < 2 AND display = 1 ORDER BY dis_order, id'; |
|
354 |
$extend_info_list = $db->getAll($sql); |
|
355 |
$smarty->assign('extend_info_list', $extend_info_list); |
|
356 |
|
|
357 |
/* 验证码相关设置 */ |
|
358 |
if((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0) |
|
359 |
{ |
|
360 |
$smarty->assign('enabled_captcha', 1); |
|
361 |
$smarty->assign('rand', mt_rand()); |
|
362 |
} |
|
363 |
|
|
364 |
/* 密码提示问题 */ |
|
365 |
$smarty->assign('passwd_questions', $_LANG['passwd_questions']); |
|
366 |
|
|
367 |
$smarty->assign('sms_register', $_CFG['sms_register']); |
|
368 |
|
|
369 |
$smarty->assign('sms_register', $_CFG['sms_register']); |
|
370 |
|
|
371 |
/* 增加是否关闭注册 */ |
|
372 |
$smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']); |
|
373 |
// 登陆注册-注册类型 |
|
374 |
$register_type = empty($_REQUEST['register_type']) ? 'mobile' : $_REQUEST['register_type']; |
|
375 |
if($register_type != 'email' && $register_type != 'mobile') |
|
376 |
{ |
|
377 |
$register_type = 'mobile'; |
|
378 |
} |
|
379 |
$smarty->assign('register_type', $register_type); |
|
380 |
$smarty->assign('back_act', $back_act); |
|
381 |
$smarty->display('user_register.dwt'); |
|
382 |
} |
|
383 |
|
|
384 |
/** |
|
385 |
* 注册会员的处理 |
|
386 |
*/ |
|
387 |
function action_register () |
|
388 |
{ |
|
389 |
|
|
390 |
// 获取全局变量 |
|
391 |
$_CFG = $GLOBALS['_CFG']; |
|
392 |
$_LANG = $GLOBALS['_LANG']; |
|
393 |
$smarty = $GLOBALS['smarty']; |
|
394 |
$db = $GLOBALS['db']; |
|
395 |
$ecs = $GLOBALS['ecs']; |
|
396 |
|
|
397 |
/* 增加是否关闭注册 */ |
|
398 |
if($_CFG['shop_reg_closed']) |
|
399 |
{ |
|
400 |
$smarty->assign('action', 'register'); |
|
401 |
$smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']); |
|
402 |
$smarty->display('user_passport.dwt'); |
|
403 |
} |
|
404 |
else |
|
405 |
{ |
|
406 |
include_once (ROOT_PATH . 'includes/lib_passport.php'); |
|
407 |
|
|
408 |
$username = isset($_POST['username']) ? trim($_POST['username']) : ''; |
|
409 |
|
|
410 |
$password = isset($_POST['password']) ? trim($_POST['password']) : ''; |
|
411 |
$email = isset($_POST['email']) ? trim($_POST['email']) : ''; |
|
412 |
$other['msn'] = isset($_POST['extend_field1']) ? $_POST['extend_field1'] : ''; |
|
413 |
$other['qq'] = isset($_POST['extend_field2']) ? $_POST['extend_field2'] : ''; |
|
414 |
$other['office_phone'] = isset($_POST['extend_field3']) ? $_POST['extend_field3'] : ''; |
|
415 |
$other['home_phone'] = isset($_POST['extend_field4']) ? $_POST['extend_field4'] : ''; |
|
416 |
//$other['mobile_phone'] = isset($_POST['extend_field5']) ? $_POST['extend_field5'] : ''; |
|
417 |
$sel_question = empty($_POST['sel_question']) ? '' : compile_str($_POST['sel_question']); |
|
418 |
$passwd_answer = isset($_POST['passwd_answer']) ? compile_str(trim($_POST['passwd_answer'])) : ''; |
|
419 |
|
|
420 |
// 注册类型:email、mobile |
|
421 |
$register_type = isset($_POST['register_type']) ? trim($_POST['register_type']) : ''; |
|
422 |
|
|
423 |
$back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : ''; |
|
424 |
|
|
425 |
if(empty($_POST['agreement'])) |
|
426 |
{ |
|
427 |
show_message($_LANG['passport_js']['agreement']); |
|
428 |
} |
|
429 |
|
|
430 |
// 注册类型不能为空 |
|
431 |
if(empty($register_type)) |
|
432 |
{ |
|
433 |
show_message($_LANG['passport_js']['msg_register_type_blank']); |
|
434 |
} |
|
435 |
|
|
436 |
// 用户名将自动生成 |
|
437 |
if(strlen($username) < 3) |
|
438 |
{ |
|
439 |
// show_message($_LANG['passport_js']['username_shorter']); |
|
440 |
} |
|
441 |
|
|
442 |
if(strlen($password) < 6) |
|
443 |
{ |
|
444 |
show_message($_LANG['passport_js']['password_shorter']); |
|
445 |
} |
|
446 |
|
|
447 |
if(strpos($password, ' ') > 0) |
|
448 |
{ |
|
449 |
show_message($_LANG['passwd_balnk']); |
|
450 |
} |
|
451 |
|
|
452 |
/** 验证码检查 只进行手机和短信验证码的检查 |
|
453 |
if((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0) |
|
454 |
{ |
|
455 |
if(empty($_POST['captcha'])) |
|
456 |
{ |
|
457 |
show_message($_LANG['invalid_captcha'], $_LANG['sign_up'], 'register.php', 'error'); |
|
458 |
} |
|
459 |
|
|
460 |
include_once ('includes/cls_captcha.php'); |
|
461 |
|
|
462 |
$captcha = new captcha(); |
|
463 |
|
|
464 |
if(! $captcha->check_word(trim($_POST['captcha']))) |
|
465 |
{ |
|
466 |
show_message($_LANG['invalid_captcha'], $_LANG['sign_up'], 'register.php', 'error'); |
|
467 |
} |
|
468 |
} |
|
469 |
**/ |
|
470 |
if($register_type == "email") |
|
471 |
{ |
|
472 |
/* 邮箱验证码检查 */ |
|
473 |
require_once (ROOT_PATH . 'includes/lib_validate_record.php'); |
|
474 |
|
|
475 |
if(empty($email)) |
|
476 |
{ |
|
477 |
show_message($_LANG['msg_email_blank'], $_LANG['sign_up'], 'register.php', 'error'); |
|
478 |
} |
|
479 |
|
|
480 |
$record = get_validate_record($email); |
|
481 |
|
|
482 |
$session_email = $_SESSION[VT_EMAIL_REGISTER]; |
|
483 |
|
|
484 |
$email_code = ! empty($_POST['email_code']) ? trim($_POST['email_code']) : ''; |
|
485 |
|
|
486 |
if(empty($email_code)) |
|
487 |
{ |
|
488 |
show_message($_LANG['msg_email_code_blank'], $_LANG['sign_up'], 'register.php', 'error'); |
|
489 |
} |
|
490 |
else if($session_email != $email) |
|
491 |
{ |
|
492 |
show_message($_LANG['email_changed'], $_LANG['sign_up'], 'register.php', 'error'); |
|
493 |
} |
|
494 |
else if($email_code != $record['record_code']) |
|
495 |
{ |
|
496 |
show_message($_LANG['invalid_email_code'], $_LANG['sign_up'], 'register.php', 'error'); |
|
497 |
} |
|
498 |
|
|
499 |
/* 邮箱注册时 */ |
|
500 |
$username = generate_username(); |
|
501 |
|
|
502 |
/* 邮箱注册 */ |
|
503 |
$result = register_by_email($username, $password, $email, $other); |
|
504 |
|
|
505 |
if($result) |
|
506 |
{ |
|
507 |
/* 删除注册的验证记录 */ |
|
508 |
remove_validate_record($email); |
|
509 |
} |
|
510 |
} |
|
511 |
else if($register_type == "mobile") |
|
512 |
{ |
|
513 |
|
|
514 |
require_once (ROOT_PATH . 'includes/lib_validate_record.php'); |
|
515 |
|
|
516 |
$mobile_phone = ! empty($_POST['mobile_phone']) ? trim($_POST['mobile_phone']) : ''; |
|
517 |
$mobile_code = ! empty($_POST['mobile_code']) ? trim($_POST['mobile_code']) : ''; |
|
518 |
|
|
519 |
$record = get_validate_record($mobile_phone); |
|
520 |
|
|
521 |
$session_mobile_phone = $_SESSION[VT_MOBILE_REGISTER]; |
|
522 |
|
|
523 |
/* 手机验证码检查 */ |
|
524 |
|
|
525 |
if(empty($mobile_code)) |
|
526 |
{ |
|
527 |
show_message($_LANG['msg_mobile_phone_blank'], $_LANG['sign_up'], 'register.php', 'error'); |
|
528 |
} |
|
529 |
// 检查发送短信验证码的手机号码和提交的手机号码是否匹配 |
|
530 |
else if($session_mobile_phone != $mobile_phone) |
|
531 |
{ |
|
532 |
show_message($_LANG['mobile_phone_changed'], $_LANG['sign_up'], 'register.php', 'error'); |
|
533 |
} |
|
534 |
// 检查验证码是否正确 |
|
535 |
else if($record['record_code'] != $mobile_code) |
|
536 |
{ |
|
537 |
show_message($_LANG['invalid_mobile_phone_code'], $_LANG['sign_up'], 'register.php', 'error'); |
|
538 |
} |
|
539 |
// 检查过期时间 |
|
540 |
else if($record['expired_time'] < time()) |
|
541 |
{ |
|
542 |
show_message($_LANG['invalid_mobile_phone_code'], $_LANG['sign_up'], 'register.php', 'error'); |
|
543 |
} |
|
544 |
|
|
545 |
/* 手机注册时,用户名默认为u+手机号 */ |
|
546 |
$username = generate_username_by_mobile($mobile_phone); |
|
547 |
|
|
548 |
/* 手机注册 */ |
|
549 |
$result = register_by_mobile($username, $password, $mobile_phone, $other); |
|
550 |
|
|
551 |
if($result) |
|
552 |
{ |
|
553 |
/* 删除注册的验证记录 */ |
|
554 |
remove_validate_record($mobile_phone); |
|
555 |
} |
|
556 |
} |
|
557 |
else |
|
558 |
{ |
|
559 |
/* 无效的注册类型 */ |
|
560 |
show_message($_LANG['register_type_invalid'], $_LANG['sign_up'], 'register.php', 'error'); |
|
561 |
} |
|
562 |
|
|
563 |
/* 随进生成用户名 */ |
|
564 |
// $username = generate_username(); |
|
565 |
|
|
566 |
if($result) |
|
567 |
{ |
|
568 |
/* 把新注册用户的扩展信息插入数据库 */ |
|
569 |
$sql = 'SELECT id FROM ' . $ecs->table('reg_fields') . ' WHERE type = 0 AND display = 1 ORDER BY dis_order, id'; // 读出所有自定义扩展字段的id |
|
570 |
$fields_arr = $db->getAll($sql); |
|
571 |
|
|
572 |
$extend_field_str = ''; // 生成扩展字段的内容字符串 |
|
573 |
foreach($fields_arr as $val) |
|
574 |
{ |
|
575 |
$extend_field_index = 'extend_field' . $val['id']; |
|
576 |
if(! empty($_POST[$extend_field_index])) |
|
577 |
{ |
|
578 |
$temp_field_content = strlen($_POST[$extend_field_index]) > 100 ? mb_substr($_POST[$extend_field_index], 0, 99) : $_POST[$extend_field_index]; |
|
579 |
$extend_field_str .= " ('" . $_SESSION['user_id'] . "', '" . $val['id'] . "', '" . compile_str($temp_field_content) . "'),"; |
|
580 |
} |
|
581 |
} |
|
582 |
$extend_field_str = substr($extend_field_str, 0, - 1); |
|
583 |
|
|
584 |
if($extend_field_str) // 插入注册扩展数据 |
|
585 |
{ |
|
586 |
$sql = 'INSERT INTO ' . $ecs->table('reg_extend_info') . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_field_str; |
|
587 |
$db->query($sql); |
|
588 |
} |
|
589 |
|
|
590 |
|
|
591 |
/* 写入密码提示问题和答案 */ |
|
592 |
if(! empty($passwd_answer) && ! empty($sel_question)) |
|
593 |
{ |
|
594 |
$sql = 'UPDATE ' . $ecs->table('users') . " SET `passwd_question`='$sel_question', `passwd_answer`='$passwd_answer' WHERE `user_id`='" . $_SESSION['user_id'] . "'"; |
|
595 |
$db->query($sql); |
|
596 |
} |
|
597 |
|
|
598 |
$now = gmtime(); |
|
599 |
if($_CFG['bonus_reg_rand']) |
|
600 |
{ |
|
601 |
$sql_bonus_ext = " order by rand() limit 0,1"; |
|
602 |
} |
|
603 |
$sql_b = "SELECT type_id FROM " . $ecs->table("bonus_type") . " WHERE send_type='" . SEND_BY_REGISTER . "' AND send_start_date<=" . $now . " AND send_end_date>=" . $now . $sql_bonus_ext; |
|
604 |
$res_bonus = $db->query($sql_b); |
|
605 |
$kkk_bonus = 0; |
|
606 |
while($row_bonus = $db->fetchRow($res_bonus)) |
|
607 |
{ |
|
608 |
$sql = "INSERT INTO " . $ecs->table('user_bonus') . "(bonus_type_id, bonus_sn, user_id, used_time, order_id, emailed)" . " VALUES('" . $row_bonus['type_id'] . "', 0, '" . $_SESSION['user_id'] . "', 0, 0, 0)"; |
|
609 |
$db->query($sql); |
|
610 |
$kkk_bonus = $kkk_bonus + 1; |
|
611 |
} |
|
612 |
if($kkk_bonus) |
|
613 |
{ |
|
614 |
$_LANG['register_success'] = '用户名 %s 注册成功,并获得官方赠送的红包礼品'; |
|
615 |
} |
|
616 |
|
|
617 |
|
|
618 |
/* 判断是否需要自动发送注册邮件 */ |
|
619 |
if($GLOBALS['_CFG']['member_email_validate'] && $GLOBALS['_CFG']['send_verify_email']) |
|
620 |
{ |
|
621 |
send_regiter_hash($_SESSION['user_id']); |
|
622 |
} |
|
623 |
$ucdata = empty($user->ucdata) ? "" : $user->ucdata; |
|
624 |
show_message(sprintf($_LANG['register_success'], $username . $ucdata), array( |
|
625 |
$_LANG['back_up_page'],$_LANG['profile_lnk'] |
|
626 |
), array( |
|
627 |
$back_act,'user.php' |
|
628 |
), 'info'); |
|
629 |
} |
|
630 |
else |
|
631 |
{ |
|
632 |
$GLOBALS['err']->show($_LANG['sign_up'], 'register.php'); |
|
633 |
} |
|
634 |
} |
|
635 |
|
|
636 |
} |
|
637 |
|
|
638 |
/** |
|
639 |
* 随机生成指定长度的数字 |
|
640 |
* |
|
641 |
* @param number $length |
|
642 |
* @return number |
|
643 |
*/ |
|
644 |
function rand_number ($length = 6) |
|
645 |
{ |
|
646 |
if($length < 1) |
|
647 |
{ |
|
648 |
$length = 6; |
|
649 |
} |
|
650 |
|
|
651 |
$min = 1; |
|
652 |
for($i = 0; $i < $length - 1; $i ++) |
|
653 |
{ |
|
654 |
$min = $min * 10; |
|
655 |
} |
|
656 |
$max = $min * 10 - 1; |
|
657 |
|
|
658 |
return rand($min, $max); |
|
659 |
} |
|
660 |
|
|
661 |
/** |
|
662 |
* 根据手机号生成用户名 |
|
663 |
* |
|
664 |
* @param number $length |
|
665 |
* @return number |
|
666 |
*/ |
|
667 |
function generate_username_by_mobile ($mobile) |
|
668 |
{ |
|
669 |
|
|
670 |
$username = 'u'.substr($mobile, 0, 3); |
|
671 |
|
|
672 |
$charts = "ABCDEFGHJKLMNPQRSTUVWXYZ"; |
|
673 |
$max = strlen($charts); |
|
674 |
|
|
675 |
for($i = 0; $i < 4; $i ++) |
|
676 |
{ |
|
677 |
$username .= $charts[mt_rand(0, $max)]; |
|
678 |
} |
|
679 |
|
|
680 |
$username .= substr($mobile, -4); |
|
681 |
|
|
682 |
$sql = "select count(*) from " . $GLOBALS['ecs']->table('users') . " where user_name = '$username'"; |
|
683 |
$count = $GLOBALS['db']->getOne($sql); |
|
684 |
if($count > 0) |
|
685 |
{ |
|
686 |
return generate_username_by_mobile(); |
|
687 |
} |
|
688 |
|
|
689 |
return $username; |
|
690 |
} |
|
691 |
|
|
692 |
/** |
|
693 |
* 根据邮箱地址生成用户名 |
|
694 |
* |
|
695 |
* @param number $length |
|
696 |
* @return number |
|
697 |
*/ |
|
698 |
function generate_username () |
|
699 |
{ |
|
700 |
|
|
701 |
$username = 'u'.rand_number(3); |
|
702 |
|
|
703 |
$charts = "ABCDEFGHJKLMNPQRSTUVWXYZ"; |
|
704 |
$max = strlen($charts); |
|
705 |
|
|
706 |
for($i = 0; $i < 4; $i ++) |
|
707 |
{ |
|
708 |
$username .= $charts[mt_rand(0, $max)]; |
|
709 |
} |
|
710 |
|
|
711 |
$username .= rand_number(4); |
|
712 |
|
|
713 |
$sql = "select count(*) from " . $GLOBALS['ecs']->table('users') . " where user_name = '$username'"; |
|
714 |
$count = $GLOBALS['db']->getOne($sql); |
|
715 |
if($count > 0) |
|
716 |
{ |
|
717 |
return generate_username(); |
|
718 |
} |
|
719 |
|
|
720 |
return $username; |
|
721 |
} |
|
722 |
|
|
723 |
?> |