Initial import
This commit is contained in:
119
one-api/application/controllers/v1/system/Auth.php
Normal file
119
one-api/application/controllers/v1/system/Auth.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
class Auth extends MY_Controller {
|
||||
var $db_regional;
|
||||
public function index()
|
||||
{
|
||||
echo "AUTH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
$this->db_log = $this->load->database("regional_log", true);
|
||||
}
|
||||
function isLogin() {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
} else {
|
||||
$prm = $this->sys_input;
|
||||
$data = array(
|
||||
"user" => $this->sys_user
|
||||
);
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
}
|
||||
function login() {
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
//existing password enc
|
||||
$sm_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
|
||||
$query = $this->db_regional->query("select M_UserID,M_UserUsername, M_UserGroupDashboard, M_UserDefaultT_SampleStationID,
|
||||
M_StaffName,M_UserGroupID
|
||||
from m_user
|
||||
join m_usergroup ON M_UserM_UserGroupID = M_UserGroupID
|
||||
left join m_staff on M_UserM_StaffID = M_StaffID
|
||||
where M_UserUsername=? and M_UserPassword=?
|
||||
and M_UserIsActive = 'Y'
|
||||
",array($prm["username"], $sm_password));
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$user = $rows[0];
|
||||
$user['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$token = JWT::encode($user,$this->SECRET_KEY);
|
||||
$data = array(
|
||||
"user" => $user,
|
||||
"token" => $token
|
||||
);
|
||||
|
||||
$query = $this->db_regional->query("update m_user SET M_UserIsLoggedIn = 'Y', M_UserLastAccess = now(), M_UserActiveToken = '{$token}' WHERE M_UserID = ?
|
||||
",array($user['M_UserID']));
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'],'LOGIN','SUCCESS',$prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($data);
|
||||
exit;
|
||||
}
|
||||
$query = $this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
",array(date('Y-m-d H:i:s'),$this->input->ip_address(),'LOGIN','FAILED',$prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$this->sys_error_db("Invalid UserName / Password");
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try
|
||||
{
|
||||
|
||||
$query = $this->db_regional->query("
|
||||
UPDATE m_user
|
||||
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
|
||||
WHERE M_UserID = ?",
|
||||
array($this->sys_user['M_UserID']));
|
||||
|
||||
if (!$query)
|
||||
{
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $this->sys_user['M_UserUsername']));
|
||||
$this->sys_ok("OK");
|
||||
|
||||
}
|
||||
catch(Exception $exc)
|
||||
{
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
156
one-api/application/controllers/v1/system/Menu.php
Normal file
156
one-api/application/controllers/v1/system/Menu.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
class Menu extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
function change_password() {
|
||||
$prm = $this->sys_input;
|
||||
if ( ! $this->isLogin ) {
|
||||
echo json_encode(
|
||||
array("status"=>"ERR", "message"=> "Invalid Token")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$sm_password = md5($this->one_salt . $prm["old"] . $this->one_salt);
|
||||
$userID = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = $this->db_regional->query("select * from m_user where M_UserID = ? and M_UserPassword = ?",
|
||||
array($userID, $sm_password) );
|
||||
if(!$query) {
|
||||
echo json_encode(
|
||||
array("status"=>"ERR", "message"=> "Invalid Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
if(count($rows) == 0 ) {
|
||||
echo json_encode(
|
||||
array("status"=>"ERR", "message"=> "Invalid Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$new_password = md5($this->one_salt . $prm["new"] . $this->one_salt);
|
||||
$query = $this->db_regional->query("update m_user set M_UserPassword=? where M_UserID = ?",
|
||||
array($new_password,$userID) );
|
||||
if(!$query) {
|
||||
echo json_encode(
|
||||
array("status"=>"ERR", "message"=> "Invalid Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
echo json_encode( array("status"=>"OK", "message"=>""));
|
||||
}
|
||||
function get_bread_crumb_v2() {
|
||||
$prm = $this->sys_input;
|
||||
/*
|
||||
if ( ! $this->is_login ) {
|
||||
echo json_encode(
|
||||
array("status"=>"ERR", "message"=> "Invalid Token","data"=>$data)
|
||||
);
|
||||
}
|
||||
*/
|
||||
$xpath = parse_url($prm["xref"]);
|
||||
$path = $xpath["path"];
|
||||
if ( substr($path,-1) == "/" ) $path = substr($path,0, strlen($path) - 1);
|
||||
$path = str_replace("/one-ui/","",$path);
|
||||
$path = str_replace("one-ui/","",$path);
|
||||
echo "path : $path \n";
|
||||
$user_id = $this->sys_user['M_UserID'];
|
||||
// get bread_crumb
|
||||
$sql = "select fn_sys_breadcrumb(?,?) as breadcrumb";
|
||||
$qry = $this->db_regional->query($sql,array($path,$user_id));
|
||||
$rows = $qry->result();
|
||||
$breadcrumb = "";
|
||||
$is_page_allowed = false;
|
||||
$dashboard = "one-ui/";
|
||||
if (count($rows) > 0 ) {
|
||||
$breadcrumb = $rows[0]->breadcrumb;
|
||||
if ($breadcrumb != "" ) $is_page_allowed = true;
|
||||
}
|
||||
$data = array(
|
||||
"bread_crumb" => $breadcrumb,
|
||||
"dashboard" => $dashboard,
|
||||
"is_page_allowed" => $is_page_allowed
|
||||
);
|
||||
echo json_encode(
|
||||
array("status"=>"OK", "data"=>$data)
|
||||
);
|
||||
|
||||
}
|
||||
function get_bread_crumb() {
|
||||
$prm = $this->sys_input;
|
||||
/*
|
||||
if ( ! $this->is_login ) {
|
||||
echo json_encode(
|
||||
array("status"=>"ERR", "message"=> "Invalid Token","data"=>$data)
|
||||
);
|
||||
}
|
||||
*/
|
||||
$xpath = parse_url($prm["xref"]);
|
||||
$path = $xpath["path"];
|
||||
if ( substr($path,-1) == "/" ) $path = substr($path,0, strlen($path) - 1);
|
||||
$path = str_replace("/one-ui/","",$path);
|
||||
$path = str_replace("one-ui/","",$path);
|
||||
|
||||
$user_id = $this->sys_user['M_UserID'];
|
||||
// get bread_crumb
|
||||
$sql = "select fn_sys_breadcrumb(?,?) as breadcrumb";
|
||||
$qry = $this->db_regional->query($sql,array($path,$user_id));
|
||||
file_put_contents("/xtmp/fx-last_query","\n" . $this->db_regional->last_query() );
|
||||
$rows = $qry->result();
|
||||
$breadcrumb = "";
|
||||
$is_page_allowed = false;
|
||||
$dashboard = "one-ui/test/vuex/one-fo-verification";
|
||||
if (count($rows) > 0 ) {
|
||||
$breadcrumb = $rows[0]->breadcrumb;
|
||||
if ($breadcrumb != "" ) $is_page_allowed = true;
|
||||
}
|
||||
$data = array(
|
||||
"bread_crumb" => $breadcrumb,
|
||||
"dashboard" => $dashboard,
|
||||
"is_page_allowed" => $is_page_allowed
|
||||
);
|
||||
echo json_encode(
|
||||
array("status"=>"OK", "data"=>$data)
|
||||
);
|
||||
|
||||
}
|
||||
function get_menu()
|
||||
{
|
||||
$sql = "CALL sp_sys_menu_user('{$this->sys_user['M_UserID']}')";
|
||||
// $query = $this->db_regional->query($sql);
|
||||
|
||||
$index = 0;
|
||||
$ResultSet = array();
|
||||
|
||||
/* execute multi query */
|
||||
if (mysqli_multi_query($this->db_regional->conn_id, $sql)) {
|
||||
do {
|
||||
if (false != $result = mysqli_store_result($this->db_regional->conn_id)) {
|
||||
$rowID = 0;
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$x = json_decode($row['x']);
|
||||
|
||||
foreach ($x as $k => $v)
|
||||
{
|
||||
if (!isset($ResultSet[$index]['p_'.$v->parent_id]))
|
||||
$ResultSet[$index]['p_'.$v->parent_id] = [];
|
||||
|
||||
$ResultSet[$index]['p_'.$v->parent_id][] = $v;
|
||||
}
|
||||
// $ResultSet[$index] =
|
||||
// $rowID++;
|
||||
}
|
||||
}
|
||||
$index++;
|
||||
} while (mysqli_next_result($this->db_regional->conn_id));
|
||||
}
|
||||
|
||||
echo json_encode(["status"=>"OK", "data"=>$ResultSet]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user