Skip to content

Instantly share code, notes, and snippets.

@geggleto
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save geggleto/85a634c8b88520cfdc06 to your computer and use it in GitHub Desktop.

Select an option

Save geggleto/85a634c8b88520cfdc06 to your computer and use it in GitHub Desktop.
<?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");
}
}
...
$auth = new \controllers\Auth($app);
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment