+ JG Adlershof+Hallo , +um dich auf der Website der Jungen Gemeinde einzuloggen, folge bitte diesem Link: + +
Der Link verfällt innerhalb 24h. +Sollte der Link nicht funktionieren, dein Authentifizierungscode lautet . + +Viele Gr, |
+
From 18da65cb74262623719f291920f03ad6ae4a277c Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Oct 2015 10:58:11 +0100 Subject: Login via E-Mail works now. --- action.php | 17 ++-- bootstrap.php | 1 + class/user.php | 23 ++++- functions.php | 62 ++++++------ index.php | 7 +- mail.php | 23 ++++- static/header.php | 18 ++-- static/mail_template.php | 256 +++++++++++++++++++++++++++++++++++++++++++++-- 8 files changed, 346 insertions(+), 61 deletions(-) diff --git a/action.php b/action.php index d291fe1..22b4cc4 100644 --- a/action.php +++ b/action.php @@ -27,7 +27,7 @@ switch($_GET["task"]){ } else if ( $user->login($_POST["name"], $_POST["password"]) ){ $goto = preg_replace("/;/", "&", $_GET["goto"]); header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: ".DOMAIN."?page=" . $goto); + header("Location: ".DOMAIN."?page=" . $goto . "&_new=1"); ob_clean(); exit; } else { @@ -385,17 +385,20 @@ JG Adlershof"; } break; case("genHash"): + /* if ( $_SERVER['REQUEST_METHOD'] != 'POST' ){ header($_SERVER["SERVER_PROTOCOL"] . " 405 Method Not Allowed"); ob_clean(); echo "Method not allowed"; exit; } + */ if ( ! $user->setHash($_REQUEST["name"], $c) ) { - print_login("password"); + print_login("hash"); } else { - print_verify_by_email(); + print_verify_by_email(htmlentities($_REQUEST["name"])); } + break; case("verify"): @@ -406,16 +409,16 @@ JG Adlershof"; exit; } //lredirect( "login"); - if ( ! isset($_REQUEST["name"]) || $_REQUEST["name"] == "" || ! isset($_REQUEST["hash"]) || $_REQUEST["hash"] == "" ){ + if ( ! isset($_REQUEST["email"]) || $_REQUEST["email"] == "" || ! isset($_REQUEST["hash"]) || $_REQUEST["hash"] == "" ){ print_login("missing"); - } else if ( $user->loginByEmail($_REQUEST["name"], $_REQUEST["hash"], $c) ){ + } else if ( $user->loginByEmail($_REQUEST["email"], $_REQUEST["hash"], $c) ){ $goto = preg_replace("/;/", "&", $_GET["goto"]); header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: ".DOMAIN."?page=" . $goto); + header("Location: ".DOMAIN."?page=" . $goto . "&_new=1"); ob_clean(); exit; } else { - print_login("password"); + print_login("hash"); } break; diff --git a/bootstrap.php b/bootstrap.php index 12c5caf..c41755a 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -62,6 +62,7 @@ if ( $_SERVER['HTTP_HOST'] != HOST){ } require(ABSPATH . 'functions.php'); +require(ABSPATH . 'mail.php'); require(ABSPATH . INCLASS . 'cache.php'); require(ABSPATH . INCLASS . 'mysql.php'); require(ABSPATH . INCLASS . 'user.php'); diff --git a/class/user.php b/class/user.php index 6e4d594..9cecf43 100644 --- a/class/user.php +++ b/class/user.php @@ -106,6 +106,8 @@ class jg { $_SESSION["userid"] = $this->getUserId(); $_SESSION["username"] = $this->username; + $_SESSION["new_login"] = 1; + return true; } @@ -149,9 +151,20 @@ class jg { return true; } - public function loginByEmail($name, $hash, $redis) { - if( $redis->getValue(strtolower($name)) == $hash ) { - return $this->login($name, null, true); + public function loginByEmail($email, $hash, $redis) { + if( $redis->getValue(strtolower($email)) == $hash ) { + global $db; + $sql = $db->prepare("SELECT * FROM " . DBPREFIX . "member WHERE email=%s;", $email); + $db_db = $db->doQuery($sql); + if ( is_bool($db_db) ) + return false; + else + $this->query = $db_db->fetch_array(MYSQLI_ASSOC); + + $this->username = $this->getUser(); + + $redis->delete( strtolower($email) ); + return $this->login($this->username, null, true); } else { return false; } @@ -160,14 +173,14 @@ class jg { public function setHash($email, $redis) { global $db; - $sql = $db->prepare("SELECT * FROM " . DBPREFIX . "user WHERE email=%s;", $email); + $sql = $db->prepare("SELECT * FROM " . DBPREFIX . "member WHERE email=%s;", $email); $db_db = $db->doQuery($sql); if ( is_bool($db_db) ) return false; else $this->query = $db_db->fetch_array(MYSQLI_ASSOC); - if ( $this->getEmail == $email) { + if ( strtolower($this->getEmail()) == strtolower($email)) { // See here: https://stackoverflow.com/questions/19017694/one-line-php-random-string-generator?answertab=active#tab-top $hash = chr( mt_rand( 97 ,122 ) ) .substr( md5( time( ) ) ,1 ); $redis->setKey(strtolower($email), $hash, 86400); diff --git a/functions.php b/functions.php index 09118a4..ff82c56 100644 --- a/functions.php +++ b/functions.php @@ -63,14 +63,19 @@ if( isset($_GET["goto"]) && $_GET["goto"] != "" ) { } else if ( $option == "logout" ){ ?>
Logout erfolgreich!
+Nutzer/Passwort falsch
Bitte fülle alle Felder aus!
+ +Deine E-Mail war falsch. Du scheinst kein Mitglied der JG zu sein.
@@ -111,6 +116,8 @@ if( isset($_GET["goto"]) && $_GET["goto"] != "" ) { */ ?> +Bitte gib deine E-Mail Adresse ein. Es wird dir daraufhin eine Mail mit einem Link zugestellt, der dich einloggt.
+Es wurde dir eine E-Mail an gesendet. +Bitte folge dem enthaltenen Link oder gebe den Code per Hand ein.
+