56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
require_once '../Router.php';
|
|
|
|
class LoginPage extends WebPage {
|
|
public $pagekey = "login";
|
|
public $title = "Login - PaperBag - Plan & Execute Your Shopping";
|
|
public $returnToPage = "/";
|
|
|
|
function load(){
|
|
$this->findReturnPage();
|
|
|
|
if(Auth::checkLogin(true)){
|
|
header("Location: ".$this->returnToPage);
|
|
}
|
|
|
|
if(isset($_GET['thank'])){
|
|
$this->msg[] = "Thank you for registering. Please log in to continue!";
|
|
}
|
|
}
|
|
|
|
protected function findReturnPage(){
|
|
if(isset($_POST['referrerPage'])){
|
|
$this->returnToPage = $_POST['referrerPage'];
|
|
}
|
|
elseif(isset($_SESSION['pre-auth'])){
|
|
$this->returnToPage = $_SESSION['pre-auth'];
|
|
}
|
|
elseif(isset($_SERVER['HTTP_REFERER'])){
|
|
$this->returnToPage = explode($_SERVER['HTTP_HOST'], $_SERVER['HTTP_REFERER'])[1];
|
|
}
|
|
|
|
if(in_array($this->returnToPage, array("login", "logout", "register"))){
|
|
$this->returnToPage = $this->pr."/";
|
|
}
|
|
}
|
|
|
|
function doPost(){
|
|
$stayLoggedIn = isset($_POST['stayLoggedIn']);
|
|
$err = Auth::loginWithCredentials($this->data['loginEmail'], $this->data['loginPwd'], $stayLoggedIn);
|
|
if($err === true){
|
|
header("Location: ".$this->returnToPage);
|
|
die();
|
|
}
|
|
|
|
// Do not send the password back to the client...
|
|
$this->data['loginPwd'] = null;
|
|
|
|
$this->err = $err;
|
|
}
|
|
}
|
|
|
|
// For use when class is extended upon
|
|
if(isExecutingPage(__file__)){
|
|
$a = new LoginPage();
|
|
} |