Mercurial > hg > fapweb
annotate register.inc.php @ 48:1fccb8f031ed
Fix e-mail check.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 05 Oct 2013 03:59:03 +0300 |
parents | 7be3f8cf1f7a |
children | c6b9041078ec |
rev | line source |
---|---|
0 | 1 <? |
2 $mode = stGetRequestItem("mode", "start"); | |
3 | |
4 $botCheckIDs = "aBcdefghIjklmnopqrsTuvxyz0123456"; | |
5 $botCheckOPs = "bit"; | |
6 $botCheckROPs = "+-*"; | |
7 | |
8 | |
9 function stPrintFormData($button, $mode = "start") | |
10 { | |
11 echo | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
12 stGetFormStart("register"). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
13 " ".stGetFormSubmitInput("continue", $button)."\n"; |
0 | 14 |
15 stPrintFormHiddenInput("mode", $mode); | |
16 | |
17 foreach (array("name", "groups", "email", "oneliner", "hash", "botcheck") as $name) | |
18 stPrintFormHiddenInput($name, stGetRequestItem($name)); | |
19 | |
20 echo "</form>\n"; | |
21 } | |
22 | |
23 | |
24 function intValueToHash($val) | |
25 { | |
26 global $botCheckIDs; | |
27 $str = ""; | |
28 do | |
29 { | |
30 $str = $botCheckIDs[$val & 31].$str; | |
31 $val >>= 5; | |
32 } | |
33 while ($val > 0); | |
34 return $str; | |
35 } | |
36 | |
37 | |
38 function intHashToValue($hash) | |
39 { | |
40 global $botCheckIDs; | |
41 for ($val = 0, $i = 0; $i < strlen($hash); $i++) | |
42 { | |
43 $val *= 32; | |
44 $n = strpos($botCheckIDs, $hash[$i]); | |
45 if ($n !== FALSE) | |
46 $val += $n; | |
47 else | |
48 return -2; | |
49 } | |
50 return $val; | |
51 } | |
52 | |
53 | |
54 function splitHash($hash) | |
55 { | |
56 global $botCheckOPs; | |
57 return preg_split("/([".$botCheckOPs."])/", $hash, -1, PREG_SPLIT_DELIM_CAPTURE); | |
58 } | |
59 | |
60 | |
61 function hashToCheckStr($hash) | |
62 { | |
63 global $botCheckOPs, $botCheckROPs; | |
64 $out = ""; | |
65 | |
66 foreach (splitHash($hash) as $val) | |
67 { | |
68 $i = strpos($botCheckOPs, $val); | |
69 if ($i !== FALSE) | |
70 $out .= " ".$botCheckROPs[$i]." "; | |
71 else | |
72 $out .= intHashToValue($val); | |
73 } | |
74 return $out; | |
75 } | |
76 | |
77 | |
78 function hashToAnswer($hash) | |
79 { | |
80 eval("\$res = ".hashToCheckStr($hash).";"); | |
81 return $res; | |
82 } | |
83 | |
84 // Check if registration is enabled | |
85 if (!stChkSetting("allowRegister")) | |
86 { | |
87 ?> | |
88 <h1>Sorry, registration disabled!</h1> | |
89 <p> | |
90 Registration to the event is not available at this time. | |
91 </p> | |
92 <? | |
93 } | |
94 else | |
95 if ($mode == "start") | |
96 { | |
97 $botCheckHash = | |
98 intValueToHash(rand(1,5)). | |
99 $botCheckOPs[rand(0,2)]. | |
100 intValueToHash(rand(1,5)). | |
101 $botCheckOPs[rand(0,2)]. | |
102 intValueToHash(5 * rand(1,5)); | |
103 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
104 echo |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
105 "<h1>Registration</h1>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
106 stGetFormStart("register"). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
107 " ".stGetFormHiddenInput("mode", "check")."\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
108 " ".stGetFormHiddenInput("hash", $botCheckHash)."\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
109 " <table>\n"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
110 stPrintFormTextInput("Handle:", "(elite)", 30, 30, "name"); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
111 stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 40, 64, "groups"); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
112 stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 40, 64, "email"); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
113 stPrintFormTextInput("Oneliner:", "(whatever)", 64, 64, "oneliner"); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
114 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
|
115 //" [".hashToAnswer($botCheckHash)."]". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
116 ")", 20, 20, "botcheck", "autocomplete=\"off\""); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
117 echo |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
118 " <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
|
119 " </table>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
120 "</form>\n"; |
0 | 121 |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
122 echo stGetSetting("registerInfoText"); |
0 | 123 } |
124 else | |
125 if ($mode == "check") | |
126 { | |
127 if (stChkDataItem("name") || strlen(stGetRequestItem("name")) < 3) | |
128 stError("Handle / name not given, or too short."); | |
129 | |
130 if (stChkDataItem("hash")) | |
131 stError("Invalid data."); | |
132 | |
16 | 133 $email = stGetRequestItem("email"); |
134 if (stGetSetting("requireEMail")) | |
135 { | |
136 if (stChkDataItem("email") || strlen($email) < 4) | |
137 stError("E-mail address not given, or it is too short."); | |
138 } | |
139 | |
48 | 140 if (strlen($email) > 0 && (strpos($email, "@") === FALSE || strpos($email, ".") === FALSE)) |
16 | 141 stError("E-mail address not in proper format."); |
142 | |
0 | 143 $hash = stGetRequestItem("hash"); |
144 $answer = stGetRequestItem("botcheck"); | |
145 if (hashToAnswer($hash) != intval($answer)) | |
146 stError("Incorrect answer to I.Q. / bot check."); | |
147 | |
148 if ($errorSet) | |
149 { | |
150 echo "<p>Following errors occured:</p>\n". | |
151 "<ul>\n".$errorMsg."</ul>\n"; | |
152 stPrintFormData("Go back"); | |
153 } | |
154 else | |
155 { | |
156 $sql = stPrepareSQL( | |
157 "INSERT INTO attendees (regtime,name,groups,oneliner,email) VALUES (%d,%S,%S,%S,%S)", | |
158 time(), "name", "groups", "oneliner", "email"); | |
159 | |
160 if (stExecSQL($sql) !== FALSE) | |
161 { | |
16 | 162 echo "<h1>Registration successful</h1>\n". |
163 stGetSetting("registerPostText"); | |
164 | |
0 | 165 if (stChkDataItem("email")) |
16 | 166 echo stGetSetting("registerPostNoEmail"); |
0 | 167 } |
168 else | |
169 { | |
170 echo "<h1>An error occured.</h1>\n"; | |
171 echo "<p>Oh noes! SQL error happenstance!</p>"; | |
172 } | |
173 } | |
174 } | |
175 ?> |