forked from greensea/seavpn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreg.php
More file actions
109 lines (85 loc) · 2.18 KB
/
reg.php
File metadata and controls
109 lines (85 loc) · 2.18 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
<?php
require_once('includes/header.php');
require_once('includes/recaptcha.php');
$ack = @$_GET['action'];
switch ($ack) {
case 'save':
reg_save();
break;
default:
reg_main();
break;
}
die();
function reg_main($error_msg = '') {
global $smarty;
foreach ($_POST as $key => $value) {
$key = strtolower($key);
$smarty->assign($key, $value);
}
if (!isset($_POST['invitecode'])) {
$smarty->assign('invitecode', @$_GET['invitecode']);
}
$smarty->assign('error_msg', $error_msg);
$smarty->assign('recaptcha_html', recaptcha_get_html(RECAPTCHA_PUBLIC_KEY, null, true));
$smarty->display('reg.html');
}
function reg_save() {
global $smarty;
$email = @$_POST['email'];
$pass = @$_POST['loginpass'];
$pass2 = @$_POST['loginpass2'];
if ($pass == '' || $email == '') {
reg_main(_('Please enter email and password'));
return false;
}
if (strpos($email, '@') == false || strpos($email, '.') == false) {
reg_main(_('Invalid email address'));
return false;
}
if ($pass != $pass2) {
reg_main(_('Password does not match'));
return false;
}
if (recaptcha_verify() !== true) {
reg_main(_('The CAPTCHA you enter is not correct'));
return false;
}
if (INVITECODE_ENABLED == 1 && reg_checkinvite(@$_POST['invitecode']) == false) {
reg_main(_('The invite code is invalid or have been used'));
return false;
}
$ret = user_add($email, $pass);
if ($ret !== true) {
reg_main("<p>$ret</p>" . _('<p>Register fail, please contact us for help if you need.</p>'));
return false;
}
$user = user_get($email);
if (INVITECODE_ENABLED == 1) {
invite_use($_POST['invitecode'], $user['id']);
}
user_online($email);
$smarty->assign('tip_title', _('Register successed'));
$smarty->assign('tip_msg', _('You have registerd successfully'));
$smarty->assign('redirect_url', 'account.php');
$smarty->display('tip.html');
}
/**
* 检查邀请码是否有效
*
* @return 成功返回 true,失败返回 false
*/
function reg_checkinvite($code) {
$qcode = addslashes($code);
$res = db_quick_fetch('invite', "WHERE code='$qcode'");
if (count($res) <= 0) {
return false;
}
if ($res[0]['utime'] == null) {
return true;
}
else {
return false;
}
}
?>