diff options
author | Kevin Chabowski <kevin@kch42.de> | 2012-01-05 15:21:38 +0100 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2012-01-05 15:21:38 +0100 |
commit | 5a87705b5142f70e3e13af93a52a9e7f612cf951 (patch) | |
tree | 611847524e1691d13df34879cd23ab24298be926 /r7r_repo/main.php | |
parent | c4cc87d9d1557ddd4cae4b06b79696712f61a2ad (diff) | |
download | r7r-repo-5a87705b5142f70e3e13af93a52a9e7f612cf951.tar.gz r7r-repo-5a87705b5142f70e3e13af93a52a9e7f612cf951.tar.bz2 r7r-repo-5a87705b5142f70e3e13af93a52a9e7f612cf951.zip |
login and logout implemented.
Diffstat (limited to 'r7r_repo/main.php')
-rw-r--r-- | r7r_repo/main.php | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/r7r_repo/main.php b/r7r_repo/main.php index af19397..a6e0199 100644 --- a/r7r_repo/main.php +++ b/r7r_repo/main.php @@ -99,7 +99,7 @@ $url_handlers = array( else $ste->vars["user"] = array( "logged_in" => True, - "name" => $user->name, + "name" => $user->get_name(), "admin" => $user->isadmin ); }, @@ -127,6 +127,53 @@ $url_handlers = array( echo $ste->exectemplate("home.html"); }, + "login" => function(&$data, $url_now, &$url_next) + { + global $ste, $user; + + if(($user === NULL) and isset($_POST["login"])) + { + try + { + $user = User::by_name($_POST["username"]); + if(PasswordHash::validate($_POST["password"], $user->pwhash)) + { + $ste->vars["success"] = "Logged in successfully."; + $_SESSION["r7r_repo_login_name"] = $user->get_name(); + $url_next = array("_prelude", "index"); + } + else + { + $user = NULL; + $ste->vars["error"] = "Username / Password wrong."; + $url_next = array("index"); + } + } + catch(DoesNotExistError $e) + { + $user = NULL; + $ste->vars["error"] = "Username / Password wrong."; + $url_next = array("index"); + } + } + else + $url_next = array("index"); + }, + "logout" => function(&$data, $url_now, &$url_next) + { + global $ste, $user; + + if($user === NULL) + { + $url_next = array("index"); + return; + } + + $user = NULL; + unset($_SESSION["r7r_repo_login_name"]); + $ste->vars["success"] = "Logged out successfully."; + $url_next = array("_prelude", "index"); + }, "setup" => function(&$data, $url_now, &$url_next) { global $settings, $ste; |