login/pass: error messages below page title
[minimedit.git] / login / mailpass.inc.php
index 1be0d68e14c3c4c5e9e4bb4532570fdd84f3da8e..77314a4ccfa02f91e27f1ff3cd4c2cc37615222c 100644 (file)
@@ -1,9 +1,10 @@
 <?php
 function userbymail($email)
 {
+       $email = strtolower($email);
        foreach (glob("profile/*") as $useropt) {
                if ($mailopt = @file_get_contents("$useropt/email.txt")
-               and rtrim($mailopt) == $email) {
+               and strtolower(rtrim($mailopt)) == $email) {
                        return substr($useropt, strlen('profile/'));
                }
        }
@@ -14,15 +15,17 @@ function mailtoken($email)
 {
        $found = userbymail($email);
        if (!$found) return FALSE;
+       $user = new User("profile/$found");
+       if (empty($user)) return FALSE;
 
        $token = substr(sha1('$Random'.rand()), 0, 10);
        if (!file_put_contents("profile/$found/.token", $token))
                throw new Exception("could not store token for $found");
 
-       $sitename = $_SERVER['HTTP_HOST'];
+       $sitename = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
        $sitelink = 'https://'.$sitename;
        $rep = [
-               '[[user]]' => $found,
+               '[[user]]' => $user->name ?: $found,
                '[[link]]' => "$sitelink/login/pass?token=$found:$token",
                '[[site]]' => $sitename,
        ];