first commit

This commit is contained in:
2026-10-29 13:34:31 +07:00
commit 45e4595c57
255 changed files with 35457 additions and 0 deletions
+147
View File
@@ -0,0 +1,147 @@
<?php
/*******************************************************************
PHP Class : /Controller/AuthController
Description : Kontrol Login Session & Auth Supervisi
Created By : Siau Pheng ([email protected]).
Created Date : January 15th, 2008.
Last Modified : October 21st, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace App\Controller;
use flight\Engine;
use flight\Session;
use flight\database\SimplePdo;
use Webapp\App\Auth;
use Webapp\Web\Param;
use Webapp\Web\Menu;
class AuthController {
private array $aapp;
private array $auser;
private array $ainv;
protected Engine $app;
protected Session $session;
protected SimplePdo $db;
protected Auth $auth;
public function __construct(Engine $app, Session $session, SimplePdo $db) {
$this->app = $app;
$this->db = $db;
$this->session = $session;
$this->auth = new Auth($app);
$this->aapp = $this->session->get('WEB_APP') ?? [];
$this->auser = $this->session->get('WEB_USER') ?? [];
$this->ainv = $this->session->get('APP_INV') ?? [];
}
public function login() {
$ajson['status'] = false;
$auser = [];
if ($this->auth->user_check(Param::Get("Username"), Param::Get("Password"))) {
$auser = $this->auth->user_data(Param::Get("Username"));
//MONITOR DISPLAY
if (($this->ainv['MON_ENABLE'] ?? false) && ($auser['UserID'] ?? false)) {
$this->auth->pos_login($this->ainv['CABANGID'], $auser['UserID'], $auser['UNIX'], $this->app->request()->ip);
}
$this->session->set('WEB_USER', $auser);
if (Param::Get("redir", "") !== "") {
$_redir = $this->auth->redirect(Param::Get("redir"));
//jika kosong, tampilkan pesan redirect tidak diijinkan
//jika berisi, js harus redirect ...
}
$ajson['status'] = true;
$ajson['token'] = $this->session->get('APP_TOKEN');
$ajson['message'] = '<div class="border border-success p-2 pt-3"><h5>Login berhasil,</h5><p><b>'.$auser["Username"].'</b> / '.$auser["Nama"].'<br>'.$auser["Posisi"].'<br><i>login terakhir :</i><br>'.tgl_sql2str($auser["Last_Date"],true).'<br>'.$auser["Last_IP"].'</p></div>';
} else {
$ajson['message'] = "Periksa kembali ID Pengguna atau Password Anda ...";
}
$this->app->json($ajson);
}
public function logout() {
$ajson['status'] = false;
//MONITOR DISPLAY
if (($this->ainv['MON_ENABLE'] ?? false) && ($this->auser['UserID'] ?? false)) {
$this->auth->pos_logout($this->ainv['CABANGID'], $this->auser['UserID'], $this->auser['UNIX'], $this->app->request()->ip);
}
$this->auth->logout();
$this->session->clear();
$_host = $this->app->request()->getVar('HTTP_ORIGIN') ?? $this->aapp['PARENT_SITE'];
$_host = str_replace(['http://','https://'], "", $_host);
if ($this->aapp['PARENT_SUB'] === true) {
$_subs = explode('.', $_host);
if (count($_subs) > 2) array_shift($_subs);
$_host = implode('.', $_subs);
}
$ajson['nexthost'] = "//" . $_host;
$this->app->json($ajson);
}
public function menu() {
$page = Param::Get("p", "");
$query = Param::Get("q", "");
$ajson['login'] = false;
if (count($this->auser) > 0 && !empty($page)) {
$ajson = Menu::MenuJSON($this->db, $page, $query);
}
$this->app->json($ajson);
}
public function supervisi() {
$data = Param::Get("data", "");
$ajson = ['status' => 0, 'pesan' => ""];
if ($data == "super-check") {
$bsuper = (Param::Get("SUPER","true") == "true") ? true : false;
$buover = (Param::Get("UOVER","false") == "true") ? true : false;
if (!$this->auth->user_check_level(Param::Get("UID"), $this->aapp['AUTH_LEVEL']) && $bsuper == true) {
$ajson['status'] = 0;
$ajson['pesan'] = "Silakan hubungi Supervisor / Administrator Anda!";
} else {
if (!$this->auth->user_check(Param::Get("UID"), Param::Get("PWD"))) {
$ajson['status'] = 0;
$ajson['pesan'] = "User ID atau Password Anda Salah!<br>Anda tidak diijinkan melanjutkan proses!";
} else {
$ajson['status'] = 1;
if ($buover == true && $bsuper == false && Param::Get("UID") <> $this->auser['Username']) {
$new_sess = $this->auth->user_data(Param::Get("UID"));
$tmp_sess = $this->session->get('WEB_USER');
foreach ($new_sess as $_key => $_val) {
if ($tmp_sess[$_key]) $tmp_sess[$_key] = $_val;
}
$this->session->set('WEB_USER', $tmp_sess);
}
}
}
} elseif ($data == "super-request") {
$this->db->delete('app_auth', 'UserID=? AND Kode=? AND SID=? AND REQ=? AND Auth=0', [$this->auser['UserID'], Param::Get("KODE"), Param::Get("REQ_SID"), Param::Get("REQ")]);
$this->db->runQuery('INSERT INTO app_auth (UserID, Kode, SID, REQ, Catatan, Tanggal) VALUES (?, ?, ?, ?, ?, NOW())', [ $this->auser['UserID'], Param::Get("KODE"), Param::Get("REQ_SID"), Param::Get("REQ"), Param::Get("MSG") ]);
} elseif ($data == "super-cancel") {
$this->db->delete('app_auth', 'UserID=? AND Kode=? AND SID=? AND REQ=?', [$this->auser['UserID'], Param::Get("KODE"), Param::Get("REQ_SID"), Param::Get("REQ")]);
} elseif ($data == "request-check") {
$_auth = (int) $this->db->fetchField('SELECT Auth FROM app_auth WHERE UserID=? AND Kode=? AND SID=? AND REQ=?', [$this->auser['UserID'], Param::Get("KODE"), Param::Get("REQ_SID"), Param::Get("REQ")]) ?? 0;
if ($_auth == 1) $ajson['status'] = 1;
}
$this->app->json($ajson);
}
}