-
Notifications
You must be signed in to change notification settings - Fork 22
/
invite.php
114 lines (77 loc) · 2.1 KB
/
invite.php
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
<?php
include("include/init.php");
loadlib("invite_codes");
loadlib("rfc822");
$redir = get_str("redir");
# These are not the invites you are looking for
if (! $GLOBALS['cfg']['enable_feature_invite_codes']){
error_404();
}
# User is already logged in
if (($GLOBALS['cfg']['user']['id']) && (! $GLOBALS['cfg']['invite_codes_allow_signedin_users'])){
header("location: /?redir=" . urlencode($redir));
exit();
}
# User has already redeemed their invite code
if (invite_codes_get_by_cookie()){
header("location: /signin/?redir=" . urlencode($redir));
exit();
}
# User is trying to redeem an invite code
if ($code = get_str("code")){
if ($invite = invite_codes_get_by_code($code)){
invite_codes_signin($invite);
exit();
}
else {
$GLOBALS['error']['invalid_code'] = 1;
}
}
# User is trying to request an invite code?
$crumb_key = 'invite';
$GLOBALS['smarty']->assign("crumb_key", $crumb_key);
$crumb_ok = crumb_check($crumb_key);
if ($crumb_ok){
$code = post_str("code");
$email = post_str("email");
# just in case the jquery doesn't work or something...
$code = ($code == "3x4mpl3c0d3") ? null : $code;
$email = ($email == "you@example.com") ? null : $email;
if ($code){
if ($invite = invite_codes_get_by_code($code)){
invite_codes_signin($invite);
exit();
}
else {
$GLOBALS['error']['invalid_code'] = 1;
}
}
else if ($email){
$email = post_str("email");
if (! rfc822_is_valid_email_address($email)){
$GLOBALS['error']['invalid_email'] = 1;
}
else {
$rsp = invite_codes_create($email);
if ($rsp['ok']){
$invite = $rsp['invite'];
if ($invite['sent']){
invite_codes_send_invite($invite);
$GLOBALS['smarty']->assign("invite_resent", 1);
}
else {
$rsp = invite_codes_register_invite($invite);
}
}
if (! $rsp['ok']){
$GLOBALS['error']['request_failed'] = 1;
$GLOBALS['error']['details'] = $rsp['error'];
}
$GLOBALS['smarty']->assign("step", "request_ok");
}
}
else {}
}
$GLOBALS['smarty']->display("page_invite.txt");
exit();
?>