2 function userbymail($email)
4 $email = strtolower($email);
5 foreach (glob("profile/*") as $useropt) {
6 if ($mailopt = @file_get_contents("$useropt/email.txt")
7 and strtolower(rtrim($mailopt)) == $email) {
8 return substr($useropt, strlen('profile/'));
14 function mailtoken($email)
16 $found = userbymail($email);
17 if (!$found) return FALSE;
18 $user = new User("profile/$found");
19 if (empty($user)) return FALSE;
21 $token = substr(sha1('$Random'.rand()), 0, 10);
22 if (!file_put_contents("profile/$found/.token", $token))
23 throw new Exception("could not store token for $found");
25 $sitename = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
26 $sitelink = 'https://'.$sitename;
28 '[[user]]' => $user->name ?: $found,
29 '[[link]]' => "$sitelink/login/pass?token=$found:$token",
30 '[[site]]' => $sitename,
33 $mailbody = file_get_contents('login/mailpass.inc.txt');
34 $mailbody = str_replace(array_keys($rep), array_values($rep), $mailbody);
35 if (!$mailbody) throw new Exception('empty mail body');
36 $mailsub = "Wachtwoord-reset voor $sitename";
37 $mailhead = "From: $sitename <info@$sitename>";
38 $rcpt = "$found <$email>";
40 return mail($rcpt, $mailsub, $mailbody, $mailhead);