<?php
/*
Login/Logout Page
TODO - add saved game logic into the login and session.
*/
class page extends pageParent {
public $template = 'login.html'; // default page
public $op = "display"; // default operation
public function execute(){
//echo $this->op;
switch ($this->op){
case "display":
//nothing to do here but display the form to login.
break;
case "login": // "display" is the default
//echo "user wants to login";
//$sql ="select *, count(*) as `count`, permission from `originator`.`orig_user` where `email`='". $_REQUEST["email"] ."' and `password`='". $_REQUEST["pass"] ."'";
$sql = "SELECT *, count(*) as count, if(permission & ". user_ADMIN .", 1,0) isAdmin, if(permission & ". user_CONTRIBUTOR .",1,0) isContributor, if(permission & ". user_ACCOUNTABUSE .", 1,0) isAbusive, if (permission & ". user_SOFTDELETE .", 1, 0) isSoftDeleted FROM `orig_user` where `email`='". addslashes($_REQUEST["email"]) ."' and `password`='". addslashes($_REQUEST["pass"]) ."'";
$dbh = db::query($sql);
$account = $dbh->fetch(PDO::FETCH_ASSOC);
//var_dump($account);
//TODO - last login
if (0 != $account["count"]){
$this->data["isLoggedIn"] = true;
session::set("isLoggedIn", true);
foreach ($account as $key=>$val){
session::set($key, $val);
$this->data[$key]=$val;
}
$this->data['redirect'] = true;
$this->data['redirectURL'] = "index.php";
$this->data['redirectMsg'] = "Ohai, ". $account["publicname"] ."! Originator is logging you in.";
$this->data['redirectTime'] = 3; // in seconds
//echo "<pre>"; print_r ($account); print_r($_SESSION); echo "</pre>";exit;
} else {
$this->setError("Userid or Password incorrect. Please try again.");
$this->op="display";
}
break;
case "logout":
if ($this->data["isLoggedIn"]) {
//echo "user wants to logout";
$this->data['redirect'] = true;
$this->data['redirectURL'] = "index.php";
$this->data['redirectMsg'] = "Dewa mata, ". session::get("publicname") ."! Originator is logging you out.";
$this->data['redirectTime'] = 2; // in seconds
$this->data["isLoggedIn"] = false;
session::destroy();
} else {
// something is wrong and they weren't logging in
$this->data['redirectURL'] = "index.php";
$this->data['redirectTime'] = 4; // in seconds
}
}
}
}
?>