76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace ppa\Controller;
|
|
|
|
use ppa\Model\UserModel;
|
|
use ppa\Library\View;
|
|
|
|
class UserController
|
|
{
|
|
private $userModel;
|
|
protected $view;
|
|
|
|
public function __construct($view)
|
|
{
|
|
$this->userModel = new UserModel();
|
|
$this->view = $view;
|
|
}
|
|
|
|
|
|
public function loginUser()
|
|
{
|
|
$erg = array();
|
|
$erg = $this->userModel->loginUser($this->sanitize($_POST["username"]), $this->sanitize($_POST["password"]) );
|
|
if ($erg["success"] == true) {
|
|
header("Location: ?controller=Welcome&do=showWelcome");
|
|
exit();
|
|
|
|
}
|
|
else {
|
|
$this->view->setDoMethodName("showUserLoginForm");
|
|
$this->showUserLoginForm();
|
|
}
|
|
|
|
}
|
|
|
|
public function logoutUser()
|
|
{
|
|
$this->userModel->logoutUser();
|
|
header("Location: ?controller=User&do=showUserLoginForm");
|
|
exit();
|
|
}
|
|
|
|
public function registerUser()
|
|
{
|
|
$erg = array();
|
|
$erg = $this->userModel->registerUser($this->sanitize($_POST["username"]), $this->sanitize($_POST["password"]) );
|
|
if ($erg["success"] == true) {
|
|
header("Location: ?controller=User&do=showUserLoginForm");
|
|
exit();
|
|
}
|
|
else {
|
|
$this->view->setDoMethodName("showUserRegisterForm");
|
|
|
|
$message = $this->sanitize($erg['message']);
|
|
echo "<script type='text/javascript'>alert(\"$message\");</script>";
|
|
$this->view->setVars([
|
|
"errmsg" => $message
|
|
]);
|
|
$this->showUserRegisterForm();
|
|
}
|
|
}
|
|
|
|
public function showUserLoginForm()
|
|
{
|
|
|
|
}
|
|
|
|
public function showUserRegisterForm()
|
|
{
|
|
|
|
}
|
|
|
|
function sanitize($data, $flags = ENT_QUOTES, $encoding = 'UTF-8') {
|
|
return htmlspecialchars((string)$data, $flags, $encoding);
|
|
}
|
|
}
|