2 /* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
4 * This file is part of e-DoKo.
6 * e-DoKo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * e-DoKo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with e-DoKo. If not, see <http://www.gnu.org/licenses/>.
21 /* make sure that we are not called from outside the scripts,
22 * use a variable defined in config.php to check this
27 /* test id and password, should really be done in one step */
28 if(!isset($_SESSION["name"]))
30 $email = $_REQUEST["email"];
31 $password = $_REQUEST["password"];
35 $name = $_SESSION["name"];
36 $email = DB_get_email('name',$name);
37 $password = DB_get_passwd_by_name($name);
40 /* user has forgotten his password */
43 /* check if player is in the database */
46 $myid = DB_get_userid('email',$email);
52 /* check how many entries in recovery table */
53 $number = DB_get_number_of_passwords_recovery($myid);
55 /* if less than N recent ones, add a new one and send out email */
58 echo "Ok, I send you a new password. <br />";
60 echo "N.B. You tried this already $number times during the last day and it will only work ".
61 " 5 times during a day.<br />";
62 echo "The new password will be valid for one day, make sure you reset it to something else.<br />";
63 echo "Back to the <a href=\"$INDEX\">main page</a>.";
65 /* create temporary password, use the fist 8 letters of a md5 hash */
66 $TIME = (string) time(); /* to avoid collisions */
67 $hash = md5("Anewpassword".$email.$TIME);
68 $newpw = substr($hash,1,8);
70 $message = "Someone (hopefully you) requested a new password. \n".
71 "You can use this email and the following password: \n".
73 "to log into the server. The new password is valid for 24h, so make\n".
74 "sure you reset your password to something new. Your old password will\n".
75 "also still be valid until you set a new one.\n";
76 $subject = 'Recovery';
77 mymail($myid,$subject,$message);
79 /* we save these in the database */
80 DB_set_recovery_password($myid,md5($newpw));
84 /* make it so that people (or a robot) can request thousands of passwords within a short time
85 * and spam a user this way */
86 echo "Sorry you already tried 5 times during the last 24h.<br />".
87 "You need to use one of those passwords or wait to get a new one.<br />";
88 echo "Back to the <a href=\"$INDEX\">main page</a>.";
92 {/* can't find user id in the database */
96 echo "You need to give me an email address! <br />".
97 "Please try <a href=\"$INDEX\">again</a>.";
98 else /* default error message */
99 echo "Couldn't find a player with this email! <br />".
100 "Please contact Arun, if you think this is a mistake <br />".
101 "or else try <a href=\"$INDEX\">again</a>.";
105 { /* normal user page */
107 /* verify password and email */
108 if(strlen($password)!=32)
109 $password = md5($password);
112 $myid = DB_get_userid('email-password',$email,$password);
118 /* user information is ok */
119 $myname = DB_get_name('email',$email);
120 $_SESSION["name"] = $myname;
122 $PREF = DB_get_PREF($myid);
124 DB_update_user_timestamp($myid);
126 display_user_menu($myid);
128 /* display all games the user has played */
129 echo "<div class=\"user\">";
131 if($myvacation = check_vacation($myid))
133 $vac_start = $myvacation[0];
134 $vac_stop = $myvacation[1];
135 $vac_comment = $myvacation[2];
136 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";
139 echo "<h4>These are all your games:</h4>\n";
141 echo "<p>Session: <br />\n";
142 echo "<span class=\"gamestatuspre\"> p </span> = pre-game phase ";
143 echo "<span class=\"gamestatusplay\">P </span> = game in progess ";
144 echo "<span class=\"gamestatusover\">E </span> = game ended ";
145 echo "<span class=\"gamestatusover multi\"><a>N</a> </span> = N games with same hand <br />";
149 $result = DB_query("SELECT Hand.hash,Hand.game_id,G.mod_date,G.player,G.status, ".
150 " (SELECT count(H.randomnumbers) FROM Game H WHERE H.randomnumbers=G.randomnumbers) AS count ".
152 " LEFT JOIN Game G ON G.id=Hand.game_id".
153 " WHERE user_id='$myid'".
154 " ORDER BY G.session,G.create_date" );
158 echo "<table>\n <tr><td>\n";
159 while( $r = DB_fetch_array($result))
162 $game = DB_format_gameid($r[1]);
163 $gamenr = (int) $game;
164 if($gamenrold < $gamenr)
167 echo "</td></tr>\n <tr> <td>$gamenr:</td>\n";
169 echo "$gamenr:</td>\n";
170 $gamenrold = $gamenr;
171 echo "<td class=\"usergames\">\n";
173 $Multi = ($r[5]>1) ? "multi" : "";
175 echo " <span class=\"gamestatuspre $Multi\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">p </a></span>\n";
176 else if (in_array($r[4],array('gameover','cancel-timedout','cancel-nines','cancel-noplay','cancel-trump')))
178 echo " <span class=\"gamestatusover $Multi\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">";
183 echo "</a></span>\n";
186 echo " <span class=\"gamestatusplay $Multi\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">P </a></span>\n";
187 if($r[4] == 'pre' || $r[4] == 'play')
189 echo "</td>\n<td>\n ";
190 if($r[3]==$myid || !$r[3])
191 echo "(it's <strong>your</strong> turn)\n";
194 $name = DB_get_name('userid',$r[3]);
196 /* check if we need to send out a reminder */
197 if(DB_get_reminder($r[3],$gameid)==0)
198 if(time()-strtotime($r[2]) > 60*60*24*7)
199 echo "<a href=\"$INDEX?action=reminder&me=".$r[0]."\">Send a reminder.</a>";
201 /* check vacaction status of this user */
202 if($vacation=check_vacation($r[3]))
204 $stop = substr($vacation[1],0,10);
205 $title = 'begin:'.substr($vacation[0],0,10).' end:'.$vacation[1].' '.$vacation[2];
206 echo "(it's <span class=\"vacation\" title=\"$title\">$name's (on vacation until $stop)</span> turn)\n";
209 echo "(it's $name's turn)\n";
211 if(time()-strtotime($r[2]) > 60*60*24*30)
212 echo "<a href=\"$INDEX?action=cancel&me=".$r[0]."\">Cancel?</a> ";
215 echo "</td></tr>\n</table>\n";
217 /* give a hint for new players */
219 echo "<p class=\"newbiehint\">You can start new games using the link in the top right corner!</p>\n";
221 /* display last 5 users that have signed up to e-DoKo */
222 $names = DB_get_names_of_new_logins(5);
223 echo "<h4>New Players:</h4>\n<p>\n";
224 echo implode(", ",$names).",...\n";
227 /* display last 5 users that logged on */
228 echo "<h4>Players last logged in:</h4>\n<p>\n";
230 $names = DB_get_names_of_last_logins(7);
231 $emails = DB_get_emails_of_last_logins(7);
234 echo "<img class=\"gravatar\" title=\"".$names[$i]."\" src=\"http://www.gravatar.com/avatar/".md5(strtolower(trim($emails[$i])))."?d=identicon\" />\n";
242 echo "<div class=\"message\">Sorry email and password don't match. Please <a href=\"$INDEX\">try again</a>. </div>";