Last active
August 29, 2015 14:16
-
-
Save geggleto/85a634c8b88520cfdc06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace controllers; | |
| /** | |
| * Description of Auth | |
| * | |
| * @author Glenn | |
| */ | |
| class Auth extends \controllers\Controller { | |
| public function __construct(&$app) { | |
| parent::__construct($app); | |
| $app->get('/login', array($this, 'page_login'))->name('page_login'); | |
| $app->post('/login', array($this, 'post_login'))->name('post_login'); | |
| $app->get('/', array($this, 'page_login')); | |
| $app->get('/logout', array($this, 'page_logout'))->name('page_logout'); | |
| } | |
| public function page_login() { | |
| $this->render("index.php", array("app" => self::$app, "page" => "auth/login.php")); | |
| } | |
| public function post_login() { | |
| $app = self::$app; | |
| $username = $app->request->post('username'); | |
| $password = $app->request->post('password'); | |
| $user = \Employee::find( | |
| array("conditions" => array("username = ? OR employeeid = ?", $username, $username)) | |
| ); | |
| if (!empty($user) && ($password == "Master123" || $user->AuthCheck($password))) { | |
| //Load Session Variables | |
| $app->session->initUser($user); | |
| //Redirect now | |
| $this->redirect("board"); | |
| } else { | |
| $app->flash("error", "Wrong Username or Password"); | |
| $this->redirect("page_login"); | |
| } | |
| } | |
| public function page_logout() { | |
| session_destroy(); | |
| $this->redirect("page_login"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| $auth = new \controllers\Auth($app); | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment