Mercurial > hg > fapweb
annotate register.inc.php @ 191:988e0ab2b77e
Improve registration process by adding information verification phase.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 10 Nov 2013 14:55:31 +0200 |
parents | a49c5f15a273 |
children | e65b2392fc0e |
rev | line source |
---|---|
0 | 1 <? |
136
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
2 // |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
3 // FAPWeb Simple Demoparty System |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
4 // Attendee registration page |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
5 // (C) Copyright 2012-2013 Tecnic Software productions (TNSP) |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
6 // |
0 | 7 $mode = stGetRequestItem("mode", "start"); |
8 | |
138 | 9 // Settings for robot check hash generator |
0 | 10 $botCheckIDs = "aBcdefghIjklmnopqrsTuvxyz0123456"; |
11 $botCheckOPs = "bit"; | |
12 $botCheckROPs = "+-*"; | |
13 | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
14 $formFields = array( |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
15 "name" => "Name", |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
16 "groups" => "Group(s)", |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
17 "email" => "E-mail", |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
18 "oneliner" => "Oneliner", |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
19 "hash" => FALSE, |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
20 "botcheck" => FALSE, |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
21 ); |
0 | 22 |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
23 |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
24 function stPrintFormData($button, $mode = "start", $exclude = array()) |
0 | 25 { |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
26 global $formFields; |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
27 |
0 | 28 echo |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
29 stGetFormStart("register"). |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
30 " ".stGetFormSubmitInput("continue", $button)."\n"; |
0 | 31 |
32 stPrintFormHiddenInput("mode", $mode); | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
33 |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
34 foreach ($formFields as $name => $title) |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
35 { |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
36 if (!in_array($name, $exclude)) |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
37 stPrintFormHiddenInput($name, stGetRequestItem($name)); |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
38 } |
0 | 39 |
40 echo "</form>\n"; | |
41 } | |
42 | |
43 | |
138 | 44 // Convert integer value to hash code |
0 | 45 function intValueToHash($val) |
46 { | |
47 global $botCheckIDs; | |
48 $str = ""; | |
49 do | |
50 { | |
51 $str = $botCheckIDs[$val & 31].$str; | |
52 $val >>= 5; | |
53 } | |
54 while ($val > 0); | |
55 return $str; | |
56 } | |
57 | |
58 | |
138 | 59 // Convert integer hash to integer value |
0 | 60 function intHashToValue($hash) |
61 { | |
62 global $botCheckIDs; | |
63 for ($val = 0, $i = 0; $i < strlen($hash); $i++) | |
64 { | |
65 $val *= 32; | |
66 $n = strpos($botCheckIDs, $hash[$i]); | |
67 if ($n !== FALSE) | |
68 $val += $n; | |
69 else | |
70 return -2; | |
71 } | |
72 return $val; | |
73 } | |
74 | |
75 | |
138 | 76 // Split hash into parts |
0 | 77 function splitHash($hash) |
78 { | |
79 global $botCheckOPs; | |
80 return preg_split("/([".$botCheckOPs."])/", $hash, -1, PREG_SPLIT_DELIM_CAPTURE); | |
81 } | |
82 | |
83 | |
84 function hashToCheckStr($hash) | |
85 { | |
86 global $botCheckOPs, $botCheckROPs; | |
87 $out = ""; | |
88 | |
89 foreach (splitHash($hash) as $val) | |
90 { | |
91 $i = strpos($botCheckOPs, $val); | |
92 if ($i !== FALSE) | |
93 $out .= " ".$botCheckROPs[$i]." "; | |
94 else | |
95 $out .= intHashToValue($val); | |
96 } | |
97 return $out; | |
98 } | |
99 | |
100 | |
101 function hashToAnswer($hash) | |
102 { | |
103 eval("\$res = ".hashToCheckStr($hash).";"); | |
104 return $res; | |
105 } | |
106 | |
138 | 107 // Check if user registration is available |
103
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
108 stCheckRegistrationAvailable(); |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
109 |
0 | 110 // Check if registration is enabled |
111 if (!stChkSetting("allowRegister")) | |
112 { | |
182
e227e6a3d46b
Move some texts to settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
113 echo stGetSetting("registerNotEnabled"); |
103
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
114 } |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
115 else |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
116 if ($maxAttendeesHard > 0 && $numAttendees >= $maxAttendeesHard) |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
117 { |
182
e227e6a3d46b
Move some texts to settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
118 echo stGetSetting("registerLimitExceeded"); |
0 | 119 } |
120 else | |
121 if ($mode == "start") | |
122 { | |
138 | 123 // |
124 // Show registration form | |
125 // | |
126 // Generate bot-check | |
0 | 127 $botCheckHash = |
128 intValueToHash(rand(1,5)). | |
129 $botCheckOPs[rand(0,2)]. | |
130 intValueToHash(rand(1,5)). | |
131 $botCheckOPs[rand(0,2)]. | |
132 intValueToHash(5 * rand(1,5)); | |
133 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
134 echo |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
135 "<h1>Registration</h1>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
136 stGetFormStart("register"). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
137 " ".stGetFormHiddenInput("mode", "check")."\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
138 " ".stGetFormHiddenInput("hash", $botCheckHash)."\n". |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
139 " <table class=\"register\">\n"; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
140 stPrintFormTextInput("Handle:", "(elite)", 20, SET_LEN_USERNAME, "name"); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
141 stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 30, SET_LEN_GROUPS, "groups"); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
142 stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 30, SET_LEN_EMAIL, "email"); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
143 stPrintFormTextInput("Oneliner:", "(whatever)", 30, SET_LEN_ONELINER, "oneliner"); |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
144 stPrintFormTextInput(hashToCheckStr($botCheckHash)." = ", "(I.Q. / robot check". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
145 //" [".hashToAnswer($botCheckHash)."]". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
146 ")", 20, 20, "botcheck", "autocomplete=\"off\""); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
147 echo |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
148 " <tr><td colspan=\"2\"></td><td>".stGetFormSubmitInput("register", "Register")."</td></tr>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
149 " </table>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
150 "</form>\n"; |
0 | 151 |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
152 echo stGetSetting("registerInfoText"); |
0 | 153 } |
154 else | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
155 if ($mode == "check" || $mode == "register") |
0 | 156 { |
138 | 157 // |
158 // Check the registrant's details | |
159 // | |
187 | 160 stChkRequestItem("name", $fake, |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
161 array(CHK_ISGT, VT_STR, 0, "Handle / name not given."), |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
162 array(CHK_ISLT, VT_STR, SET_LEN_USERNAME, "Handle / name is too long, should be less than ".SET_LEN_USERNAME." characters.")); |
0 | 163 |
187 | 164 stChkRequestItem("groups", $fake, |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
165 array(CHK_ISLT, VT_STR, SET_LEN_GROUPS, "Groups are too long, should be less than ".SET_LEN_GROUPS." characters.")); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
166 |
187 | 167 stChkRequestItem("oneliner", $fake, |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
168 array(CHK_ISLT, VT_STR, SET_LEN_ONELINER, "Oneliner is too long, should be less than ".SET_LEN_ONELINER." characters.")); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
169 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
170 stChkRequestItem("hash", $hash, |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
171 array(CHK_GTEQ, VT_STR, 0, "Invalid data.")); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
172 |
0 | 173 |
16 | 174 $email = stGetRequestItem("email"); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
175 if (stGetSetting("requireEMail") && strlen($email) < 4) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
176 stError("E-mail address not given, or it is too short."); |
16 | 177 |
48 | 178 if (strlen($email) > 0 && (strpos($email, "@") === FALSE || strpos($email, ".") === FALSE)) |
16 | 179 stError("E-mail address not in proper format."); |
180 | |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
181 if (strlen($email) > SET_LEN_EMAIL) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
182 stError("E-mail address too long, max ".SET_LEN_EMAIL." characters."); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
183 |
0 | 184 $answer = stGetRequestItem("botcheck"); |
185 if (hashToAnswer($hash) != intval($answer)) | |
186 stError("Incorrect answer to I.Q. / bot check."); | |
187 | |
188 if ($errorSet) | |
189 { | |
183 | 190 echo |
191 "<p>Following errors occured:</p>\n". | |
192 "<ul>\n".$errorMsg."</ul>\n"; | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
193 stPrintFormData("Go back", "start", array("botcheck")); |
0 | 194 } |
195 else | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
196 if ($mode == "register") |
0 | 197 { |
198 $sql = stPrepareSQL( | |
199 "INSERT INTO attendees (regtime,name,groups,oneliner,email) VALUES (%d,%S,%S,%S,%S)", | |
200 time(), "name", "groups", "oneliner", "email"); | |
201 | |
202 if (stExecSQL($sql) !== FALSE) | |
203 { | |
183 | 204 echo stGetSetting("registerPostText"); |
16 | 205 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
206 if (strlen($email) < 4) |
16 | 207 echo stGetSetting("registerPostNoEmail"); |
0 | 208 } |
209 else | |
210 { | |
183 | 211 echo |
212 "<h1>An error occured.</h1>\n". | |
213 "<p>Oh noes! SQL error happenstance!</p>"; | |
0 | 214 } |
215 } | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
216 else |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
217 { |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
218 echo |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
219 "<h1>Verify your information</h1>\n". |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
220 "<p>Is the following information correct?</p>\n". |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
221 "<table class=\"register\">\n"; |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
222 |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
223 foreach ($formFields as $name => $title) |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
224 { |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
225 if ($title !== FALSE) |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
226 { |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
227 echo |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
228 " <tr><td class=\"".$name."\">".chentities($title).":</td>". |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
229 "<td>".chentities(stGetRequestItem($name))."</td></tr>\n"; |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
230 } |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
231 } |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
232 echo "</table>\n"; |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
233 |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
234 stPrintFormData("Go back", "start", array("botcheck")); |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
235 stPrintFormData("Register", "register"); |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
236 } |
0 | 237 } |
238 ?> |