commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
define('IN_ECS', true); |
|
3 |
|
|
4 |
require (dirname(__FILE__) . '/includes/init.php'); |
|
5 |
/* 载入语言文件 */ |
|
6 |
require_once (ROOT_PATH . 'languages/' . $_CFG['lang'] . '/user.php'); |
|
7 |
|
|
8 |
$action = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default'; |
|
9 |
|
|
10 |
$function_name = 'action_' . $action; |
|
11 |
|
|
12 |
if(! function_exists($function_name)) |
|
13 |
{ |
|
14 |
$function_name = "action_default"; |
|
15 |
} |
|
16 |
|
|
17 |
call_user_func($function_name); |
|
18 |
|
|
19 |
return; |
|
20 |
|
|
21 |
/** |
|
22 |
* 发送邮箱验证所需的验证码 |
|
23 |
*/ |
|
24 |
function action_send_email_code () |
|
25 |
{ |
|
26 |
$_LANG = $GLOBALS['_LANG']; |
|
27 |
$_CFG = $GLOBALS['_CFG']; |
|
28 |
$smarty = $GLOBALS['smarty']; |
|
29 |
$db = $GLOBALS['db']; |
|
30 |
$ecs = $GLOBALS['ecs']; |
|
31 |
|
|
32 |
require_once (ROOT_PATH . 'includes/lib_validate_record.php'); |
|
33 |
|
|
34 |
$email = trim($_SESSION[VT_EMAIL_VALIDATE]); |
|
35 |
|
|
36 |
if(empty($email)) |
|
37 |
{ |
|
38 |
exit("邮箱不能为空"); |
|
39 |
return; |
|
40 |
} |
|
41 |
else if(! is_email($email)) |
|
42 |
{ |
|
43 |
exit("邮箱格式不正确"); |
|
44 |
return; |
|
45 |
} |
|
46 |
else if(check_validate_record_exist($email)) |
|
47 |
{ |
|
48 |
|
|
49 |
$record = get_validate_record($email); |
|
50 |
|
|
51 |
/** |
|
52 |
* 检查是过了限制发送邮件的时间 |
|
53 |
*/ |
|
54 |
if(time() - $record['last_send_time'] < 60) |
|
55 |
{ |
|
56 |
echo ("每60秒内只能发送一次注册邮箱验证码,请稍候重试"); |
|
57 |
return; |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
require_once (ROOT_PATH . 'includes/lib_passport.php'); |
|
62 |
|
|
63 |
/* 设置验证邮件模板所需要的内容信息 */ |
|
64 |
$template = get_mail_template('email_validate'); |
|
65 |
|
|
66 |
// 生成邮箱验证码 |
|
67 |
$email_code = rand_number(6); |
|
68 |
|
|
69 |
$GLOBALS['smarty']->assign('email_code', $email_code); |
|
70 |
$GLOBALS['smarty']->assign('shop_name', $GLOBALS['_CFG']['shop_name']); |
|
71 |
$GLOBALS['smarty']->assign('send_date', date($GLOBALS['_CFG']['date_format'])); |
|
72 |
|
|
73 |
$content = $GLOBALS['smarty']->fetch('str:' . $template['template_content']); |
|
74 |
|
|
75 |
/* 发送激活验证邮件 */ |
|
76 |
$result = send_mail($email, $email, $template['template_subject'], $content, $template['is_html']); |
|
77 |
if($result) |
|
78 |
{ |
|
79 |
// 保存验证码到Session中 |
|
80 |
$_SESSION[VT_EMAIL_VALIDATE] = $email; |
|
81 |
// 保存验证记录 |
|
82 |
save_validate_record($email, $email_code, VT_EMAIL_VALIDATE, time(), time() + 30 * 60); |
|
83 |
|
|
84 |
echo 'ok'; |
|
85 |
} |
|
86 |
else |
|
87 |
{ |
|
88 |
echo '邮箱验证码发送失败'; |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* 发送手机验证所需的短信验证码 |
|
94 |
*/ |
|
95 |
function action_send_mobile_code () |
|
96 |
{ |
|
97 |
$_LANG = $GLOBALS['_LANG']; |
|
98 |
$smarty = $GLOBALS['smarty']; |
|
99 |
$db = $GLOBALS['db']; |
|
100 |
$ecs = $GLOBALS['ecs']; |
|
101 |
|
|
102 |
require_once (ROOT_PATH . 'includes/lib_validate_record.php'); |
|
103 |
|
|
104 |
$mobile_phone = trim($_SESSION[VT_MOBILE_VALIDATE]); |
|
105 |
|
|
106 |
if(empty($mobile_phone)) |
|
107 |
{ |
|
108 |
exit("手机号不能为空"); |
|
109 |
return; |
|
110 |
} |
|
111 |
else if(! is_mobile_phone($mobile_phone)) |
|
112 |
{ |
|
113 |
exit("手机号格式不正确"); |
|
114 |
return; |
|
115 |
} |
|
116 |
else if(check_validate_record_exist($mobile_phone)) |
|
117 |
{ |
|
118 |
// 获取数据库中的验证记录 |
|
119 |
$record = get_validate_record($mobile_phone); |
|
120 |
|
|
121 |
/** |
|
122 |
* 检查是过了限制发送短信的时间 |
|
123 |
*/ |
|
124 |
$last_send_time = $record['last_send_time']; |
|
125 |
$expired_time = $record['expired_time']; |
|
126 |
$create_time = $record['create_time']; |
|
127 |
$count = $record['count']; |
|
128 |
|
|
129 |
// 每天每个手机号最多发送的验证码数量 |
|
130 |
$max_sms_count = 10; |
|
131 |
// 发送最多验证码数量的限制时间,默认为24小时 |
|
132 |
$max_sms_count_time = 60 * 60 * 24; |
|
133 |
|
|
134 |
if((time() - $last_send_time) < 60) |
|
135 |
{ |
|
136 |
echo ("每60秒内只能发送一次短信验证码,请稍候重试"); |
|
137 |
return; |
|
138 |
} |
|
139 |
else if(time() - $create_time < $max_sms_count_time && $record['count'] > $max_sms_count) |
|
140 |
{ |
|
141 |
echo ("您发送验证码太过于频繁,请稍后重试!"); |
|
142 |
return; |
|
143 |
} |
|
144 |
else |
|
145 |
{ |
|
146 |
$count ++; |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
150 |
require_once (ROOT_PATH . 'includes/lib_passport.php'); |
|
151 |
|
|
152 |
// 设置为空 |
|
153 |
$_SESSION[VT_MOBILE_VALIDATE] = array(); |
|
154 |
|
|
155 |
require_once (ROOT_PATH . 'sms/sms.php'); |
|
156 |
|
|
157 |
// 生成6位短信验证码 |
|
158 |
$mobile_code = rand_number(6); |
|
159 |
// 短信内容 |
|
160 |
$content = sprintf($GLOBALS['_CFG']['sms_register_tpl'],$mobile_code,$GLOBALS['_CFG']['shop_name']); |
|
161 |
|
|
162 |
/* 发送激活验证邮件 */ |
|
163 |
$result = sendSMS($mobile_phone, $content); |
|
164 |
// $result = true; |
|
165 |
if($result) |
|
166 |
{ |
|
167 |
if(! isset($count)) |
|
168 |
{ |
|
169 |
$ext_info = array( |
|
170 |
"count" => 1 |
|
171 |
); |
|
172 |
} |
|
173 |
else |
|
174 |
{ |
|
175 |
$ext_info = array( |
|
176 |
"count" => $count |
|
177 |
); |
|
178 |
} |
|
179 |
// 保存验证的手机号 |
|
180 |
$_SESSION[VT_MOBILE_VALIDATE] = $mobile_phone; |
|
181 |
// 保存验证信息 |
|
182 |
save_validate_record($mobile_phone, $mobile_code, VT_MOBILE_VALIDATE, time(), time() + 30 * 60, $ext_info); |
|
183 |
echo 'ok'; |
|
184 |
} |
|
185 |
else |
|
186 |
{ |
|
187 |
echo '短信验证码发送失败'; |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* 随机生成指定长度的数字 |
|
193 |
* |
|
194 |
* @param number $length |
|
195 |
* @return number |
|
196 |
*/ |
|
197 |
function rand_number ($length = 6) |
|
198 |
{ |
|
199 |
if($length < 1) |
|
200 |
{ |
|
201 |
$length = 6; |
|
202 |
} |
|
203 |
|
|
204 |
$min = 1; |
|
205 |
for($i = 0; $i < $length - 1; $i ++) |
|
206 |
{ |
|
207 |
$min = $min * 10; |
|
208 |
} |
|
209 |
$max = $min * 10 - 1; |
|
210 |
|
|
211 |
return rand($min, $max); |
|
212 |
} |
|
213 |
|
|
214 |
?> |