2 /* make sure that we are not called from outside the scripts,
3 * use a variable defined in config.php to check this
8 /* test id and password, should really be done in one step */
9 if(!isset($_SESSION["name"]))
11 $email = $_REQUEST["email"];
12 $password = $_REQUEST["password"];
16 $name = $_SESSION["name"];
17 $email = DB_get_email('name',$name);
18 $password = DB_get_passwd_by_name($name);
21 /* user has forgotten his password */
24 /* check if player is in the database */
27 $myid = DB_get_userid('email',$email);
33 /* check how many entries in recovery table */
34 $number = DB_get_number_of_passwords_recovery($myid);
36 /* if less than N recent ones, add a new one and send out email */
39 echo "Ok, I send you a new password. <br />";
41 echo "N.B. You tried this already $number times during the last day and it will only work ".
42 " 5 times during a day.<br />";
43 echo "The new password will be valid for one day, make sure you reset it to something else.<br />";
44 echo "Back to the <a href=\"$INDEX\">main page</a>.";
46 /* create temporary password, use the fist 8 letters of a md5 hash */
47 $TIME = (string) time(); /* to avoid collisions */
48 $hash = md5("Anewpassword".$email.$TIME);
49 $newpw = substr($hash,1,8);
51 $message = "Someone (hopefully you) requested a new password. \n".
52 "You can use this email and the following password: \n".
54 "to log into the server. The new password is valid for 24h, so make\n".
55 "sure you reset your password to something new. Your old password will\n".
56 " also still be valid until you set a new one\n";
57 mymail($email,$EmailName."recovery ",$message);
59 /* we save these in the database */
60 DB_set_recovery_password($myid,md5($newpw));
64 /* make it so that people (or a robot) can request thousands of passwords within a short time
65 * and spam a user this way */
66 echo "Sorry you already tried 5 times during the last 24h.<br />".
67 "You need to use one of those passwords or wait to get a new one.<br />";
68 echo "Back to the <a href=\"$INDEX\">main page</a>.";
72 {/* can't find user id in the database */
76 echo "You need to give me an email address! <br />".
77 "Please try <a href=\"$INDEX\">again</a>.";
78 else /* default error message */
79 echo "Couldn't find a player with this email! <br />".
80 "Please contact Arun, if you think this is a mistake <br />".
81 "or else try <a href=\"$INDEX\">again</a>.";
85 { /* normal user page */
87 /* verify password and email */
88 if(strlen($password)!=32)
89 $password = md5($password);
92 $myid = DB_get_userid('email-password',$email,$password);
98 /* user information is ok */
99 $myname = DB_get_name('email',$email);
100 $_SESSION["name"] = $myname;
102 $PREF = DB_get_PREF($myid);
104 DB_update_user_timestamp($myid);
106 display_user_menu($myid);
108 /* display all games the user has played */
109 echo "<div class=\"user\">";
111 if($myvacation = check_vacation($myid))
113 $vac_start = $myvacation[0];
114 $vac_stop = $myvacation[1];
115 $vac_comment = $myvacation[2];
116 echo "<p class=\"vacation\">Enjoy your vacation (don't forgot to change your settings once you're back). Between $vac_start and $vac_stop other users will see the following message: $vac_comment.</p>\n";
119 echo "<h4>These are all your games:</h4>\n";
121 echo "<p>Session: <br />\n";
122 echo "<span class=\"gamestatuspre\"> p </span> = pre-game phase ";
123 echo "<span class=\"gamestatusplay\">P </span> = game in progess ";
124 echo "<span class=\"gamestatusover\">E </span> = game ended ";
125 echo "<span class=\"gamestatusover multi\"><a>N</a> </span> = N games with same hand <br />";
129 $result = DB_query("SELECT Hand.hash,Hand.game_id,G.mod_date,G.player,G.status, ".
130 " (SELECT count(H.randomnumbers) FROM Game H WHERE H.randomnumbers=G.randomnumbers) AS count ".
132 " LEFT JOIN Game G ON G.id=Hand.game_id".
133 " WHERE user_id='$myid'".
134 " ORDER BY G.session,G.create_date" );
138 echo "<table>\n <tr><td>\n";
139 while( $r = DB_fetch_array($result))
142 $game = DB_format_gameid($r[1]);
143 $gamenr = (int) $game;
144 if($gamenrold < $gamenr)
147 echo "</td></tr>\n <tr> <td>$gamenr:</td>\n";
149 echo "$gamenr:</td>\n";
150 $gamenrold = $gamenr;
151 echo "<td class=\"usergames\">\n";
153 $Multi = ($r[5]>1) ? "multi" : "";
155 echo " <span class=\"gamestatuspre $Multi\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">p </a></span>\n";
156 else if ($r[4]=='gameover')
158 echo " <span class=\"gamestatusover $Multi\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">";
163 echo "</a></span>\n";
166 echo " <span class=\"gamestatusplay $Multi\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">P </a></span>\n";
167 if($r[4] != 'gameover')
169 echo "</td>\n<td>\n ";
170 if($r[3]==$myid || !$r[3])
171 echo "(it's <strong>your</strong> turn)\n";
174 $name = DB_get_name('userid',$r[3]);
176 /* check if we need to send out a reminder */
177 if(DB_get_reminder($r[3],$gameid)==0)
178 if(time()-strtotime($r[2]) > 60*60*24*7)
179 echo "<a href=\"$INDEX?action=reminder&me=".$r[0]."\">Send a reminder.</a>";
181 /* check vacaction status of this user */
182 if($vacation=check_vacation($r[3]))
184 $stop = substr($vacation[1],0,10);
185 $title = 'begin:'.substr($vacation[0],0,10).' end:'.$vacation[1].' '.$vacation[2];
186 echo "(it's <span class=\"vacation\" title=\"$title\">$name's (on vacation until $stop)</span> turn)\n";
189 echo "(it's $name's turn)\n";
191 if(time()-strtotime($r[2]) > 60*60*24*30)
192 echo "<a href=\"$INDEX?action=cancel&me=".$r[0]."\">Cancel?</a>".
193 " (clicking here is final and can't be restored)";
196 echo "</td></tr>\n</table>\n";
198 /* give a hint for new players */
200 echo "<p class=\"newbiehint\">You can start new games using the link in the top right corner!</p>\n";
202 /* display last 5 users that have signed up to e-DoKo */
203 $names = DB_get_names_of_new_logins(5);
204 echo "<h4>New Players:</h4>\n<p>\n";
205 echo implode(", ",$names).",...\n";
208 /* display last 5 users that logged on */
209 $names = DB_get_names_of_last_logins(5);
210 echo "<h4>Players last logged in:</h4>\n<p>\n";
211 echo implode(", ",$names).",...\n";
218 echo "<div class=\"message\">Sorry email and password don't match. Please <a href=\"$INDEX\">try again</a>. </div>";