adding user class
This commit is contained in:
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
|
|
||||||
Module : /Web/Auth.php
|
Module : /App/Auth.php
|
||||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||||
Created Date : March 16th, 2008.
|
Created Date : March 16th, 2008.
|
||||||
Last Modified : September 3rd, 2026.
|
Last Modified : September 10th, 2026.
|
||||||
|
|
||||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Webapp\Web;
|
namespace Webapp\App;
|
||||||
|
|
||||||
use \flight\Engine;
|
use \flight\Engine;
|
||||||
use \flight\Session;
|
use \flight\Session;
|
||||||
@@ -27,7 +27,7 @@ use \flight\database\SimplePdo;
|
|||||||
* @license MIT, https://www.3fonia.com
|
* @license MIT, https://www.3fonia.com
|
||||||
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
||||||
*
|
*
|
||||||
* @package Webapp\Web
|
* @package Webapp\App
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final class Auth {
|
final class Auth {
|
||||||
@@ -56,9 +56,13 @@ final class Auth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function user_data(string $user): array {
|
public function user_data(string $user): array {
|
||||||
$adata = $this->db->fetchRow('SELECT *,DECODE(Menu,?) Menu2 FROM app_operator WHERE Username=?', [$this->id_reg, $user])->getData();
|
$adata = [ 'Grup_MenuID' => 0 ];
|
||||||
|
$xdata = $this->db->fetchRow('SELECT *,DECODE(Menu,?) Menu2 FROM app_operator WHERE Username=?', [$this->id_reg, $user]);
|
||||||
|
if ($xdata) {
|
||||||
|
$adata = $xdata->getData();
|
||||||
$adata['Menu'] = $adata['Menu2'];
|
$adata['Menu'] = $adata['Menu2'];
|
||||||
unset($adata['Menu2']);
|
unset($adata['Menu2'], $adata['Password']);
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($this->session->get('APP_TOKEN'))) {
|
if (empty($this->session->get('APP_TOKEN'))) {
|
||||||
$_token = $this->genToken(60);
|
$_token = $this->genToken(60);
|
||||||
@@ -104,8 +108,7 @@ final class Auth {
|
|||||||
public function user_log(): void {
|
public function user_log(): void {
|
||||||
$_user_id = $this->session->get('WEB_USER')['UserID'] ?? 0;
|
$_user_id = $this->session->get('WEB_USER')['UserID'] ?? 0;
|
||||||
if ($_user_id === 0) return;
|
if ($_user_id === 0) return;
|
||||||
$x_hasil = $this->db->fetchRow('SELECT * FROM app_logs WHERE UserID=? ORDER BY Last_Date DESC LIMIT 1', [$_user_id]);
|
$a_hasil = $this->db->fetchRow('SELECT * FROM app_logs WHERE UserID=? ORDER BY Last_Date DESC LIMIT 1', [$_user_id])->getData();
|
||||||
$a_hasil = ($x_hasil) ? $x_hasil->getData() : [];
|
|
||||||
if (count($a_hasil) > 0) {
|
if (count($a_hasil) > 0) {
|
||||||
$this->db->update('app_operator', [ 'Last_IP' => $a_hasil['Last_IP'], 'Last_Date' => $a_hasil['Last_Date'] ], 'UserID=?', [$_user_id]);
|
$this->db->update('app_operator', [ 'Last_IP' => $a_hasil['Last_IP'], 'Last_Date' => $a_hasil['Last_Date'] ], 'UserID=?', [$_user_id]);
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
|
|
||||||
Module : /Web/Register.php
|
Module : /App/Register.php
|
||||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||||
Created Date : November 23th, 2011.
|
Created Date : November 23th, 2011.
|
||||||
Last Modified : August 22nd, 2026.
|
Last Modified : September 10th, 2026.
|
||||||
|
|
||||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Webapp\Web;
|
namespace Webapp\App;
|
||||||
|
|
||||||
use \flight\Engine;
|
use \flight\Engine;
|
||||||
use \flight\Session;
|
use \flight\Session;
|
||||||
@@ -27,30 +27,30 @@ use \flight\database\SimplePdo;
|
|||||||
* @license MIT, https://www.3fonia.com
|
* @license MIT, https://www.3fonia.com
|
||||||
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
||||||
*
|
*
|
||||||
* @package Webapp\Web
|
* @package Webapp\App
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final class Register {
|
final class Register {
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function reg_id(Session $session) {
|
public static function reg_id(Session $session): string {
|
||||||
$id = (string)$session->get('WEB_APP', ['REG_ID'=>''])['REG_ID'];
|
$id = (string) $session->get('WEB_APP', ['REG_ID'=>''])['REG_ID'];
|
||||||
return (substr($id,0,3).".".substr($id,3,3).".".substr($id,6));
|
return (substr($id,0,3).".".substr($id,3,3).".".substr($id,6));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function reg_code(Session $session) {
|
public static function reg_code(Session $session): string {
|
||||||
$id = (string)$session->get('WEB_APP', ['REG_CODE'=>''])['REG_CODE'];
|
$id = (string) $session->get('WEB_APP', ['REG_CODE'=>''])['REG_CODE'];
|
||||||
return (substr($id,0,6)."-".substr($id,6,5)."-".substr($id,11,5)."-".substr($id,16,5)."-".substr($id,21,5)."-".substr($id,26,6));
|
return (substr($id,0,6)."-".substr($id,6,5)."-".substr($id,11,5)."-".substr($id,16,5)."-".substr($id,21,5)."-".substr($id,26,6));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function reg_check(Session $session) {
|
public static function reg_check(Session $session): bool {
|
||||||
$webapp = $session->get('WEB_APP');
|
$webapp = $session->get('WEB_APP');
|
||||||
return (bool)(isset($webapp['REG_STATUS']) && $webapp['REG_STATUS']) ?? false;
|
return (bool) (isset($webapp['REG_STATUS']) && $webapp['REG_STATUS']) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function reg_status(SimplePdo $db, array $apps) {
|
public static function reg_status(SimplePdo $db, array $apps): array {
|
||||||
$kode_db = (bool)$db->fetchField('SELECT UPPER(CONVERT(MD5(CONCAT(REG_YEAR,CONVERT(MD5(CONCAT(REG_ID,REG_NAME)) using latin1),REG_ID,REG_NAME)) using latin1))=REG_CODE FROM app_config WHERE REG_ID=?', [$apps['APP_CODE'] ?? '']);
|
$kode_db = (bool) $db->fetchField('SELECT UPPER(CONVERT(MD5(CONCAT(REG_YEAR,CONVERT(MD5(CONCAT(REG_ID,REG_NAME)) using latin1),REG_ID,REG_NAME)) using latin1))=REG_CODE FROM app_config WHERE REG_ID=?', [$apps['APP_CODE'] ?? '']);
|
||||||
return [ 'REG_STATUS' => $kode_db === true ];
|
return [ 'REG_STATUS' => $kode_db === true ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
|
|
||||||
Module : /Web/Update.php
|
Module : /App/Update.php
|
||||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||||
Created Date : June 14th, 2013.
|
Created Date : June 14th, 2013.
|
||||||
Last Modified : August 22nd, 2026.
|
Last Modified : August 22nd, 2026.
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Webapp\Web;
|
namespace Webapp\App;
|
||||||
|
|
||||||
use \flight\Engine;
|
use \flight\Engine;
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ use \flight\Engine;
|
|||||||
* @license MIT, https://www.3fonia.com
|
* @license MIT, https://www.3fonia.com
|
||||||
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
||||||
*
|
*
|
||||||
* @package Webapp\Web
|
* @package Webapp\App
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final class Update {
|
final class Update {
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
|
||||||
|
Module : /App/User.php
|
||||||
|
Created By : Siau Pheng ([email protected]).
|
||||||
|
Created Date : September 10th, 2026.
|
||||||
|
Last Modified : September 10th, 2026.
|
||||||
|
|
||||||
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||||
|
|
||||||
|
*******************************************************************/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Webapp\App;
|
||||||
|
|
||||||
|
use \flight\Engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class User
|
||||||
|
*
|
||||||
|
* User & Role Class.
|
||||||
|
*
|
||||||
|
* @license MIT, https://www.3fonia.com
|
||||||
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
|
||||||
|
*
|
||||||
|
* @package Webapp\App
|
||||||
|
*/
|
||||||
|
|
||||||
|
final class User {
|
||||||
|
private array $web_user;
|
||||||
|
protected Engine $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Engine $app
|
||||||
|
*/
|
||||||
|
public function __construct(Engine $app) {
|
||||||
|
$this->app = $app;
|
||||||
|
$this->web_user = (array) $app->session()->get('WEB_USER');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logged(): bool {
|
||||||
|
return !empty($this->web_user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_level(int $level = 9): bool {
|
||||||
|
if (($this->web_user['Level'] ?? 9) <= $level) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function not_level(int $level = 9): bool {
|
||||||
|
if (($this->web_user['Level'] ?? 9) !== $level) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function id(int $digit = 0): string|int {
|
||||||
|
$id_user = (int) $this->web_user['UserID'] ?? 0;
|
||||||
|
if ($digit > 0) return isi_nol($id_user, $digit);
|
||||||
|
return $id_user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function username(): string {
|
||||||
|
return (string) $this->web_user['Username'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function level(): int {
|
||||||
|
return (int) $this->web_user['Level'] ?? 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unix(): string {
|
||||||
|
return (string) $this->web_user['UNIX'] ?? '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nama(): string {
|
||||||
|
return (string) $this->web_user['Nama'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user