60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
use PhangoApp\WPDO;
|
|
use PhaTemplates\Templates;
|
|
|
|
class TplController extends PhangoApp\PhaRouter\Controller {
|
|
|
|
public $tpl;
|
|
public $db;
|
|
|
|
public function __construct() {
|
|
|
|
session_start();
|
|
|
|
$useradmin=new WPDO\WTable('useradmin', ['id', 'username', 'password', 'email', 'double_auth', 'auth_token']);
|
|
|
|
$login_tries=new WPDO\WTable('login_tries', ['ip', 'num_tries', 'date']);
|
|
|
|
$this->db=new WPDO\WPDO(['useradmin' => $useradmin, 'login_tries' => $login_tries]);
|
|
|
|
$this->tpl=new Templates(['theme/admin/templates', 'modules/admin/templates']);
|
|
|
|
}
|
|
|
|
public function check_login() {
|
|
|
|
if(isset($_SESSION['admin_login'])) {
|
|
|
|
if(isset($_SESSION['double_auth']) && $this->path_info!='/admin/app/check_auth') {
|
|
|
|
header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin', 'app', ['check_auth']));
|
|
die;
|
|
|
|
} else {
|
|
|
|
$now=date("Y-m-d H:i:s");
|
|
|
|
$timestamp_5_min=strtotime($now)-300;
|
|
$timestamp_last_login=strtotime($_SESSION['date_login']);
|
|
|
|
if($timestamp_5_min>$timestamp_last_login) {
|
|
|
|
header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin', 'app', ['logout']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|