mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Commit realizando cambios en los roles de los usuarios
This commit is contained in:
86
ci4/app/Controllers/Activity.php
Normal file
86
ci4/app/Controllers/Activity.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ActivityModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class Activity extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $activity_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->activity_model = new ActivityModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$session = session();
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.activity_title"),
|
||||
'page' => lang("App.activity_subtitle"),
|
||||
'icon' => 'fas fa-list'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.activity_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['logs'] = $this->activity_model->select('SUM( IF( os LIKE "%Windows%", 1, 0 ) ) AS windows,
|
||||
SUM( IF( os = "Mac OS X", 1, 0 ) ) AS mac,
|
||||
SUM( IF( os = "Linux", 1, 0 ) ) AS linux,
|
||||
SUM( IF( os = "Android", 1, 0 ) ) AS android,
|
||||
SUM( IF( os = "iOS", 1, 0 ) ) AS iphone,
|
||||
SUM( IF( browser LIKE "%Chrome%", 1, 0 ) ) AS chrome,
|
||||
SUM( IF( browser LIKE "%Firefox%", 1, 0 ) ) AS firefox,
|
||||
SUM( IF( browser LIKE "%Safari%", 1, 0 ) ) AS safari,
|
||||
SUM( IF( browser LIKE "%Internet Explorer%", 1, 0 ) ) AS ie,
|
||||
SUM( IF( browser LIKE "%Edge%", 1, 0 ) ) AS edge,
|
||||
SUM( IF( browser LIKE "%Opera%", 1, 0 ) ) AS opera')->where('activity.user',$session->get('token'))->first();
|
||||
$data['all'] = "";
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/activity/index',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
$session = session();
|
||||
$dashboard = $session->get('dashboard')??'user';
|
||||
if($dashboard != 'admin'){
|
||||
return redirect()->to('/activity');
|
||||
}
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.activity_title"),
|
||||
'page' => lang("App.activity_subtitle"),
|
||||
'icon' => 'fas fa-list'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.activity_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['logs'] = $this->activity_model->select('SUM( IF( os LIKE "%Windows%", 1, 0 ) ) AS windows,
|
||||
SUM( IF( os = "Mac OS X", 1, 0 ) ) AS mac,
|
||||
SUM( IF( os = "Linux", 1, 0 ) ) AS linux,
|
||||
SUM( IF( os = "Android", 1, 0 ) ) AS android,
|
||||
SUM( IF( os = "iOS", 1, 0 ) ) AS iphone,
|
||||
SUM( IF( browser LIKE "%Chrome%", 1, 0 ) ) AS chrome,
|
||||
SUM( IF( browser LIKE "%Firefox%", 1, 0 ) ) AS firefox,
|
||||
SUM( IF( browser LIKE "%Safari%", 1, 0 ) ) AS safari,
|
||||
SUM( IF( browser LIKE "%Internet Explorer%", 1, 0 ) ) AS ie,
|
||||
SUM( IF( browser LIKE "%Edge%", 1, 0 ) ) AS edge,
|
||||
SUM( IF( browser LIKE "%Opera%", 1, 0 ) ) AS opera')->first();
|
||||
$data['all'] = "/all";
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/activity/index',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
}
|
||||
488
ci4/app/Controllers/Ajax.php
Normal file
488
ci4/app/Controllers/Ajax.php
Normal file
@ -0,0 +1,488 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\CronTabModel;
|
||||
use App\Models\NotificationModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Models\UserGroupModel;
|
||||
use App\Models\GroupUserModel;
|
||||
use App\Models\ActivityModel;
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
|
||||
class Ajax extends ResourceController
|
||||
{
|
||||
private $user_model;
|
||||
private $group_model;
|
||||
private $group_user_model;
|
||||
private $activity_model;
|
||||
private $crontab_model;
|
||||
private $notification_model;
|
||||
private $id_user;
|
||||
private $token_user;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->group_model = new UserGroupModel();
|
||||
$this->group_user_model = new GroupUserModel();
|
||||
$this->activity_model = new ActivityModel();
|
||||
$this->crontab_model = new CronTabModel();
|
||||
$this->notification_model = new NotificationModel();
|
||||
$this->id_user = session()->get('id_user');
|
||||
$this->token_user = session()->get('token');
|
||||
$language = \Config\Services::language();
|
||||
$language->setLocale(session()->lang);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return redirect()->to('/home');
|
||||
}
|
||||
|
||||
public function getUsers(){
|
||||
$postData = service('request')->getVar();
|
||||
if($postData != null && isset($postData->data)){
|
||||
$dtpostData = $postData->data;
|
||||
|
||||
//Read value
|
||||
$draw = $dtpostData->draw;
|
||||
$start = $dtpostData->start;
|
||||
$rowperpage = $dtpostData->length; // Rows display per page
|
||||
$columnIndex = $dtpostData->order[0]->column; // Column index
|
||||
$columnName = $dtpostData->columns[$columnIndex]->data; // Column name
|
||||
$columnSortOrder = $dtpostData->order[0]->dir; // asc or desc
|
||||
$searchValue = $dtpostData->search->value; // Search value
|
||||
|
||||
//Total number of records without filtering
|
||||
$totalRecords = $this->user_model->select('id_user')
|
||||
->join('auth_user_group','auth_user_group.token = auth_user.group')
|
||||
->countAllResults();
|
||||
|
||||
//Total number of records with filtering
|
||||
$totalRecordwithFilter = $this->user_model->select('id_user')
|
||||
->join('auth_user_group','auth_user_group.token = auth_user.group')
|
||||
->orLike('first_name', $searchValue)
|
||||
->orLike('email', $searchValue)
|
||||
->countAllResults();
|
||||
|
||||
//Fetch records
|
||||
$records = $this->user_model->select('auth_user.*,auth_user_group.title')
|
||||
->join('auth_user_group','auth_user_group.token = auth_user.group')
|
||||
->orLike('first_name', $searchValue)
|
||||
->orLike('email', $searchValue)
|
||||
->orderBy($columnName,$columnSortOrder)
|
||||
->findAll($rowperpage, $start);
|
||||
|
||||
//Format records
|
||||
foreach ($records as $key => $value){
|
||||
if($records[$key]['email_confirmed'] == 1){
|
||||
$records[$key]['email'] = $records[$key]['email'].' '.'<span class="text-success"><i class="fas fa-check-circle"></i></span>';
|
||||
}
|
||||
$editLink = site_url('user/edit/').$records[$key]['token'];
|
||||
$records[$key]['options'] = ''.
|
||||
'<div class="btn-group mr-1 mb-1" xmlns="http://www.w3.org/1999/html">
|
||||
<button type="button" class="btn btn-primary btn-block dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
'.lang("App.user_grid_options").'
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="'.$editLink.'"><i class="fas fa-edit"></i> '.lang("App.user_btn_edit").'</a>
|
||||
<button type="button" class="dropdown-item" onclick="delete_user(\''.$records[$key]['token'].'\');"><i class="fas fa-trash"></i> '.lang("App.user_btn_delete").'</button>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
//Data records
|
||||
$data = array();
|
||||
foreach($records as $record ){
|
||||
$data[] = array(
|
||||
"first_name"=>$record['first_name'],
|
||||
"email"=>$record['email'],
|
||||
"group"=>$record['title'],
|
||||
"mobile"=>$record['mobile'],
|
||||
"last_access"=>$record['last_access'],
|
||||
"last_ip"=>$record['last_ip'],
|
||||
"created_at"=>$record['created_at'],
|
||||
"options"=>$record['options']
|
||||
);
|
||||
}
|
||||
|
||||
//Response
|
||||
$response = array(
|
||||
"draw" => intval($draw),
|
||||
"iTotalRecords" => $totalRecords,
|
||||
"iTotalDisplayRecords" => $totalRecordwithFilter,
|
||||
"aaData" => $data,
|
||||
"token" => csrf_hash() // New token hash
|
||||
);
|
||||
return $this->response->setJSON($response);
|
||||
}else{
|
||||
return $this->response->setJSON(["error"=>true]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getGroups(){
|
||||
$postData = service('request')->getVar();
|
||||
if($postData != null && isset($postData->data)){
|
||||
$dtpostData = $postData->data;
|
||||
|
||||
//Read value
|
||||
$draw = $dtpostData->draw;
|
||||
$start = $dtpostData->start;
|
||||
$rowperpage = $dtpostData->length; // Rows display per page
|
||||
$columnIndex = $dtpostData->order[0]->column; // Column index
|
||||
$columnName = $dtpostData->columns[$columnIndex]->data; // Column name
|
||||
$columnSortOrder = $dtpostData->order[0]->dir; // asc or desc
|
||||
$searchValue = $dtpostData->search->value; // Search value
|
||||
|
||||
//Total number of records without filtering
|
||||
$totalRecords = $this->group_model->select('id_group')
|
||||
->countAllResults();
|
||||
|
||||
//Total number of records with filtering
|
||||
$totalRecordwithFilter = $this->group_model->select('id_group')
|
||||
->orLike('title', $searchValue)
|
||||
->countAllResults();
|
||||
|
||||
//Fetch records
|
||||
$records = $this->group_model->select('*')
|
||||
->orLike('title', $searchValue)
|
||||
->orderBy($columnName,$columnSortOrder)
|
||||
->findAll($rowperpage, $start);
|
||||
|
||||
//Format records
|
||||
foreach ($records as $key => $value){
|
||||
$editLink = site_url('group/edit/').$records[$key]['token'];
|
||||
$records[$key]['options'] = ''.
|
||||
'<div class="btn-group mr-1 mb-1" xmlns="http://www.w3.org/1999/html">
|
||||
<button type="button" class="btn btn-primary btn-block dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
'.lang("App.group_grid_options").'
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="'.$editLink.'"><i class="fas fa-edit"></i> '.lang("App.group_btn_edit").'</a>
|
||||
<button type="button" class="dropdown-item" onclick="delete_group(\''.$records[$key]['token'].'\');"><i class="fas fa-trash"></i> '.lang("App.group_btn_delete").'</button>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
//Data records
|
||||
$data = array();
|
||||
foreach($records as $record ){
|
||||
$data[] = array(
|
||||
"title"=>$record['title'],
|
||||
"dashboard"=>$record['dashboard'],
|
||||
"created_at"=>$record['created_at'],
|
||||
"updated_at"=>$record['updated_at'],
|
||||
"options"=>$record['options']
|
||||
);
|
||||
}
|
||||
|
||||
//Response
|
||||
$response = array(
|
||||
"draw" => intval($draw),
|
||||
"iTotalRecords" => $totalRecords,
|
||||
"iTotalDisplayRecords" => $totalRecordwithFilter,
|
||||
"aaData" => $data,
|
||||
"token" => csrf_hash() // New token hash
|
||||
);
|
||||
return $this->response->setJSON($response);
|
||||
}else{
|
||||
return $this->response->setJSON(["error"=>true]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getActivities($all=""){
|
||||
$postData = service('request')->getVar();
|
||||
if($postData != null && isset($postData->data)){
|
||||
$dtpostData = $postData->data;
|
||||
|
||||
//Read value
|
||||
$draw = $dtpostData->draw;
|
||||
$start = $dtpostData->start;
|
||||
$rowperpage = $dtpostData->length; // Rows display per page
|
||||
$columnIndex = $dtpostData->order[0]->column; // Column index
|
||||
$columnName = $dtpostData->columns[$columnIndex]->data; // Column name
|
||||
$columnSortOrder = $dtpostData->order[0]->dir; // asc or desc
|
||||
$searchValue = $dtpostData->search->value; // Search value
|
||||
|
||||
$session = session();
|
||||
|
||||
//Total number of records without filtering
|
||||
if($session->get('dashboard')=='admin' && !empty($all)){
|
||||
$totalRecords = $this->activity_model->select('id_activity')
|
||||
->join('user','user.token = activity.user')
|
||||
->countAllResults();
|
||||
}else{
|
||||
$totalRecords = $this->activity_model->select('id_activity')
|
||||
->join('user','user.token = activity.user')
|
||||
->where('activity.user',$session->get('token'))
|
||||
->countAllResults();
|
||||
}
|
||||
|
||||
//Total number of records with filtering
|
||||
if($session->get('dashboard')=='admin' && !empty($all)){
|
||||
$totalRecordwithFilter = $this->activity_model->select('id_activity')
|
||||
->join('user','user.token = activity.user')
|
||||
->orLike('first_name', $searchValue)
|
||||
->countAllResults();
|
||||
}else{
|
||||
$totalRecordwithFilter = $this->activity_model->select('id_activity')
|
||||
->join('user','user.token = activity.user')
|
||||
->orLike('first_name', $searchValue)
|
||||
->where('activity.user',$session->get('token'))
|
||||
->countAllResults();
|
||||
}
|
||||
|
||||
//Fetch records
|
||||
if($session->get('dashboard')=='admin' && !empty($all)){
|
||||
$records = $this->activity_model->select('activity.*,concat(first_name, " (",email, ")") AS name')
|
||||
->join('user','user.token = activity.user')
|
||||
->orLike('first_name', $searchValue)
|
||||
->orderBy($columnName,$columnSortOrder)
|
||||
->findAll($rowperpage, $start);
|
||||
}else{
|
||||
$records = $this->activity_model->select('activity.*,concat(first_name, " (",email, ")") AS name')
|
||||
->join('user','user.token = activity.user')
|
||||
->orLike('first_name', $searchValue)
|
||||
->where('activity.user',$session->get('token'))
|
||||
->orderBy($columnName,$columnSortOrder)
|
||||
->findAll($rowperpage, $start);
|
||||
}
|
||||
|
||||
|
||||
//Data records
|
||||
$data = array();
|
||||
foreach($records as $record ){
|
||||
$data[] = array(
|
||||
"name"=>$record['name'],
|
||||
"level"=>$record['level'],
|
||||
"event"=>$record['event'],
|
||||
"ip"=>$record['ip'],
|
||||
"os"=>$record['os'],
|
||||
"browser"=>$record['browser'],
|
||||
"created_at"=>$record['created_at']
|
||||
);
|
||||
}
|
||||
|
||||
//Response
|
||||
$response = array(
|
||||
"draw" => intval($draw),
|
||||
"iTotalRecords" => $totalRecords,
|
||||
"iTotalDisplayRecords" => $totalRecordwithFilter,
|
||||
"aaData" => $data,
|
||||
"token" => csrf_hash() // New token hash
|
||||
);
|
||||
return $this->response->setJSON($response);
|
||||
}else{
|
||||
return $this->response->setJSON(["error"=>true]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCronHistory(){
|
||||
$postData = service('request')->getVar();
|
||||
if($postData != null && isset($postData->data)){
|
||||
$dtpostData = $postData->data;
|
||||
|
||||
//Read value
|
||||
$draw = $dtpostData->draw;
|
||||
$start = $dtpostData->start;
|
||||
$rowperpage = $dtpostData->length; // Rows display per page
|
||||
$columnIndex = $dtpostData->order[0]->column; // Column index
|
||||
$columnName = $dtpostData->columns[$columnIndex]->data; // Column name
|
||||
$columnSortOrder = $dtpostData->order[0]->dir; // asc or desc
|
||||
$searchValue = $dtpostData->search->value; // Search value
|
||||
|
||||
//Total number of records without filtering
|
||||
$totalRecords = $this->crontab_model->select('id_crontab')
|
||||
->countAllResults();
|
||||
|
||||
//Total number of records with filtering
|
||||
$totalRecordwithFilter = $this->crontab_model->select('id_crontab')
|
||||
->orLike('routine', $searchValue)
|
||||
->orLike('error', $searchValue)
|
||||
->countAllResults();
|
||||
|
||||
//Fetch records
|
||||
$records = $this->crontab_model->select('*')
|
||||
->orLike('routine', $searchValue)
|
||||
->orLike('error', $searchValue)
|
||||
->orderBy($columnName,$columnSortOrder)
|
||||
->findAll($rowperpage, $start);
|
||||
|
||||
//Data records
|
||||
$data = array();
|
||||
foreach($records as $record ){
|
||||
$data[] = array(
|
||||
"routine"=>$record['routine'],
|
||||
"error"=>$record['error'],
|
||||
"created_at"=>$record['created_at']
|
||||
);
|
||||
}
|
||||
|
||||
//Response
|
||||
$response = array(
|
||||
"draw" => intval($draw),
|
||||
"iTotalRecords" => $totalRecords,
|
||||
"iTotalDisplayRecords" => $totalRecordwithFilter,
|
||||
"aaData" => $data,
|
||||
"token" => csrf_hash() // New token hash
|
||||
);
|
||||
return $this->response->setJSON($response);
|
||||
}else{
|
||||
return $this->response->setJSON(["error"=>true]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getNotification(){
|
||||
$postData = service('request')->getVar();
|
||||
if($postData != null && isset($postData->data)){
|
||||
$dtpostData = $postData->data;
|
||||
|
||||
//Read value
|
||||
$draw = $dtpostData->draw;
|
||||
$start = $dtpostData->start;
|
||||
$rowperpage = $dtpostData->length; // Rows display per page
|
||||
$columnIndex = $dtpostData->order[0]->column; // Column index
|
||||
$columnName = $dtpostData->columns[$columnIndex]->data; // Column name
|
||||
$columnSortOrder = $dtpostData->order[0]->dir; // asc or desc
|
||||
$searchValue = $dtpostData->search->value; // Search value
|
||||
|
||||
//Total number of records without filtering
|
||||
$totalRecords = $this->notification_model->select('id_notification')
|
||||
->join('user AS sender','notification.user_sender = sender.token','left')
|
||||
->join('user AS recipient','notification.user_recipient = recipient.token','left')
|
||||
->countAllResults();
|
||||
|
||||
//Total number of records with filtering
|
||||
$totalRecordwithFilter = $this->notification_model->select('id_notification')
|
||||
->join('user AS sender','notification.user_sender = sender.token','left')
|
||||
->join('user AS recipient','notification.user_recipient = recipient.token','left')
|
||||
->orLike('title', $searchValue)
|
||||
->orLike('sender.first_name', $searchValue)
|
||||
->orLike('recipient.first_name', $searchValue)
|
||||
->countAllResults();
|
||||
|
||||
//Fetch records
|
||||
$records = $this->notification_model->select('notification.token, sender.first_name AS sender, recipient.first_name AS recipient, notification.title, is_send_email, is_read, notification.created_at')
|
||||
->join('user AS sender','notification.user_sender = sender.token','left')
|
||||
->join('user AS recipient','notification.user_recipient = recipient.token','left')
|
||||
->orLike('title', $searchValue)
|
||||
->orLike('sender.first_name', $searchValue)
|
||||
->orLike('recipient.first_name', $searchValue)
|
||||
->orderBy($columnName,$columnSortOrder)
|
||||
->findAll($rowperpage, $start);
|
||||
|
||||
//Format records
|
||||
foreach ($records as $key => $value){
|
||||
$records[$key]['options'] = ''.
|
||||
'<div class="btn-group mr-1 mb-1" xmlns="http://www.w3.org/1999/html">
|
||||
<button type="button" class="btn btn-primary btn-block dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
'.lang("App.notification_grid_options").'
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<button type="button" class="dropdown-item" onclick="delete_this(\''.$records[$key]['token'].'\');"><i class="fas fa-trash"></i> '.lang("App.user_btn_delete").'</button>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
//Data records
|
||||
$data = array();
|
||||
foreach($records as $record ){
|
||||
$data[] = array(
|
||||
"sender"=>$record['sender'],
|
||||
"recipient"=>$record['recipient'],
|
||||
"title"=>$record['title'],
|
||||
"is_send_email"=>$record['is_send_email'],
|
||||
"is_read"=>$record['is_read'],
|
||||
"created_at"=>$record['created_at'],
|
||||
"options"=>$record['options']
|
||||
);
|
||||
}
|
||||
|
||||
//Response
|
||||
$response = array(
|
||||
"draw" => intval($draw),
|
||||
"iTotalRecords" => $totalRecords,
|
||||
"iTotalDisplayRecords" => $totalRecordwithFilter,
|
||||
"aaData" => $data,
|
||||
"token" => csrf_hash() // New token hash
|
||||
);
|
||||
return $this->response->setJSON($response);
|
||||
}else{
|
||||
return $this->response->setJSON(["error"=>true]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getMyNotification(){
|
||||
$postData = service('request')->getVar();
|
||||
if($postData != null && isset($postData->data)){
|
||||
$dtpostData = $postData->data;
|
||||
|
||||
//Read value
|
||||
$draw = $dtpostData->draw;
|
||||
$start = $dtpostData->start;
|
||||
$rowperpage = $dtpostData->length; // Rows display per page
|
||||
$columnIndex = $dtpostData->order[0]->column; // Column index
|
||||
$columnName = $dtpostData->columns[$columnIndex]->data; // Column name
|
||||
$columnSortOrder = $dtpostData->order[0]->dir; // asc or desc
|
||||
$searchValue = $dtpostData->search->value; // Search value
|
||||
|
||||
//Total number of records without filtering
|
||||
$totalRecords = $this->notification_model->select('id_notification')
|
||||
->join('user AS sender','notification.user_sender = sender.token','left')
|
||||
->join('user AS recipient','notification.user_recipient = recipient.token','left')
|
||||
->where('user_recipient',$this->token_user)
|
||||
->countAllResults();
|
||||
|
||||
//Total number of records with filtering
|
||||
$totalRecordwithFilter = $this->notification_model->select('id_notification')
|
||||
->join('user AS sender','notification.user_sender = sender.token','left')
|
||||
->join('user AS recipient','notification.user_recipient = recipient.token','left')
|
||||
->orLike('title', $searchValue)
|
||||
->where('user_recipient',$this->token_user)
|
||||
->countAllResults();
|
||||
|
||||
//Fetch records
|
||||
$records = $this->notification_model->select('notification.token, sender.first_name AS sender, recipient.first_name AS recipient, notification.title, is_read, notification.created_at')
|
||||
->join('user AS sender','notification.user_sender = sender.token','left')
|
||||
->join('user AS recipient','notification.user_recipient = recipient.token','left')
|
||||
->orLike('title', $searchValue)
|
||||
->where('user_recipient',$this->token_user)
|
||||
->orderBy($columnName,$columnSortOrder)
|
||||
->findAll($rowperpage, $start);
|
||||
|
||||
//Format records
|
||||
foreach ($records as $key => $value){
|
||||
$records[$key]['options'] = '<a class="btn btn-primary" href="/my/notification_view/'.$records[$key]['token'].'"><i class="fas fa-eye"></i> '.lang("App.notification_view_btn").'</a>';
|
||||
}
|
||||
|
||||
//Data records
|
||||
$data = array();
|
||||
foreach($records as $record ){
|
||||
$data[] = array(
|
||||
"sender"=>$record['sender'],
|
||||
"recipient"=>$record['recipient'],
|
||||
"title"=>$record['title'],
|
||||
"created_at"=>$record['created_at'],
|
||||
"is_read"=>$record['is_read'],
|
||||
"options"=>$record['options']
|
||||
);
|
||||
}
|
||||
|
||||
//Response
|
||||
$response = array(
|
||||
"draw" => intval($draw),
|
||||
"iTotalRecords" => $totalRecords,
|
||||
"iTotalDisplayRecords" => $totalRecordwithFilter,
|
||||
"aaData" => $data,
|
||||
"token" => csrf_hash() // New token hash
|
||||
);
|
||||
return $this->response->setJSON($response);
|
||||
}else{
|
||||
return $this->response->setJSON(["error"=>true]);
|
||||
}
|
||||
}
|
||||
}
|
||||
273
ci4/app/Controllers/Api.php
Normal file
273
ci4/app/Controllers/Api.php
Normal file
@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\PasswordHash;
|
||||
use App\Models\SettingsModel;
|
||||
use App\Models\UserModel;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use CodeIgniter\Validation\Exceptions\ValidationException;
|
||||
use Config\Services;
|
||||
|
||||
class Api extends ResourceController
|
||||
{
|
||||
private $user_model;
|
||||
private $settings_model;
|
||||
private $data_format;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->settings_model = new SettingsModel();
|
||||
$this->data_format = getenv('api.return')??'json';
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->response->setJSON([
|
||||
'message' => 'Welcome!'
|
||||
]);
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->response->setJSON([
|
||||
'status' => true,
|
||||
'message' => 'The system is running!'
|
||||
]);
|
||||
}
|
||||
|
||||
public function signIn()
|
||||
{
|
||||
$rules = [
|
||||
'email' => 'required|valid_email|validateAuthPermission[email]',
|
||||
'password' => 'required|validateAuthPassword[email, password]'
|
||||
];
|
||||
$errors = [
|
||||
'email' => [
|
||||
'required' => 'The email field is required.',
|
||||
'valid_email' => 'Invalid email.',
|
||||
'validateAuthPermission' => 'This user {value} does not have access permission.'
|
||||
],
|
||||
'password' => [
|
||||
'required' => 'The password field is required.',
|
||||
'validateAuthPassword' => 'Invalid password.'
|
||||
]
|
||||
];
|
||||
$input = $this->baseRequest($this->request);
|
||||
if (!$this->baseValidateRequest($input, $rules, $errors)) {
|
||||
return $this->baseResponse($this->validator->getErrors(),ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
return $this->generateCredential($input['email']);
|
||||
}
|
||||
|
||||
private function generateCredential(string $email, int $responseCode = ResponseInterface::HTTP_OK){
|
||||
try {
|
||||
helper('jwt');
|
||||
return $this->baseResponse([
|
||||
'access_token' => jwtSignature($email)
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
return $this->baseResponse(['error' => $exception->getMessage()], $responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
private function baseResponse(array $responseBody, int $code = ResponseInterface::HTTP_OK)
|
||||
{
|
||||
if($this->data_format == 'json'){
|
||||
return $this->response->setStatusCode($code)->setJSON($responseBody)??'';
|
||||
}else{
|
||||
return $this->response->setStatusCode($code)->setXML($responseBody)??'';
|
||||
}
|
||||
}
|
||||
|
||||
private function baseRequest(IncomingRequest $request){
|
||||
return $request->getVar()??[];
|
||||
}
|
||||
|
||||
private function baseValidateRequest(array $input, array $rules, array $messages = []){
|
||||
$this->validator = Services::Validation()->setRules($rules);
|
||||
if (is_string($rules)) {
|
||||
$validation = config('Validation');
|
||||
if (!isset($validation->$rules)) {
|
||||
throw ValidationException::forRuleNotFound($rules);
|
||||
}
|
||||
if (!$messages) {
|
||||
$errorName = $rules . '_errors';
|
||||
$messages = $validation->$errorName ?? [];
|
||||
}
|
||||
$rules = $validation->$rules;
|
||||
}
|
||||
return $this->validator->setRules($rules, $messages)->run($input);
|
||||
}
|
||||
|
||||
public function user($method = null, $key = null)
|
||||
{
|
||||
switch ($method):
|
||||
/**
|
||||
* Return all users.
|
||||
*/
|
||||
case 'all':
|
||||
try {
|
||||
$data = $this->user_model->select('token,first_name,last_name,date_birth,email,mobile,picture,language,address,address,state,country,zip_code,status,created_at,updated_at')->findAll()??[];
|
||||
return $this->setResponseFormat($this->data_format)->respond($data);
|
||||
} catch (\Exception $exception) {
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => $exception->getMessage()
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Return user for token id.
|
||||
*/
|
||||
case 'id':
|
||||
try {
|
||||
$data = $this->user_model->select('token,first_name,last_name,date_birth,email,mobile,picture,language,address,address,state,country,zip_code,status,created_at,updated_at')->where('token',$key)->first()??[];
|
||||
return $this->setResponseFormat($this->data_format)->respond($data);
|
||||
} catch (\Exception $exception) {
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => $exception->getMessage()
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Return add user.
|
||||
*/
|
||||
case 'add':
|
||||
try {
|
||||
$body = $this->request->getVar() == [] ? (array) $this->request->getJSON() : $this->request->getVar();
|
||||
if(empty($body["first_name"]??"")){
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => 'The first name parameter is null or empty.'
|
||||
]);
|
||||
}
|
||||
if(empty($body["last_name"]??"")){
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => 'The last name parameter is null or empty.'
|
||||
]);
|
||||
}
|
||||
if(empty($body["email"]??"")){
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => 'The email parameter is null or empty.'
|
||||
]);
|
||||
}else{
|
||||
$validate = $this->user_model->where('email',$body["email"]??"")->countAllResults();
|
||||
if($validate > 0){
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => 'Email already registered!'
|
||||
]);
|
||||
}
|
||||
}
|
||||
if(empty($body["password"]??"")){
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => 'The password parameter is null or empty.'
|
||||
]);
|
||||
}else{
|
||||
if(strlen($body["password"]??"") < 8){
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => 'Password must be at least 8 characters long.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
$settings = $this->settings_model->first()??[];
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$token = md5(uniqid(rand(), true));
|
||||
$this->user_model->save([
|
||||
'group' => $settings['default_role'],
|
||||
'first_name' => $body['first_name'],
|
||||
'last_name' => $body['last_name'],
|
||||
'mobile' => '',
|
||||
'picture' => '/assets/img/default-user.png',
|
||||
'email' => $body['email'],
|
||||
'password' => $phpass->HashPassword($body['password']),
|
||||
'last_access' => date('Y-m-d h:i:s'),
|
||||
'last_ip' => '::1',
|
||||
'language' => $settings['default_language'],
|
||||
'token' => $token,
|
||||
'status' => true
|
||||
]);
|
||||
$data = $this->user_model->select('token,first_name,last_name,date_birth,email,mobile,picture,language,address,address,state,country,zip_code,status,created_at,updated_at')->where('token',$token)->first()??[];
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => false,
|
||||
'message' => 'Added successfully!',
|
||||
'data' => $data??[]
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => $exception->getMessage()
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Return edit user.
|
||||
*/
|
||||
case 'edit':
|
||||
try {
|
||||
$data = $this->user_model->where('token',$key)->first()??[];
|
||||
if($data == []){
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => 'User not found!'
|
||||
]);
|
||||
}
|
||||
$body = $this->request->getVar() == [] ? (array) $this->request->getJSON() : $this->request->getVar();
|
||||
$this->user_model->save([
|
||||
'id_user' => $data['id_user'],
|
||||
'first_name' => empty($body["first_name"]??"")?$data['first_name']:$body["first_name"]??"",
|
||||
'last_name' => empty($body["last_name"]??"")?$data['last_name']:$body["last_name"]??"",
|
||||
'date_birth' => empty($body["date_birth"]??"")?$data['date_birth']:$body["date_birth"]??"",
|
||||
'address' => empty($body["address"]??"")?$data['address']:$body["address"]??"",
|
||||
'city' => empty($body["city"]??"")?$data['city']:$body["city"]??"",
|
||||
'state' => empty($body["state"]??"")?$data['state']:$body["state"]??"",
|
||||
'country' => empty($body["country"]??"")?$data['country']:$body["country"]??"",
|
||||
'zip_code' => empty($body["zip_code"]??"")?$data['zip_code']:$body["zip_code"]??"",
|
||||
'mobile' => empty($body["mobile"]??"")?$data['mobile']:$body["mobile"]??"",
|
||||
'status' => empty($body["status"]??"")?$data['status']:$body["status"]??""
|
||||
]);
|
||||
$data = $this->user_model->select('token,first_name,last_name,date_birth,email,mobile,picture,language,address,address,state,country,zip_code,status,created_at,updated_at')->where('token',$key)->first()??[];
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => false,
|
||||
'message' => 'Successfully Edited!',
|
||||
'data' => $data??[]
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => $exception->getMessage()
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Return delete user.
|
||||
*/
|
||||
case 'delete':
|
||||
try {
|
||||
$this->user_model->where('token', $key)->delete();
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => false,
|
||||
'message' => 'Successfully deleted!'
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => $exception->getMessage()
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Return Default.
|
||||
*/
|
||||
default:
|
||||
return $this->setResponseFormat($this->data_format)->respond([
|
||||
'error' => true,
|
||||
'message' => 'Method call is invalid.'
|
||||
]);
|
||||
endswitch;
|
||||
}
|
||||
}
|
||||
80
ci4/app/Controllers/BaseController.php
Normal file
80
ci4/app/Controllers/BaseController.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\NotificationModel;
|
||||
use App\Models\SettingsModel;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\CLIRequest;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
*
|
||||
* BaseController provides a convenient place for loading components
|
||||
* and performing functions that are needed by all your controllers.
|
||||
* Extend this class in any new controllers:
|
||||
* class Home extends BaseController
|
||||
*
|
||||
* For security be sure to declare any new methods as protected or private.
|
||||
*/
|
||||
class BaseController extends Controller
|
||||
{
|
||||
/**
|
||||
* Instance of the main Request object.
|
||||
*
|
||||
* @var CLIRequest|IncomingRequest
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* An array of helpers to be loaded automatically upon
|
||||
* class instantiation. These helpers will be available
|
||||
* to all other controllers that extend BaseController.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $helpers = ['general','jwt'];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
// Do Not Edit This Line
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
// Preload any models, libraries, etc, here.
|
||||
|
||||
// E.g.: $this->session = \Config\Services::session();
|
||||
$session = \Config\Services::session();
|
||||
|
||||
// Language Validate
|
||||
$language = \Config\Services::language();
|
||||
$language->setLocale($session->lang);
|
||||
|
||||
// Set TimeZone
|
||||
if(empty($session->get('settings'))){
|
||||
$settingsModel = new SettingsModel();
|
||||
$settings = $settingsModel->select('default_timezone')->first()??[];
|
||||
date_default_timezone_set($settings['default_timezone']??'America/Sao_Paulo');
|
||||
}else{
|
||||
date_default_timezone_set($session->get('settings')['default_timezone']??'America/Sao_Paulo');
|
||||
}
|
||||
|
||||
// Get notification
|
||||
if(!empty($session->get('token'))) {
|
||||
$notificationModel = new NotificationModel();
|
||||
$pulse = $notificationModel->where('user_recipient',$session->get('token'))->where('is_read',false)->countAllResults() ?? 0;
|
||||
$notification = $notificationModel->select('token,title,is_read,created_at')->where('user_recipient',$session->get('token'))->orderBy('created_at','desc')->findAll(5) ?? [];
|
||||
$session->set('notification', $notification);
|
||||
$session->set('pulse', $pulse);
|
||||
}else{
|
||||
$session->set('notification', []);
|
||||
$session->set('pulse', 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
88
ci4/app/Controllers/Cron.php
Normal file
88
ci4/app/Controllers/Cron.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ActivityModel;
|
||||
use App\Models\BackupModel;
|
||||
use App\Models\CronTabModel;
|
||||
use App\Models\NotificationModel;
|
||||
use App\Models\SettingsModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class Cron extends BaseController
|
||||
{
|
||||
private $integration;
|
||||
private $user_model;
|
||||
private $notification_model;
|
||||
private $crontab_model;
|
||||
private $settings_model;
|
||||
private $activity_model;
|
||||
private $backup_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->integration = new Integration();
|
||||
$this->user_model = new UserModel();
|
||||
$this->notification_model = new NotificationModel();
|
||||
$this->settings_model = new SettingsModel();
|
||||
$this->crontab_model = new CronTabModel();
|
||||
$this->activity_model = new ActivityModel();
|
||||
$this->backup_model = new BackupModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$settings = $this->settings_model->first()??[];
|
||||
|
||||
// Cron Notification E-mail
|
||||
try {
|
||||
$email_list = $this->notification_model
|
||||
->select('notification.id_notification, recipient.email, notification.title, notification.body')
|
||||
->join('user AS recipient','notification.user_recipient = recipient.token','left')
|
||||
->where('send_email_notification',true)
|
||||
->where('is_send_email',false)
|
||||
->orderBy('notification.id_notification','desc')
|
||||
->findAll(25);
|
||||
foreach ($email_list as $item){
|
||||
if($this->integration->send_email($item['email'],$item['title'],$item['body'])){
|
||||
$this->notification_model->save(['id_notification' => $item['id_notification'],'is_send_email' => true]);
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
$this->crontab_model->save(['routine'=>'Notification Email','error'=>$e->getMessage()]);
|
||||
}
|
||||
|
||||
// Cron Backup
|
||||
if(date('Y-m-d') > date('Y-m-d',strtotime($settings['backup_latest']))){
|
||||
if(date('H:i:s') >= date('H:i:s',strtotime($settings['backup_time']))){
|
||||
try {
|
||||
$this->settings_model->save([
|
||||
'id_settings' => $settings['id_settings'],
|
||||
'backup_latest' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$this->integration->create_backup();
|
||||
}catch (\Exception $e){
|
||||
$this->crontab_model->save(['routine'=>'Backup','error'=>$e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cron Log Delete
|
||||
if(date('Y-m-d') >= date('Y-m-d',strtotime(date($settings['remove_log_latest']) . ' +'.$settings['remove_log_time'].' day'))){
|
||||
try {
|
||||
$this->settings_model->save([
|
||||
'id_settings' => $settings['id_settings'],
|
||||
'remove_log_latest' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$dateStart = date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s') . ' -5 year'));
|
||||
$dateEnd = date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s') . ' -30 day'));
|
||||
$this->crontab_model->where('created_at between "'.$dateStart.'" and "'.$dateEnd.'"')->delete();
|
||||
$this->activity_model->where('created_at between "'.$dateStart.'" and "'.$dateEnd.'"')->delete();
|
||||
$this->backup_model->where('created_at between "'.$dateStart.'" and "'.$dateEnd.'"')->delete();
|
||||
}catch (\Exception $e){
|
||||
$this->crontab_model->save(['routine'=>'Delete Log','error'=>$e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
212
ci4/app/Controllers/Group.php
Normal file
212
ci4/app/Controllers/Group.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\UserModel;
|
||||
use App\Models\UserGroupModel;
|
||||
|
||||
class Group extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $group_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->group_model = new UserGroupModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = [
|
||||
'module' => lang("App.group_title"),
|
||||
'page' => lang("App.group_subtitle"),
|
||||
'icon' => 'fas fa-user-lock'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.group_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_add'] = [
|
||||
'title' => lang("App.group_btn_add"),
|
||||
'route' => '/group/add',
|
||||
'class' => 'btn btn-lg btn-primary float-md-right',
|
||||
'icon' => 'fas fa-plus'
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/group/index',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
helper('form');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.group_add_title"),
|
||||
'page' => lang("App.group_add_subtitle"),
|
||||
'icon' => 'far fa-plus-square'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.group_title"), 'route' => "/group", 'active' => false],
|
||||
['title' => lang("App.group_add_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/group',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/group/form',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
helper('form');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.group_edit_title"),
|
||||
'page' => lang("App.group_edit_subtitle"),
|
||||
'icon' => 'fas fa-edit'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.group_title"), 'route' => "/group", 'active' => false],
|
||||
['title' => lang("App.group_edit_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/group',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
$data['obj'] = $this->group_model->where('token', $id)->first();
|
||||
if($data['obj']==null){
|
||||
return redirect()->to('/group');
|
||||
}
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/group/form',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/group');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
helper('form');
|
||||
|
||||
$rules = [
|
||||
'title' => 'required',
|
||||
'dashboard' => 'required'
|
||||
];
|
||||
$rules_error = [
|
||||
'title' => [
|
||||
'required' => lang("App.group_rules_title_r")
|
||||
],
|
||||
'dashboard' => [
|
||||
'required' => lang("App.group_rules_dashboard_r")
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->validate($rules,$rules_error)){
|
||||
if($listPost = $this->request->getPost()){
|
||||
|
||||
$getChecked = $this->request->getPost();
|
||||
|
||||
unset($getChecked['id_group']);
|
||||
unset($getChecked['title']);
|
||||
unset($getChecked['dashboard']);
|
||||
|
||||
$controller = null;
|
||||
$rules_access = null;
|
||||
|
||||
foreach ($getChecked as $key=>$value){
|
||||
$exp = explode('_',$key);
|
||||
$controller[] = $exp[0];
|
||||
}
|
||||
if($controller != null){
|
||||
foreach (array_unique($controller) as $item){
|
||||
$rules_access[$item] = [];
|
||||
foreach ($getChecked as $key=>$value){
|
||||
$exp = explode('_',$key);
|
||||
if($exp[0] == $item){
|
||||
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$listPost['rules'] = json_encode($rules_access??'{}');
|
||||
if(empty($listPost['id_group'])){
|
||||
$listPost['token'] = md5(uniqid(rand(), true));
|
||||
}
|
||||
|
||||
$this->group_model->save($listPost);
|
||||
|
||||
if(empty($listPost['id_group'])){
|
||||
$session->setFlashdata('sweet', ['success',lang("App.group_alert_add")]);
|
||||
return redirect()->to('/group');
|
||||
}else{
|
||||
if($session->get('group') == $this->request->getPost('token')){
|
||||
$session->set('rules', $listPost['rules']);
|
||||
}
|
||||
$session->setFlashdata('sweet', ['success',lang("App.group_alert_edit")]);
|
||||
return redirect()->to('/group');
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('error','error');
|
||||
$this->add();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/group');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
if($this->user_model->where('group', $id)->countAllResults() == 0){
|
||||
$this->group_model->where('token', $id)->delete();
|
||||
$session->setFlashdata('sweet', ['success',lang("App.group_alert_delete")]);
|
||||
}else{
|
||||
$session->setFlashdata('sweet', ['error',lang("App.group_alert_error")]);
|
||||
}
|
||||
return redirect()->to('/group');
|
||||
}
|
||||
}
|
||||
152
ci4/app/Controllers/Home.php
Normal file
152
ci4/app/Controllers/Home.php
Normal file
@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ActivityModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class Home extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $activity_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->activity_model = new ActivityModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$session = session();
|
||||
$id_user = $session->get('id_user');
|
||||
$name = $session->get('first_name');
|
||||
$hora = date('H');
|
||||
|
||||
//Salutation
|
||||
if( $hora >= 6 && $hora <= 12 )
|
||||
$salutation = lang("App.dashboard_good_morning");
|
||||
else if ( $hora > 12 && $hora <=18 )
|
||||
$salutation = lang("App.dashboard_good_afternoon");
|
||||
else
|
||||
$salutation = lang("App.dashboard_good_night");
|
||||
|
||||
switch ($session->get('dashboard')):
|
||||
case 'admin':
|
||||
$data['title'] = [
|
||||
'module' => lang("App.dashboard_hello").' '.$name,
|
||||
'page' => lang("App.dashboard_indicators"),
|
||||
'icon' => ''
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
//Cards Top
|
||||
$initialDate = date('Y-m-d H:i:s', strtotime('-1 day', time()));
|
||||
$finalDate = date('Y-m-d H:i:s');
|
||||
$data['total_user'] = $this->user_model->countAllResults();
|
||||
$data['total_new'] = $this->user_model->where('created_at between \''.$initialDate.'\' and \''.$finalDate.'\'')->countAllResults();
|
||||
$data['total_enabled'] = $this->user_model->where('status',true)->countAllResults();
|
||||
$data['total_disabled'] = $this->user_model->where('status',false)->countAllResults();
|
||||
|
||||
//Char Bar
|
||||
$titles_char_bar["labels"] = explode(',',lang("App.dashboard_chart_months"));
|
||||
$value_char_bar["series"] = [];
|
||||
$return_char_bar_geral = $this->user_model->select("DATE_FORMAT(created_at,'%m') AS month,COUNT(DATE_FORMAT(created_at,'%m')) AS total")
|
||||
->where("DATE_FORMAT(NOW(),'%Y') = DATE_FORMAT(created_at,'%Y')")
|
||||
->groupBy("DATE_FORMAT(created_at,'%Y-%m')")
|
||||
->findAll();
|
||||
$return_char_bar_enabled = $this->user_model->select("DATE_FORMAT(created_at,'%m') AS month,COUNT(DATE_FORMAT(created_at,'%m')) AS total")
|
||||
->where("DATE_FORMAT(NOW(),'%Y') = DATE_FORMAT(created_at,'%Y') AND status = true")
|
||||
->groupBy("DATE_FORMAT(created_at,'%Y-%m')")
|
||||
->findAll();
|
||||
$return_char_bar_disabled = $this->user_model->select("DATE_FORMAT(updated_at,'%m') AS month,COUNT(DATE_FORMAT(updated_at,'%m')) AS total")
|
||||
->where("DATE_FORMAT(NOW(),'%Y') = DATE_FORMAT(updated_at,'%Y') AND status = false")
|
||||
->groupBy("DATE_FORMAT(updated_at,'%Y-%m')")
|
||||
->findAll();
|
||||
$year = [];
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$notFound = true;
|
||||
foreach ($return_char_bar_geral as $item){
|
||||
if($i == intval($item['month'])){
|
||||
array_push($year,intval($item['total']));
|
||||
$notFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($notFound){
|
||||
array_push($year,0);
|
||||
}
|
||||
}
|
||||
array_push($value_char_bar["series"],$year);
|
||||
$year = [];
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$notFound = true;
|
||||
foreach ($return_char_bar_enabled as $item){
|
||||
if($i == intval($item['month'])){
|
||||
array_push($year,intval($item['total']));
|
||||
$notFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($notFound){
|
||||
array_push($year,0);
|
||||
}
|
||||
}
|
||||
array_push($value_char_bar["series"],$year);
|
||||
$year = [];
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$notFound = true;
|
||||
foreach ($return_char_bar_disabled as $item){
|
||||
if($i == intval($item['month'])){
|
||||
array_push($year,intval($item['total']));
|
||||
$notFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($notFound){
|
||||
array_push($year,0);
|
||||
}
|
||||
}
|
||||
array_push($value_char_bar["series"],$year);
|
||||
$data['data_char_bar'] = json_encode(array_merge($titles_char_bar,$value_char_bar));
|
||||
|
||||
$data['data_user'] = $this->user_model->select('picture,first_name,last_name,email,created_at')
|
||||
->orderBy('id_user','DESC')
|
||||
->findAll(15);
|
||||
|
||||
$data['data_activity'] = $this->activity_model
|
||||
->select('auth_user.first_name,auth_user.email,auth_activity.detail,auth_activity.created_at')
|
||||
->join('auth_user','auth_user.token=auth_activity.user')
|
||||
->orderBy('auth_activity.id_activity','DESC')
|
||||
->findAll(30);
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/dashboard/admin',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
$data['title'] = [
|
||||
'module' => lang("App.dashboard_hello").' '.$name,
|
||||
'page' => lang("App.dashboard_indicators"),
|
||||
'icon' => ''
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/dashboard/user',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
break;
|
||||
default:
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/dashboard/index');
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
endswitch;
|
||||
}
|
||||
}
|
||||
515
ci4/app/Controllers/Integration.php
Normal file
515
ci4/app/Controllers/Integration.php
Normal file
@ -0,0 +1,515 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ActivityModel;
|
||||
use App\Models\PasswordRecoveryModel;
|
||||
use App\Models\SettingsModel;
|
||||
use App\Models\TemplateModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Libraries\PasswordHash;
|
||||
use CodeIgniter\HTTP\Files\FileCollection;
|
||||
|
||||
class Integration extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $settings_model;
|
||||
private $pass_recovery_model;
|
||||
private $template_model;
|
||||
private $activity_model;
|
||||
private $id_user;
|
||||
private $token_user;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->settings_model = new SettingsModel();
|
||||
$this->pass_recovery_model = new PasswordRecoveryModel();
|
||||
$this->template_model = new TemplateModel();
|
||||
$this->activity_model = new ActivityModel();
|
||||
$this->id_user = session()->get('id_user');
|
||||
$this->token_user = session()->get('token');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/dashboard/index');
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function send_email($email='',$subject='',$body='',$key='',$json=false){
|
||||
if(empty($email)){
|
||||
return $json ? json_encode(["return" => false]) : false;
|
||||
}
|
||||
$phpass = new PasswordHash(8, true);
|
||||
if(!$phpass->CheckPassword(MD5($email), $key)){
|
||||
return $json ? json_encode(["return" => false]) : false;
|
||||
}
|
||||
$user = $this->user_model->where('email',$email??null)->first();
|
||||
if(!empty($user)){
|
||||
foreach (keywordEmail()??[] as $item){
|
||||
$field = str_replace(['[','user_',']'],'',$item);
|
||||
$body = str_replace('['.$item.']',$user[$field],$body);
|
||||
}
|
||||
}
|
||||
if($this->sendMail($subject,unescape($body),$email)){
|
||||
return $json ? json_encode(["return" => true]) : true;
|
||||
}else{
|
||||
return $json ? json_encode(["return" => false]) : false;
|
||||
}
|
||||
}
|
||||
|
||||
public function send_email_test($email=''){
|
||||
$token = session()->get('token')??'';
|
||||
if(!empty($token)){
|
||||
if(empty($email)){
|
||||
return $this->response->setJSON(["return" => false]);
|
||||
}
|
||||
$subject = "Email Test";
|
||||
$body = "Email working successfully!";
|
||||
if($this->sendMail($subject,unescape($body),$email)){
|
||||
return $this->response->setJSON(["return" => true]);
|
||||
}else{
|
||||
return $this->response->setJSON(["return" => false]);
|
||||
}
|
||||
}else{
|
||||
return $this->response->setJSON(["return" => false]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function reset_password(){
|
||||
$session = session();
|
||||
$settings = $session->get('settings');
|
||||
helper('text');
|
||||
|
||||
if($listPost = $this->request->getPost()){
|
||||
|
||||
// Captcha Validation
|
||||
if($settings['captcha_recovery']??false){
|
||||
if($settings['captcha_gateway'] == 'recaptcha'){
|
||||
if(isset($listPost['g-recaptcha-response'])){
|
||||
$captcha = $listPost['g-recaptcha-response'];
|
||||
$url = 'https://www.google.com/recaptcha/api/siteverify?secret='.urlencode($settings['captcha_secret_key']??'').'&response='.urlencode($captcha);
|
||||
$response = file_get_contents($url);
|
||||
$responseKeys = json_decode($response,true);
|
||||
if(!$responseKeys["success"]) {
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_invalid")]);
|
||||
return redirect()->to('/login/forgot_password');
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_not_found")]);
|
||||
return redirect()->to('/login/forgot_password');
|
||||
}
|
||||
}
|
||||
if($settings['captcha_gateway'] == 'hcaptcha'){
|
||||
if(isset($listPost['h-captcha-response'])){
|
||||
$captcha = $listPost['h-captcha-response'];
|
||||
$url = 'https://hcaptcha.com/siteverify?secret='.urlencode($settings['captcha_secret_key']??'').'&response='.urlencode($captcha).'&remoteip='.$_SERVER['REMOTE_ADDR'];
|
||||
$response = file_get_contents($url);
|
||||
$responseKeys = json_decode($response,true);
|
||||
if(!$responseKeys["success"]) {
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_invalid")]);
|
||||
return redirect()->to('/login/forgot_password');
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_not_found")]);
|
||||
return redirect()->to('/login/forgot_password');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$user = $this->user_model->where('email',$listPost['email']??null)->first();
|
||||
|
||||
if(empty($user)){
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_user_not_found")]);
|
||||
return redirect()->to('/login/forgot_password');
|
||||
}
|
||||
|
||||
$template = $this->template_model->where('id_template',1)->first();
|
||||
|
||||
foreach (keywordEmail()??[] as $item){
|
||||
$field = str_replace(['[','user_',']'],'',$item);
|
||||
$template = str_replace('['.$item.']',$user[$field],$template);
|
||||
}
|
||||
|
||||
$token = random_string("alnum", 50);
|
||||
$url = base_url().'/login/recovery/'.$token;
|
||||
|
||||
$this->pass_recovery_model->save([
|
||||
'user' => $user['token'],
|
||||
'token' => $token
|
||||
]);
|
||||
|
||||
$title = $template['subject']??'';
|
||||
$msg = $template['body']??'';
|
||||
$msg = str_replace('[recovery_password]',$url,$msg);
|
||||
$email = $user['email'];
|
||||
|
||||
$this->setLog('recovery','recovery-password',$user['token']);
|
||||
$send = $this->sendMail($title,$msg,$email);
|
||||
if($send){
|
||||
$session->setFlashdata('toast', ['success',lang("App.login_alert_send"),lang("App.login_alert_send_pass")]);
|
||||
return redirect()->to('/login/forgot_password');
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_error_email")]);
|
||||
return redirect()->to('/login/forgot_password');
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_error_pass")]);
|
||||
return redirect()->to('/login/forgot_password');
|
||||
}
|
||||
}
|
||||
|
||||
public function setLog($level,$event,$user='')
|
||||
{
|
||||
$request = \Config\Services::request();
|
||||
$ip = $request->getIPAddress();
|
||||
$agent = $request->getUserAgent();
|
||||
|
||||
if ($agent->isBrowser())
|
||||
{
|
||||
$currentAgent = $agent->getBrowser().' '.$agent->getVersion();
|
||||
}
|
||||
elseif ($agent->isRobot())
|
||||
{
|
||||
$currentAgent = $this->agent->robot();
|
||||
}
|
||||
elseif ($agent->isMobile())
|
||||
{
|
||||
$currentAgent = $agent->getMobile();
|
||||
}
|
||||
else
|
||||
{
|
||||
$currentAgent = 'Unidentified User Agent';
|
||||
}
|
||||
|
||||
$this->activity_model->save([
|
||||
'user' => $this->token_user??$user,
|
||||
'level' => $level,
|
||||
'event' => $event,
|
||||
'ip' => $ip,
|
||||
'os' => $agent->getPlatform(),
|
||||
'browser' => $currentAgent,
|
||||
'detail' => $agent
|
||||
]);
|
||||
}
|
||||
|
||||
private function sendMail($subject,$body,$recipient)
|
||||
{
|
||||
$config = $this->settings_model->first();
|
||||
$gateway = $config['email_gateway'];
|
||||
$body = html_entity_decode($body);
|
||||
|
||||
if($gateway == 'smtp'){
|
||||
try {
|
||||
//https://codeigniter.com/user_guide/libraries/email.html
|
||||
$email = \Config\Services::email();
|
||||
$config['protocol'] = $config['email_gateway'];
|
||||
$config['SMTPHost'] = $config['email_smtp'];
|
||||
$config['SMTPUser'] = $config['email_address'];
|
||||
$config['SMTPPass'] = $config['email_pass'];
|
||||
$config['SMTPPort'] = $config['email_port'];
|
||||
$config['SMTPCrypto'] = $config['email_cert']=='none'?'':$config['email_cert'];
|
||||
$config['SMTPTimeout'] = 15;
|
||||
$config['mailType'] = 'html';
|
||||
$config['wordWrap'] = true;
|
||||
|
||||
$email->initialize($config);
|
||||
|
||||
$email->setFrom($config['email_address'], $config['email_name']);
|
||||
$email->setTo($recipient);
|
||||
|
||||
$email->setSubject($subject);
|
||||
$email->setMessage($body);
|
||||
|
||||
if (!$email->send())
|
||||
{
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function saveStorage($file=null,$path='',$allow=[]){
|
||||
$config = $this->settings_model->first();
|
||||
$gateway = $config['storage_gateway'];
|
||||
|
||||
switch ($gateway) {
|
||||
case "local":
|
||||
try {
|
||||
$ext = $file ? $file->getExtension() : '';
|
||||
if (in_array(strtolower($ext), $allow)) {
|
||||
if(strtolower(PHP_OS) == 'linux'){
|
||||
$pathServer = $path;
|
||||
}else{
|
||||
$pathServer = str_replace('/','\\',$path);
|
||||
}
|
||||
if ($file->isValid()) {
|
||||
$name = $file->getName();
|
||||
$rename = $file->getRandomName();
|
||||
$file->move($pathServer,$rename);
|
||||
return $path.$rename;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
case "aws":
|
||||
case "minio":
|
||||
$aws_endpoint = $config['aws_endpoint'];
|
||||
$aws_key = $config['aws_key'];
|
||||
$aws_secret = $config['aws_secret'];
|
||||
$aws_region = $config['aws_region'];
|
||||
$aws_bucket = $config['aws_bucket'];
|
||||
|
||||
try {
|
||||
$ext = $file ? $file->getExtension() : '';
|
||||
if (in_array(strtolower($ext), $allow)) {
|
||||
|
||||
if($gateway=="minio"){
|
||||
$s3Client = new \Aws\S3\S3Client([
|
||||
'version' => 'latest',
|
||||
'region' => $aws_region,
|
||||
'endpoint' => $aws_endpoint,
|
||||
'use_path_style_endpoint' => true,
|
||||
'credentials' => [
|
||||
'key' => $aws_key,
|
||||
'secret' => $aws_secret
|
||||
]
|
||||
]);
|
||||
}else{
|
||||
$s3Client = new \Aws\S3\S3Client([
|
||||
'version' => 'latest',
|
||||
'region' => $aws_region,
|
||||
'credentials' => [
|
||||
'key' => $aws_key,
|
||||
'secret' => $aws_secret
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$rename = $file->getRandomName();
|
||||
$file->move(WRITEPATH.'uploads',$rename);
|
||||
if(strtolower(PHP_OS) == 'linux'){
|
||||
$file_Path = WRITEPATH.'uploads/'. $rename;
|
||||
}else{
|
||||
$file_Path = WRITEPATH.'uploads\\'. $rename;
|
||||
}
|
||||
$result = $s3Client->putObject([
|
||||
'Bucket' => $aws_bucket,
|
||||
'Key' => $rename,
|
||||
'Body' => fopen($file_Path, 'r')
|
||||
]);
|
||||
unlink($file_Path);
|
||||
if($result['@metadata']['statusCode'] == 200){
|
||||
return $result['@metadata']['effectiveUri'];
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
} catch (\Aws\S3\Exception\S3Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $ex) {
|
||||
return null;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function saveStorageBackup($file=null,$name=null){
|
||||
$config = $this->settings_model->first();
|
||||
$gateway = $config['backup_storage'];
|
||||
|
||||
switch ($gateway) {
|
||||
case "local":
|
||||
try {
|
||||
return $file;
|
||||
} catch (\Exception $ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
case "aws":
|
||||
case "minio":
|
||||
$aws_endpoint = $config['aws_endpoint'];
|
||||
$aws_key = $config['aws_key'];
|
||||
$aws_secret = $config['aws_secret'];
|
||||
$aws_region = $config['aws_region'];
|
||||
$aws_bucket = $config['aws_bucket'];
|
||||
|
||||
try {
|
||||
if($gateway=="minio"){
|
||||
$s3Client = new \Aws\S3\S3Client([
|
||||
'version' => 'latest',
|
||||
'region' => $aws_region,
|
||||
'endpoint' => $aws_endpoint,
|
||||
'use_path_style_endpoint' => true,
|
||||
'credentials' => [
|
||||
'key' => $aws_key,
|
||||
'secret' => $aws_secret
|
||||
]
|
||||
]);
|
||||
}else{
|
||||
$s3Client = new \Aws\S3\S3Client([
|
||||
'version' => 'latest',
|
||||
'region' => $aws_region,
|
||||
'credentials' => [
|
||||
'key' => $aws_key,
|
||||
'secret' => $aws_secret
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $s3Client->putObject([
|
||||
'Bucket' => $aws_bucket,
|
||||
'Key' => $name,
|
||||
'Body' => fopen($file, 'r')
|
||||
]);
|
||||
unlink($file);
|
||||
if($result['@metadata']['statusCode'] == 200){
|
||||
return $result['@metadata']['effectiveUri'];
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
} catch (\Aws\S3\Exception\S3Exception $e) {
|
||||
return null;
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
return null;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function create_backup($download=false)
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
if($download==true){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/settings');
|
||||
}else{
|
||||
die();
|
||||
}
|
||||
}
|
||||
$settings = $this->settings_model->first()??[];
|
||||
if($settings['backup_automatic']){
|
||||
helper('text');
|
||||
$db = db_connect('default');
|
||||
try {
|
||||
$all = false;
|
||||
$tables = explode(',',$settings['backup_table']??'');
|
||||
foreach ($tables as $item){
|
||||
if ($item == 'all'){
|
||||
$all = true;
|
||||
}
|
||||
}
|
||||
$token = random_string("alnum", 10);
|
||||
$name ='mysql_'.$token.'_'.date("YmdHis").'.sql';
|
||||
if(strtolower(PHP_OS) == 'linux'){
|
||||
$file_Path = WRITEPATH.'uploads/'.$name;
|
||||
}else{
|
||||
$file_Path = WRITEPATH.'uploads\\'.$name;
|
||||
}
|
||||
if($all){
|
||||
\Spatie\DbDumper\Databases\MySql::create()
|
||||
->setHost(getenv('database.default.hostname'))
|
||||
->setDbName(getenv('database.default.database'))
|
||||
->setUserName(getenv('database.default.username'))
|
||||
->setPassword(getenv('database.default.password'))
|
||||
->setDumpBinaryPath(getenv('database.default.dump'))
|
||||
->dumpToFile($file_Path);
|
||||
}else{
|
||||
\Spatie\DbDumper\Databases\MySql::create()
|
||||
->setHost(getenv('database.default.hostname'))
|
||||
->setDbName(getenv('database.default.database'))
|
||||
->setUserName(getenv('database.default.username'))
|
||||
->setPassword(getenv('database.default.password'))
|
||||
->setDumpBinaryPath(getenv('database.default.dump'))
|
||||
->includeTables($tables)
|
||||
->dumpToFile($file_Path);
|
||||
}
|
||||
$file = $this->saveStorageBackup($file_Path,$name);
|
||||
$db->query("INSERT INTO backup VALUES (NULL,'".$file."','',NOW(),NOW())");
|
||||
if($settings['backup_notification_email']){
|
||||
$send = $this->send_email($settings['backup_email'],$settings['title']." (BACKUP)",lang("App.crontab_backup_success").date("Y-m-d H:i:s"));
|
||||
if(!$send){
|
||||
$db->query("INSERT INTO backup VALUES (NULL,'','".lang("App.crontab_email_error")."',NOW(),NOW())");
|
||||
}
|
||||
}
|
||||
if($download){
|
||||
$this->download_backup($file,$name);
|
||||
}
|
||||
} catch (\Spatie\DbDumper\Exceptions\DumpFailed $e) {
|
||||
$error = str_replace("'","\'",$e->getMessage());
|
||||
$db->query("INSERT INTO backup VALUES (NULL,'','".$error."',NOW(),NOW())");
|
||||
if($settings['backup_notification_email']){
|
||||
$send = $this->send_email($settings['backup_email'],$settings['title']." (BACKUP ERROR)",'Error: '.$e->getMessage());
|
||||
if(!$send){
|
||||
$db->query("INSERT INTO backup VALUES (NULL,'','".lang("App.crontab_email_error")."',NOW(),NOW())");
|
||||
}
|
||||
}
|
||||
if($download){
|
||||
session()->setFlashdata('sweet', ['error',lang("App.crontab_backup_error")]);
|
||||
return redirect()->to('/settings');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function download_backup($path=null,$name=null)
|
||||
{
|
||||
if (!empty(session()->get('token')??'')){
|
||||
set_time_limit(0);
|
||||
if(!empty($path) && !empty($name) && file_exists($path)){
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Disposition: attachment; filename="'.$name.'"');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: ' . filesize($path));
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Expires: 0');
|
||||
readfile($path);
|
||||
}
|
||||
}else{
|
||||
return redirect()->to('/settings');
|
||||
}
|
||||
}
|
||||
|
||||
public function download_postman()
|
||||
{
|
||||
if(!empty(session()->get('token')??'')){
|
||||
set_time_limit(0);
|
||||
$path = WRITEPATH.'postman_collection.json';
|
||||
if(file_exists($path)){
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Disposition: attachment; filename="WebGuard ApiRest - postman_collection.json"');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: ' . filesize($path));
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Expires: 0');
|
||||
readfile($path);
|
||||
}
|
||||
}else{
|
||||
return redirect()->to('/settings');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
18
ci4/app/Controllers/Language.php
Normal file
18
ci4/app/Controllers/Language.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
class Language extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$session = session();
|
||||
$locale = $this->request->getLocale();
|
||||
$session->remove('lang');
|
||||
$session->set('lang', $locale);
|
||||
$url = base_url();
|
||||
return redirect()->to($url);
|
||||
}
|
||||
}
|
||||
560
ci4/app/Controllers/Login.php
Normal file
560
ci4/app/Controllers/Login.php
Normal file
@ -0,0 +1,560 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Authenticator;
|
||||
use App\Libraries\PasswordHash;
|
||||
use App\Models\ActivityModel;
|
||||
use App\Models\ConfirmationTokenModel;
|
||||
use App\Models\NotificationModel;
|
||||
use App\Models\PasswordRecoveryModel;
|
||||
use App\Models\SettingsModel;
|
||||
use App\Models\TemplateModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Models\UserGroupModel;
|
||||
|
||||
class login extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $group_model;
|
||||
private $settings_model;
|
||||
private $pass_recovery_model;
|
||||
private $activity_model;
|
||||
private $notification_model;
|
||||
private $template_model;
|
||||
private $confirmation_model;
|
||||
private $integration;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->group_model = new UserGroupModel();
|
||||
$this->settings_model = new SettingsModel();
|
||||
$this->pass_recovery_model = new PasswordRecoveryModel();
|
||||
$this->activity_model = new ActivityModel();
|
||||
$this->notification_model = new NotificationModel();
|
||||
$this->template_model = new TemplateModel();
|
||||
$this->confirmation_model = new ConfirmationTokenModel();
|
||||
$this->integration = new Integration();
|
||||
// Get Settings
|
||||
$loginAuthFilter = new \App\Filters\LoginAuthFilter();
|
||||
$loginAuthFilter->getSettings();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$session = session();
|
||||
$data['settings'] = $session->get('settings');
|
||||
$header['title'] = lang("App.login_title");
|
||||
|
||||
echo view(getenv('theme.path').'login/header',$header);
|
||||
echo view(getenv('theme.path').'form/login/index',$data);
|
||||
echo view(getenv('theme.path').'login/footer');
|
||||
}
|
||||
|
||||
public function forgot_password()
|
||||
{
|
||||
$session = session();
|
||||
if($session->get('settings')['forgot_password']??false){
|
||||
$data['settings'] = $session->get('settings');
|
||||
$header['title'] = lang("App.login_title_forgot_password");
|
||||
|
||||
echo view(getenv('theme.path').'login/header',$header);
|
||||
echo view(getenv('theme.path').'form/login/forgot_password',$data);
|
||||
echo view(getenv('theme.path').'login/footer');
|
||||
}else{
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function authenticate()
|
||||
{
|
||||
$session = session();
|
||||
$settings = $session->get('settings');
|
||||
|
||||
if(!empty($session->get('oauth'))){
|
||||
// Data obtained by oAuth
|
||||
$login = $this->user_model->where('email', $session->get('oauth')->email)->first();
|
||||
} else {
|
||||
// Data obtained by Form
|
||||
$getVar = $this->request->getvar();
|
||||
$login = $this->user_model->where('email', $getVar['email']??'')->first();
|
||||
// Captcha Validation
|
||||
if($settings['captcha_login']??false){
|
||||
if($settings['captcha_gateway'] == 'recaptcha'){
|
||||
if(isset($getVar['g-recaptcha-response'])){
|
||||
$captcha = $getVar['g-recaptcha-response'];
|
||||
$url = 'https://www.google.com/recaptcha/api/siteverify?secret='.urlencode($settings['captcha_secret_key']??'').'&response='.urlencode($captcha);
|
||||
$response = file_get_contents($url);
|
||||
$responseKeys = json_decode($response,true);
|
||||
if(!$responseKeys["success"]) {
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_invalid")]);
|
||||
return redirect()->to('login');
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_not_found")]);
|
||||
return redirect()->to('login');
|
||||
}
|
||||
}
|
||||
if($settings['captcha_gateway'] == 'hcaptcha'){
|
||||
if(isset($getVar['h-captcha-response'])){
|
||||
$captcha = $getVar['h-captcha-response'];
|
||||
$url = 'https://hcaptcha.com/siteverify?secret='.urlencode($settings['captcha_secret_key']??'').'&response='.urlencode($captcha).'&remoteip='.$_SERVER['REMOTE_ADDR'];
|
||||
$response = file_get_contents($url);
|
||||
$responseKeys = json_decode($response,true);
|
||||
if(!$responseKeys["success"]) {
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_invalid")]);
|
||||
return redirect()->to('login');
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_not_found")]);
|
||||
return redirect()->to('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remember Me Validation
|
||||
if($settings['remember_me']??false){
|
||||
if($getVar['remember']??'' == 'on') {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), $_COOKIE[session_name()], time() + 60*60*24*30, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($login))
|
||||
{
|
||||
// Blocked Validation
|
||||
if($login['blocked']!=null){
|
||||
$dateBlocked = date($login['blocked']);
|
||||
$dateNow = date('Y-m-d H:i:s');
|
||||
if($dateBlocked > $dateNow){
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_user_blocked").$settings['throttle_auth_lockour_time'].' '.lang("App.global_hours")]);
|
||||
return redirect()->to('login');
|
||||
}else{
|
||||
$this->user_model->save([
|
||||
'id_user' => $login['id_user'],
|
||||
'blocked' => null
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Get Ip Address
|
||||
$request = \Config\Services::request();
|
||||
$last_ip = $request->getIPAddress();
|
||||
|
||||
if(empty($session->get('oauth'))){
|
||||
// Check user password
|
||||
$phpass = new PasswordHash(8, true);
|
||||
if(!$phpass->CheckPassword($getVar['password']??'', $login['password'])){
|
||||
// Throttling Validation
|
||||
if($settings['throttle_auth']??false){
|
||||
$initialDate = date('Y-m-d H:i:s', strtotime('-12 hour', time()));
|
||||
$finalDate = date('Y-m-d H:i:s');
|
||||
$amount = $this->activity_model->where('user',$login['token'])->where('level','throttling')->where('created_at between \''.$initialDate.'\' and \''.$finalDate.'\'')->countAllResults();
|
||||
if($amount >= intval($settings['throttle_auth_max_attempts']??'')){
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_user_blocked").$settings['throttle_auth_lockour_time'].' '.lang("App.global_hours")]);
|
||||
$blocked = date('Y-m-d H:i:s', strtotime('+'.$settings['throttle_auth_lockour_time'].' hour', time()));
|
||||
$this->user_model->save([
|
||||
'id_user' => $login['id_user'],
|
||||
'blocked' => $blocked
|
||||
]);
|
||||
return redirect()->to('login');
|
||||
}else{
|
||||
// Register Throttling Log
|
||||
$this->integration->setLog('throttling','login-authenticate',$login['token']);
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_pass_invalid_2"). ($amount+1) .lang("App.login_alert_pass_attempt"). $settings['throttle_auth_max_attempts']??0]);
|
||||
return redirect()->to('login');
|
||||
}
|
||||
}
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_pass_invalid")]);
|
||||
return redirect()->to('login');
|
||||
}
|
||||
// Check email confirmed
|
||||
if($settings['email_confirmation']??false){
|
||||
if(!$login['email_confirmed']){
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.user_alert_email_confirmed")]);
|
||||
return redirect()->to('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check user status
|
||||
if(!$login['status']){
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_disabled_access")]);
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
|
||||
// Get access rules
|
||||
$rules = $this->group_model->where('token', $login['group'])->first();
|
||||
|
||||
// Save data in session
|
||||
$session->set('id_user', $login['id_user']);
|
||||
$session->set('group', $login['group']);
|
||||
$session->set('first_name', $login['first_name']);
|
||||
$session->set('last_name', $login['last_name']);
|
||||
$session->set('email', $login['email']);
|
||||
$session->set('token', $login['token']);
|
||||
$session->set('dashboard', $rules['dashboard']);
|
||||
$session->set('rules', html_entity_decode($rules['rules']));
|
||||
$session->set('picture', $login['picture']);
|
||||
$session->set('tfa', $login['tfa']);
|
||||
$session->set('tfa_secret', $login['tfa_secret']);
|
||||
$session->set('tfa_code', $login['tfa_code']);
|
||||
$session->set('lang', $login['language'] ?? 'en');
|
||||
// Update last access
|
||||
$last_access = date('Y-m-d H:i:s');
|
||||
$this->user_model->set('last_access', $last_access)->set('last_ip', $last_ip)->where('id_user', $session->get('id_user'))->update();
|
||||
|
||||
// Register Access Log
|
||||
$integration = new \App\Controllers\Integration;
|
||||
$integration->setLog('information','login-authenticate');
|
||||
|
||||
// Check if it has two factors
|
||||
if($login['tfa']??false){
|
||||
return redirect()->to('/login/authentication');
|
||||
}else{
|
||||
return redirect()->to('home');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_user_not_found")]);
|
||||
return redirect()->to('login');
|
||||
}
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
// Destroy the session
|
||||
$session = session();
|
||||
$lang = $session->get('lang');
|
||||
$session->destroy();
|
||||
return redirect()->to('/lang/'.$lang);
|
||||
}
|
||||
|
||||
public function signup()
|
||||
{
|
||||
$session = session();
|
||||
helper('form');
|
||||
$data['settings'] = $session->get('settings');
|
||||
$header['title'] = lang("App.login_title_signup");
|
||||
|
||||
echo view(getenv('theme.path').'login/header',$header);
|
||||
echo view(getenv('theme.path').'form/login/signup',$data);
|
||||
echo view(getenv('theme.path').'login/footer');
|
||||
}
|
||||
|
||||
public function authentication()
|
||||
{
|
||||
$session = session();
|
||||
if($session->get('tfa')??false){
|
||||
$header['title'] = lang("App.login_title_otp");
|
||||
echo view(getenv('theme.path').'login/header',$header);
|
||||
echo view(getenv('theme.path').'form/login/authentication');
|
||||
echo view(getenv('theme.path').'login/footer');
|
||||
}else{
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function otp()
|
||||
{
|
||||
$session = session();
|
||||
$tfa_secret = $session->get('tfa_secret');
|
||||
$tfa_code = $session->get('tfa_code');
|
||||
$pin = $this->request->getVar();
|
||||
$otp = "";
|
||||
|
||||
foreach ($pin as $key=>$value){
|
||||
if(strpos($key, 'pin') !== false){
|
||||
$otp .= $value;
|
||||
}
|
||||
}
|
||||
|
||||
$tfa = new Authenticator();
|
||||
$backup_pass = false;
|
||||
$checkResult = $tfa->verify($tfa_secret??'', $otp);
|
||||
|
||||
if($tfa_code??'') {
|
||||
$backup_codes = explode(',' , $tfa_code??'');
|
||||
if (in_array($otp, $backup_codes)) {
|
||||
$backup_pass = true;
|
||||
$key = array_search($otp, $backup_codes);
|
||||
unset($backup_codes[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if($checkResult || $backup_pass == true) {
|
||||
$session->set('tfa',false);
|
||||
$session->set('tfa_secret','');
|
||||
$session->set('tfa_code','');
|
||||
return redirect()->to('/home');
|
||||
} else {
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_code_invalid")]);
|
||||
return redirect()->to('/login/authentication');
|
||||
}
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$session = session();
|
||||
$settings = $session->get('settings');
|
||||
|
||||
helper('form');
|
||||
helper('text');
|
||||
|
||||
$rules = [
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'email' => 'required|valid_email|is_unique[user.email]',
|
||||
'password' => 'required|min_length[8]'
|
||||
];
|
||||
$rules_error = [
|
||||
'first_name' => [
|
||||
'required' => lang("App.login_rules_first_name_r")
|
||||
],
|
||||
'last_name' => [
|
||||
'required' => lang("App.login_rules_last_name_r")
|
||||
],
|
||||
'email' => [
|
||||
'required' => lang("App.login_rules_email_r"),
|
||||
'is_unique' => lang("App.login_rules_email_i"),
|
||||
'valid_email' => lang("App.login_rules_email_v"),
|
||||
],
|
||||
'password' => [
|
||||
'required' => lang("App.login_rules_password_r"),
|
||||
'min_length' => lang("App.login_rules_password_m")
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->validate($rules,$rules_error)){
|
||||
if($listPost = $this->request->getPost()) {
|
||||
if($settings['captcha_register']??false){
|
||||
if($settings['captcha_gateway'] == 'recaptcha'){
|
||||
if(isset($listPost['g-recaptcha-response'])){
|
||||
$captcha = $listPost['g-recaptcha-response'];
|
||||
$url = 'https://www.google.com/recaptcha/api/siteverify?secret='.urlencode($settings['captcha_secret_key']??'').'&response='.urlencode($captcha);
|
||||
$response = file_get_contents($url);
|
||||
$responseKeys = json_decode($response,true);
|
||||
if(!$responseKeys["success"]) {
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_invalid")]);
|
||||
$this->signup();
|
||||
die();
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_not_found")]);
|
||||
$this->signup();
|
||||
die();
|
||||
}
|
||||
}
|
||||
if($settings['captcha_gateway'] == 'hcaptcha'){
|
||||
if(isset($listPost['h-captcha-response'])){
|
||||
$captcha = $listPost['h-captcha-response'];
|
||||
$url = 'https://hcaptcha.com/siteverify?secret='.urlencode($settings['captcha_secret_key']??'').'&response='.urlencode($captcha).'&remoteip='.$_SERVER['REMOTE_ADDR'];
|
||||
$response = file_get_contents($url);
|
||||
$responseKeys = json_decode($response,true);
|
||||
if(!$responseKeys["success"]) {
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_invalid")]);
|
||||
$this->signup();
|
||||
die();
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_captcha_not_found")]);
|
||||
$this->signup();
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$userToken = md5(uniqid(rand(), true));
|
||||
$this->user_model->save([
|
||||
'group' => $settings['default_role'],
|
||||
'first_name' => $listPost['first_name'],
|
||||
'last_name' => $listPost['last_name'],
|
||||
'mobile' => '',
|
||||
'picture' => '/assets/img/default-user.png',
|
||||
'email' => $listPost['email'],
|
||||
'password' => $phpass->HashPassword($listPost['password']),
|
||||
'last_access' => date('Y-m-d h:i:s'),
|
||||
'last_ip' => '::1',
|
||||
'language' => $settings['default_language'],
|
||||
'token' => $userToken,
|
||||
'status' => true
|
||||
]);
|
||||
//Get Data Template
|
||||
$templates = $this->template_model->findAll();
|
||||
|
||||
//Notification E-mail User Welcome
|
||||
if($settings['send_email_welcome']??false){
|
||||
$template = templateSelect($templates,'template_label_welcome','email');
|
||||
if($template != null){
|
||||
try {
|
||||
$this->integration->send_email($listPost['email'],$template['subject'],$template['body'],$phpass->HashPassword(MD5($listPost['email'])));
|
||||
}catch (\Exception $e){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//E-mail Account Confirmation
|
||||
if($settings['email_confirmation']??false){
|
||||
$template = templateSelect($templates,'template_label_confirmation_email','email');
|
||||
if($template != null){
|
||||
$token = random_string("alnum", 50);
|
||||
$url = base_url().'/login/confirmation/'.$token;
|
||||
$body = str_replace('[link_confirmation]',$url,$template['body']);
|
||||
try {
|
||||
$this->integration->send_email($listPost['email'],$template['subject'],$body,$phpass->HashPassword(MD5($listPost['email'])));
|
||||
$this->confirmation_model->save([
|
||||
'id_confirmation' => null,
|
||||
'user' => $userToken,
|
||||
'token' => $token,
|
||||
'confirmed' => false,
|
||||
'type' => 'email'
|
||||
]);
|
||||
}catch (\Exception $e){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Notification New Register
|
||||
if($settings['send_notification_register']??false){
|
||||
$template = templateSelect($templates,'template_label_notification','email');
|
||||
if($template != null){
|
||||
if(!empty($settings['send_user_register']??null)){
|
||||
$data = [
|
||||
'id_notification' => null,
|
||||
'user_sender' => $settings['send_user_register']??null,
|
||||
'user_recipient' => $settings['send_user_register']??null,
|
||||
'title' => $template['subject'],
|
||||
'body' => $template['body'],
|
||||
'is_read' => false,
|
||||
'is_send_email' => false,
|
||||
'send_email_notification' => $settings['send_email_register']??false,
|
||||
'token' => md5(uniqid(rand(), true))
|
||||
];
|
||||
$this->notification_model->save($data);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$userAdm = $this->user_model->where('token',$settings['send_user_register']??null)->first();
|
||||
if($settings['send_email_register']??false){
|
||||
$template = templateSelect($templates,'template_label_notification','email');
|
||||
if($template != null){
|
||||
try {
|
||||
$this->integration->send_email($userAdm['email'],$template['subject'],$template['body'],$phpass->HashPassword(MD5($listPost['email'])));
|
||||
}catch (\Exception $e){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$session = session();
|
||||
$session->setFlashdata('toast', ['success', lang("App.login_alert_success"), lang("App.login_alert_success_register")]);
|
||||
return redirect()->to('/login');
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error', lang("App.login_alert"),lang("App.login_alert_parameter_invalid")]);
|
||||
$this->signup();
|
||||
}
|
||||
}else{
|
||||
$session = session();
|
||||
$session->setFlashdata('error','error');
|
||||
$this->signup();
|
||||
}
|
||||
}
|
||||
|
||||
public function recovery($token=null)
|
||||
{
|
||||
$session = session();
|
||||
if(!empty($token) && $session->get('settings')['forgot_password']??false){
|
||||
$pass_recovery = $this->pass_recovery_model->where('token',$token)->where('changed',false)->first();
|
||||
if($pass_recovery != null){
|
||||
$data['token'] = $token;
|
||||
$data['user'] = $pass_recovery['user'];
|
||||
$header['title'] = lang("App.login_title_recovery");
|
||||
echo view(getenv('theme.path').'login/header',$header);
|
||||
echo view(getenv('theme.path').'form/login/password_recovery',$data);
|
||||
echo view(getenv('theme.path').'login/footer');
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error', lang("App.login_alert"), lang("App.login_alert_invalid_token")]);
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error', lang("App.login_alert"), lang("App.login_alert_empty_token")]);
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function recovery_store()
|
||||
{
|
||||
$session = session();
|
||||
|
||||
helper('form');
|
||||
|
||||
$rules = [
|
||||
'password' => 'required|min_length[8]'
|
||||
];
|
||||
|
||||
$rules_error = [
|
||||
'password' => [
|
||||
'required' => lang("App.login_rules_password_r"),
|
||||
'min_length' => lang("App.login_rules_password_m")
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->validate($rules,$rules_error)){
|
||||
if($listPost = $this->request->getPost()) {
|
||||
$pass_recovery = $this->pass_recovery_model->where('user',$listPost['user'])->where('token',$listPost['token'])->where('changed',false)->first();
|
||||
if($pass_recovery != null){
|
||||
$user = $this->user_model->select('id_user')->where('token',$listPost['user'])->first();
|
||||
if($user != null){
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$this->user_model->save([
|
||||
'id_user' => $user['id_user'],
|
||||
'password' => $phpass->HashPassword($listPost['password'])
|
||||
]);
|
||||
$this->pass_recovery_model->save([
|
||||
'id_pass_recovery' => $pass_recovery['id_pass_recovery'],
|
||||
'changed' => true
|
||||
]);
|
||||
$session->setFlashdata('toast', ['success', lang("App.login_alert_success"), lang("App.login_alert_success_recovery")]);
|
||||
}
|
||||
}
|
||||
return redirect()->to('/login');
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error', lang("App.login_alert"), lang("App.login_alert_parameter_invalid")]);
|
||||
$this->recovery($this->request->getVar('token'));
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('error','error');
|
||||
$this->recovery($this->request->getVar('token'));
|
||||
}
|
||||
}
|
||||
|
||||
public function confirmation($token=null)
|
||||
{
|
||||
$session = session();
|
||||
if(!empty($token)){
|
||||
$confirmation = $this->confirmation_model->where('token',$token)->where('confirmed',false)->first();
|
||||
if($confirmation != null){
|
||||
$user = $this->user_model->select('id_user')->where('token',$confirmation['user'])->first();
|
||||
if($confirmation['type'] == 'email'){
|
||||
$this->user_model->save([
|
||||
'id_user'=>$user['id_user'],
|
||||
'email_confirmed'=>true
|
||||
]);
|
||||
}
|
||||
$this->confirmation_model->save([
|
||||
'id_confirmation'=>$confirmation['id_confirmation'],
|
||||
'confirmed'=>true
|
||||
]);
|
||||
$session->setFlashdata('toast', ['success', lang("App.login_alert_success"), lang("App.login_alert_success_confirmation")]);
|
||||
return redirect()->to('/login');
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error', lang("App.login_alert"), lang("App.login_alert_invalid_token")]);
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('toast', ['error', lang("App.login_alert"), lang("App.login_alert_empty_token")]);
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ci4/app/Controllers/Migrate.php
Normal file
24
ci4/app/Controllers/Migrate.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
use Throwable;
|
||||
|
||||
class Migrate extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$migrate = \Config\Services::migrations();
|
||||
|
||||
try {
|
||||
#$migrate->regress(-1);
|
||||
$migrate->latest();
|
||||
echo "migrated";
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
95
ci4/app/Controllers/My.php
Normal file
95
ci4/app/Controllers/My.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\NotificationModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class My extends BaseController
|
||||
{
|
||||
|
||||
private $user_model;
|
||||
private $notification_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->notification_model = new NotificationModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return redirect()->to('profile');
|
||||
}
|
||||
|
||||
public function notification()
|
||||
{
|
||||
$session = session();
|
||||
$data['title'] = [
|
||||
'module' => lang("App.notification_title_my"),
|
||||
'page' => lang("App.notification_subtitle_my"),
|
||||
'icon' => 'fas fa-bell'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.notification_title_my"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_add'] = [
|
||||
'title' => lang("App.notification_btn_add"),
|
||||
'route' => '/notification/add',
|
||||
'class' => 'btn btn-lg btn-primary float-md-right',
|
||||
'icon' => 'fas fa-plus'
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/my/notification',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function notification_view($id)
|
||||
{
|
||||
$session = session();
|
||||
$data['obj'] = $this->notification_model->where('token', $id)->first();
|
||||
if($data['obj']==null){
|
||||
return redirect()->to('/my/notification');
|
||||
}else{
|
||||
if(!$data['obj']['is_read']){
|
||||
$this->notification_model->save(['id_notification' => $data['obj']['id_notification'],'is_read' => true]);
|
||||
$notification = $session->get('notification')??[];
|
||||
foreach ($notification as $key => $value){
|
||||
if($notification[$key]['token'] == $id){
|
||||
$notification[$key]['is_read'] = '1';
|
||||
}
|
||||
}
|
||||
$pulse = $this->notification_model->where('user_recipient',$session->get('token'))->where('is_read',false)->countAllResults() ?? 0;
|
||||
$session->set('pulse', $pulse);
|
||||
$session->set('notification',$notification);
|
||||
}
|
||||
}
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.notification_title_my"),
|
||||
'page' => lang("App.notification_subtitle_view"),
|
||||
'icon' => 'far fa-envelope-open'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.notification_title_my"), 'route' => "/my/notification", 'active' => false],
|
||||
['title' => lang("App.notification_subtitle_view"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/my/notification',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/my/view',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
}
|
||||
190
ci4/app/Controllers/Notification.php
Normal file
190
ci4/app/Controllers/Notification.php
Normal file
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\CountriesModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Models\NotificationModel;
|
||||
|
||||
class Notification extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $countries_model;
|
||||
private $id_user;
|
||||
private $token_user;
|
||||
private $notification_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->countries_model = new CountriesModel();
|
||||
$this->id_user = session()->get('id_user');
|
||||
$this->token_user = session()->get('token');
|
||||
$this->notification_model = new NotificationModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = [
|
||||
'module' => lang("App.notification_title"),
|
||||
'page' => lang("App.notification_subtitle"),
|
||||
'icon' => 'fas fa-bell'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.notification_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_add'] = [
|
||||
'title' => lang("App.notification_btn_add"),
|
||||
'route' => '/notification/add',
|
||||
'class' => 'btn btn-lg btn-primary float-md-right',
|
||||
'icon' => 'fas fa-plus'
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/notification/index',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
helper('form');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.notification_add_title"),
|
||||
'page' => lang("App.notification_add_subtitle"),
|
||||
'icon' => 'far fa-plus-square'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.notification_title"), 'route' => "/user", 'active' => false],
|
||||
['title' => lang("App.notification_add_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/notification',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
$data['user'] = $this->user_model->where('status',true)->findAll();
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/notification/form',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/notification');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
helper('form');
|
||||
|
||||
$rules = [
|
||||
'title' => 'required',
|
||||
'body' => 'required'
|
||||
];
|
||||
|
||||
$rules_error = [
|
||||
'title' => [
|
||||
'required' => lang("App.notification_rules_title_r"),
|
||||
],
|
||||
'body' => [
|
||||
'required' => lang("App.notification_rules_body_r"),
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->validate($rules,$rules_error)){
|
||||
if($listPost = $this->request->getPost()){
|
||||
|
||||
$listPost['send_email_notification'] = isset($listPost['send_email_notification']) && $listPost['send_email_notification'] == 'on';
|
||||
|
||||
if(!empty($listPost['user_recipient'])){
|
||||
$user = $this->user_model->where('token',$session->get('token'))->first();
|
||||
foreach (keywordEmail()??[] as $item){
|
||||
$field = str_replace(['[','user_',']'],'',$item);
|
||||
$listPost['title'] = str_replace('['.$item.']',$user[$field],$listPost['title']);
|
||||
$listPost['body'] = str_replace('['.$item.']',$user[$field],$listPost['body']);
|
||||
}
|
||||
$listPost['token'] = md5(uniqid(rand(), true));
|
||||
$listPost['user_sender'] = $session->get('token');
|
||||
$this->notification_model->save($listPost);
|
||||
}else{
|
||||
$users = $this->user_model->where('status',true)->findAll();
|
||||
$data = [];
|
||||
foreach ($users as $user){
|
||||
$title = $listPost['title'];
|
||||
$template = $listPost['body'];
|
||||
foreach (keywordEmail()??[] as $item){
|
||||
$field = str_replace(['[','user_',']'],'',$item);
|
||||
$title = str_replace('['.$item.']',$user[$field],$title);
|
||||
$template = str_replace('['.$item.']',$user[$field],$template);
|
||||
}
|
||||
array_push($data,[
|
||||
'id_notification' => null,
|
||||
'user_sender' => $session->get('token'),
|
||||
'user_recipient' => $user['token'],
|
||||
'title' => $title,
|
||||
'body' => $template,
|
||||
'is_read' => false,
|
||||
'is_send_email' => false,
|
||||
'send_email_notification' => $listPost['send_email_notification'],
|
||||
'token' => md5(uniqid(rand(), true)),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
if(count($data)>0){
|
||||
$this->notification_model->insertBatch($data);
|
||||
}
|
||||
}
|
||||
if(empty($this->request->getPost('id_notification'))){
|
||||
$session->setFlashdata('sweet', ['success',lang("App.notification_alert_add")]);
|
||||
return redirect()->to('/notification');
|
||||
}else{
|
||||
$session->setFlashdata('sweet', ['success',lang("App.notification_alert_edit")]);
|
||||
return redirect()->to('/notification');
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('error','error');
|
||||
$this->add();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($token)
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/notification');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
if(!empty($session->get('token'))){
|
||||
$this->notification_model->where('token', $token)->delete();
|
||||
$session->setFlashdata('sweet', ['success',lang("App.notification_alert_delete")]);
|
||||
return redirect()->to('/notification');
|
||||
}else{
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
194
ci4/app/Controllers/Profile.php
Normal file
194
ci4/app/Controllers/Profile.php
Normal file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\PasswordHash;
|
||||
use App\Models\CountriesModel;
|
||||
use App\Models\UserGroupModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class Profile extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $countries_model;
|
||||
private $id_user;
|
||||
private $token_user;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->countries_model = new CountriesModel();
|
||||
$this->id_user = session()->get('id_user');
|
||||
$this->token_user = session()->get('token');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
helper('file');
|
||||
helper('form');
|
||||
helper('text');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.profile_title"),
|
||||
'page' => lang("App.profile_subtitle"),
|
||||
'icon' => 'fas fa-user'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.profile_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
$session = session();
|
||||
|
||||
$data['obj'] = $this->user_model->where('id_user',$this->id_user)->first();
|
||||
if(!empty($data['obj']['date_birth'])){
|
||||
$data['obj']['date_birth'] = dateFormatWeb($data['obj']['date_birth']);
|
||||
}
|
||||
$data['country'] = $this->countries_model->select('code,name')->where('data_lang',session()->get('lang')??'en')->findAll();
|
||||
|
||||
$file = $this->request->getFile('file');
|
||||
if(!empty($file)){
|
||||
$integration = new Integration();
|
||||
$allow = ['jpeg','jpg','gif','bmp','png'];
|
||||
$path = 'assets/img/';
|
||||
$pathRet = '/'.$integration->saveStorage($file,$path,$allow);
|
||||
if(!empty($pathRet)){
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->id_user,
|
||||
'picture' => $pathRet
|
||||
]);
|
||||
$data['obj']['picture'] = $pathRet;
|
||||
$session->set('picture',$pathRet);
|
||||
}
|
||||
}else{
|
||||
if(!empty($this->request->getPost())){
|
||||
$post = $this->request->getPost();
|
||||
$image = '';
|
||||
foreach ($post as $key=>$value){
|
||||
if(strpos($key, 'image') !== false){
|
||||
$image = $value;
|
||||
}
|
||||
}
|
||||
if(!empty($image)){
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->id_user,
|
||||
'picture' => $image
|
||||
]);
|
||||
$data['obj']['picture'] = $image;
|
||||
$session->set('picture',$image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/profile/index', $data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/profile');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
helper('form');
|
||||
|
||||
$password = 'max_length[35]';
|
||||
$confirm_password = 'max_length[35]';
|
||||
|
||||
if(!empty($this->request->getPost('password'))){
|
||||
$password = 'required|min_length[8]';
|
||||
$confirm_password = 'matches[password]';
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'password' => $password,
|
||||
'confirm_password' => $confirm_password
|
||||
];
|
||||
|
||||
$rules_error = [
|
||||
'first_name' => ['required' => lang("App.profile_rules_first_name_r")],
|
||||
'last_name' => ['required' => lang("App.profile_rules_last_name_r")],
|
||||
'password' => [
|
||||
'required' => lang("App.profile_rules_password_r"),
|
||||
'min_length' => lang("App.profile_rules_password_m")
|
||||
],
|
||||
'confirm_password' => ['matches' => lang("App.profile_rules_password_confirm_m")]
|
||||
];
|
||||
|
||||
if(empty($this->request->getPost('tfa_secret'))){
|
||||
if ($this->validate($rules??[],$rules_error??[])){
|
||||
if(!empty($this->id_user)){
|
||||
$date_birth = !empty($this->request->getPost('date_birth')??'') ? dateFormatMysql($this->request->getPost('date_birth')):null;
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->id_user,
|
||||
'first_name' => $this->request->getPost('first_name'),
|
||||
'last_name' => $this->request->getPost('last_name'),
|
||||
'date_birth' => $date_birth,
|
||||
'address' => $this->request->getPost('address'),
|
||||
'city' => $this->request->getPost('city'),
|
||||
'state' => $this->request->getPost('state'),
|
||||
'country' => $this->request->getPost('country'),
|
||||
'zip_code' => $this->request->getPost('zip_code'),
|
||||
'mobile' => $this->request->getPost('mobile'),
|
||||
'language' => $this->request->getPost('language')
|
||||
]);
|
||||
$session->set('lang', $this->request->getPost('language') ?? 'en');
|
||||
if(!empty($this->request->getPost('password'))){
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->id_user,
|
||||
'password' => $phpass->HashPassword($this->request->getPost('password')),
|
||||
]);
|
||||
}
|
||||
$session->setFlashdata('sweet', ['success',lang("App.global_alert_save_success")]);
|
||||
}else{
|
||||
$session->setFlashdata('sweet', ['error',lang("App.global_alert_save_error")]);
|
||||
}
|
||||
}else{
|
||||
|
||||
$session->setFlashdata('error','error');
|
||||
return $this->index();
|
||||
}
|
||||
}else{
|
||||
if($this->request->getPost('tfa') == 'on'){
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->id_user,
|
||||
'tfa' => true,
|
||||
'tfa_secret' => $this->request->getPost('tfa_secret'),
|
||||
'tfa_code' => $this->request->getPost('tfa_code')
|
||||
]);
|
||||
}else{
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->id_user,
|
||||
'tfa' => false,
|
||||
'tfa_secret' => '',
|
||||
'tfa_code' => ''
|
||||
]);
|
||||
}
|
||||
$session->setFlashdata('sweet', ['success',lang("App.global_alert_save_success")]);
|
||||
}
|
||||
return redirect()->to('/profile');
|
||||
}
|
||||
}
|
||||
220
ci4/app/Controllers/Settings.php
Normal file
220
ci4/app/Controllers/Settings.php
Normal file
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\CountriesModel;
|
||||
use App\Models\CronTabModel;
|
||||
use App\Models\CurrencyModel;
|
||||
use App\Models\SettingsModel;
|
||||
use App\Models\TemplateModel;
|
||||
use App\Models\ThemeModel;
|
||||
use App\Models\TimezoneModel;
|
||||
use App\Models\UserGroupModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class Settings extends BaseController
|
||||
{
|
||||
private $settings_model;
|
||||
private $countries_model;
|
||||
private $theme_model;
|
||||
private $currency_model;
|
||||
private $timezone_model;
|
||||
private $group_model;
|
||||
private $template_model;
|
||||
private $user_model;
|
||||
private $crontab_model;
|
||||
private $integration;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->settings_model = new SettingsModel();
|
||||
$this->countries_model = new CountriesModel();
|
||||
$this->theme_model = new ThemeModel();
|
||||
$this->currency_model = new CurrencyModel();
|
||||
$this->timezone_model = new TimezoneModel();
|
||||
$this->group_model = new UserGroupModel();
|
||||
$this->template_model = new TemplateModel();
|
||||
$this->user_model = new UserModel();
|
||||
$this->crontab_model = new CronTabModel();
|
||||
$this->integration = new Integration();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
helper('form');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.settings_title"),
|
||||
'page' => lang("App.settings_subtitle"),
|
||||
'icon' => 'fas fa-sliders-h'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.menu_settings"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/home',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
$data['obj'] = $this->settings_model->first();
|
||||
$data['countries'] = $this->countries_model->select('id_country,code,name')->where('data_lang',session()->get('lang')??'en')->findAll();
|
||||
$data['theme'] = $this->theme_model->select('id_theme,type,name')->findAll();
|
||||
$data['currency'] = $this->currency_model->select('id_currency,code,name')->findAll();
|
||||
$data['timezone'] = $this->timezone_model->select('id_timezone,timezone,description')->findAll();
|
||||
$data['group'] = $this->group_model->select('token,title')->findAll();
|
||||
$db = db_connect('default');
|
||||
$data['tables'] = $db->listTables();
|
||||
$data['user'] = $this->user_model->select('token,first_name,email')->where('status',true)->findAll();
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/settings/index', $data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/settings');
|
||||
}
|
||||
|
||||
helper('form');
|
||||
$session = session();
|
||||
if($listPost = $this->request->getPost()){
|
||||
$listPost['id_settings'] = 1;
|
||||
$listPost['captcha_register'] = isset($listPost['captcha_register']) && $listPost['captcha_register'] == 'on';
|
||||
$listPost['captcha_login'] = isset($listPost['captcha_login']) && $listPost['captcha_login'] == 'on';
|
||||
$listPost['captcha_recovery'] = isset($listPost['captcha_recovery']) && $listPost['captcha_recovery'] == 'on';
|
||||
$listPost['registration'] = isset($listPost['registration']) && $listPost['registration'] == 'on';
|
||||
$listPost['terms_conditions'] = isset($listPost['terms_conditions']) && $listPost['terms_conditions'] == 'on';
|
||||
$listPost['email_confirmation'] = isset($listPost['email_confirmation']) && $listPost['email_confirmation'] == 'on';
|
||||
$listPost['send_email_register'] = isset($listPost['send_email_register']) && $listPost['send_email_register'] == 'on';
|
||||
$listPost['send_notification_register'] = isset($listPost['send_notification_register']) && $listPost['send_notification_register'] == 'on';
|
||||
$listPost['send_email_welcome'] = isset($listPost['send_email_welcome']) && $listPost['send_email_welcome'] == 'on';
|
||||
$listPost['remember_me'] = isset($listPost['remember_me']) && $listPost['remember_me'] == 'on';
|
||||
$listPost['forgot_password'] = isset($listPost['forgot_password']) && $listPost['forgot_password'] == 'on';
|
||||
$listPost['two_factor_auth'] = isset($listPost['two_factor_auth']) && $listPost['two_factor_auth'] == 'on';
|
||||
$listPost['throttle_auth'] = isset($listPost['throttle_auth']) && $listPost['throttle_auth'] == 'on';
|
||||
$listPost['enable_api'] = isset($listPost['enable_api']) && $listPost['enable_api'] == 'on';
|
||||
$listPost['block_external_api'] = isset($listPost['block_external_api']) && $listPost['block_external_api'] == 'on';
|
||||
$listPost['remove_log'] = isset($listPost['remove_log']) && $listPost['remove_log'] == 'on';
|
||||
$listPost['backup_notification_email'] = isset($listPost['backup_notification_email']) && $listPost['backup_notification_email'] == 'on';
|
||||
$listPost['backup_automatic'] = isset($listPost['backup_automatic']) && $listPost['backup_automatic'] == 'on';
|
||||
$listPost['backup_table'] = implode(",",$listPost['backup_table']??[]);
|
||||
$this->settings_model->save($listPost);
|
||||
$settings = $this->settings_model->first()??[];
|
||||
$session->set('settings', $settings);
|
||||
$session->set('lang', $settings['default_language'] ?? 'en');
|
||||
$session->setFlashdata('sweet', ['success',lang("App.settings_alert_add")]);
|
||||
return redirect()->to('/settings');
|
||||
} else{
|
||||
$session->setFlashdata('sweet', ['error',lang("App.settings_alert_error")]);
|
||||
return redirect()->to('/settings');
|
||||
}
|
||||
}
|
||||
|
||||
public function template()
|
||||
{
|
||||
helper('form');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.template_title"),
|
||||
'page' => lang("App.template_subtitle"),
|
||||
'icon' => 'fas fa-mail-bulk'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.menu_settings"), 'route' => "/settings", 'active' => false],
|
||||
['title' => lang("App.template_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/home',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
$data['template'] = $this->template_model->findAll();
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/settings/template', $data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function template_store()
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/settings/template');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
helper('form');
|
||||
|
||||
if($field = $this->request->getPost()){
|
||||
$ids = [];
|
||||
$template = [];
|
||||
unset($field['files']);
|
||||
foreach ($field as $key=>$value){
|
||||
$id = explode('_',$key);
|
||||
array_push($ids,$id[2]);
|
||||
}
|
||||
foreach (array_unique($ids) as $item){
|
||||
$template[$item] = [];
|
||||
foreach ($field as $key=>$value){
|
||||
$id = explode('_',$key);
|
||||
if($id[2] == $item){
|
||||
if(empty($template[$item])){
|
||||
$template[$item] = array_merge( $template[$item],['id_template' => intval($id[2])]);
|
||||
$template[$item] = array_merge( $template[$item],['subject' => ""]);
|
||||
$template[$item] = array_merge( $template[$item],['body' => ""]);
|
||||
}
|
||||
switch($id[1])
|
||||
{
|
||||
case 'email';
|
||||
switch($id[0])
|
||||
{
|
||||
case 'title';
|
||||
$template[$item] = array_merge( $template[$item],['subject' => $value]);
|
||||
break;
|
||||
default;
|
||||
$template[$item] = array_merge( $template[$item],[$id[0] => $value]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->template_model->updateBatch($template,'id_template');
|
||||
$session->setFlashdata('sweet', ['success',lang("App.template_alert_add")]);
|
||||
return redirect()->to('/settings/template');
|
||||
} else{
|
||||
$session->setFlashdata('sweet', ['error',lang("App.template_alert_error")]);
|
||||
return redirect()->to('/settings/template');
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ci4/app/Controllers/Test.php
Normal file
24
ci4/app/Controllers/Test.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
|
||||
class Test extends BaseController
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
["id_user"]=>
|
||||
string(1) "1"
|
||||
$test = [
|
||||
"115b5ad39b853084209caf6824224f6b",
|
||||
"fff26488a4249d76a8de5c0426acb8f7",
|
||||
"72f5e898a67bb2fb72b185d9138585b2"];
|
||||
|
||||
echo "Hola";
|
||||
}
|
||||
}
|
||||
311
ci4/app/Controllers/User.php
Normal file
311
ci4/app/Controllers/User.php
Normal file
@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\PasswordHash;
|
||||
use App\Models\ActivityModel;
|
||||
use App\Models\CountriesModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Models\UserGroupModel;
|
||||
use App\Models\GroupUserModel;
|
||||
|
||||
class User extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $group_model;
|
||||
private $group_user_model;
|
||||
private $countries_model;
|
||||
private $activity_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->group_model = new UserGroupModel();
|
||||
$this->countries_model = new CountriesModel();
|
||||
$this->activity_model = new ActivityModel();
|
||||
$this->group_user_model = new GroupUserModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = [
|
||||
'module' => lang("App.user_title"),
|
||||
'page' => lang("App.user_subtitle"),
|
||||
'icon' => 'fas fa-user-friends'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.user_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_add'] = [
|
||||
'title' => lang("App.user_btn_add"),
|
||||
'route' => '/user/add',
|
||||
'class' => 'btn btn-lg btn-primary float-md-right',
|
||||
'icon' => 'fas fa-plus'
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/user/index',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
helper('form');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.user_add_title"),
|
||||
'page' => lang("App.user_add_subtitle"),
|
||||
'icon' => 'far fa-plus-square'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.user_title"), 'route' => "/user", 'active' => false],
|
||||
['title' => lang("App.user_add_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/user',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
$data['group'] = $this->group_user_model->select('token,title')->findAll();
|
||||
$data['country'] = $this->countries_model->select('code,name')->where('data_lang',session()->get('lang')??'en')->findAll();
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/user/form',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function edit($token=null)
|
||||
{
|
||||
if(empty($token)){
|
||||
return redirect()->to('/user');
|
||||
}
|
||||
|
||||
helper('form');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.user_edit_title"),
|
||||
'page' => lang("App.user_edit_subtitle"),
|
||||
'icon' => 'fas fa-edit'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.user_title"), 'route' => "/user", 'active' => false],
|
||||
['title' => lang("App.user_edit_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/user',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
$data['obj'] = $this->user_model->where('token', $token)->first();
|
||||
if($data['obj']==null){
|
||||
return redirect()->to('/user');
|
||||
}
|
||||
if(!empty($data['obj']['date_birth'])){
|
||||
$data['obj']['date_birth'] = dateFormatWeb($data['obj']['date_birth']);
|
||||
}
|
||||
|
||||
$data['selected_groups'] = $this->group_user_model->select('token_group')->where('token_user', $token)->findAll();
|
||||
$data['group'] = $this->group_model->select('token,title')->findAll();
|
||||
$data['country'] = $this->countries_model->select('code,name')->where('data_lang',session()->get('lang')??'en')->findAll();
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/user/form',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/user');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
helper('form');
|
||||
|
||||
$password = 'max_length[35]';
|
||||
$confirm_password = 'max_length[35]';
|
||||
$email = 'required|valid_email';
|
||||
|
||||
if(empty($this->request->getPost('id_user'))){
|
||||
$email = 'required|valid_email|is_unique[user.email]';
|
||||
$password = 'required|min_length[8]';
|
||||
$confirm_password = 'matches[password]';
|
||||
}else{
|
||||
if(!empty($this->request->getPost('password'))){
|
||||
$password = 'required|min_length[8]';
|
||||
$confirm_password = 'matches[password]';
|
||||
}
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'confirm_password' => $confirm_password
|
||||
];
|
||||
|
||||
$rules_error = [
|
||||
'first_name' => [
|
||||
'required' => lang("App.user_rules_first_name_r"),
|
||||
],
|
||||
'last_name' => [
|
||||
'required' => lang("App.user_rules_last_name_r"),
|
||||
],
|
||||
'email' => [
|
||||
'required' => lang("App.user_rules_email_r"),
|
||||
'is_unique' => lang("App.user_rules_email_i"),
|
||||
],
|
||||
'password' => [
|
||||
'required' => lang("App.user_rules_password_r"),
|
||||
'min_length' => lang("App.user_rules_password_m"),
|
||||
],
|
||||
'confirm_password' => [
|
||||
'matches' => lang("App.user_rules_password_confirm_m"),
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->validate($rules,$rules_error)){
|
||||
$date_birth = !empty($this->request->getPost('date_birth')??'') ? dateFormatMysql($this->request->getPost('date_birth')):null;
|
||||
if(empty($this->request->getPost('id_user'))){
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$this->user_model->save([
|
||||
'id_user' => null,
|
||||
'group' => $this->request->getPost('group'),
|
||||
'first_name' => $this->request->getPost('first_name'),
|
||||
'last_name' => $this->request->getPost('last_name'),
|
||||
'date_birth' => $date_birth,
|
||||
'address' => $this->request->getPost('address'),
|
||||
'city' => $this->request->getPost('city'),
|
||||
'state' => $this->request->getPost('state'),
|
||||
'country' => $this->request->getPost('country'),
|
||||
'zip_code' => $this->request->getPost('zip_code'),
|
||||
'mobile' => $this->request->getPost('mobile'),
|
||||
'email' => $this->request->getPost('email'),
|
||||
'password' => $phpass->HashPassword($this->request->getPost('password')),
|
||||
'last_access' => date('Y-m-d h:i:s'),
|
||||
'last_ip' => '::1',
|
||||
'picture' => '/assets/img/default-user.png',
|
||||
'language' => $this->request->getPost('language'),
|
||||
'token' => md5(uniqid(rand(), true)),
|
||||
'status' => $this->request->getPost('status'),
|
||||
'email_confirmed' => $this->request->getPost('email_confirmed')
|
||||
]);
|
||||
|
||||
}else{
|
||||
|
||||
echo "<pre>";
|
||||
var_dump($this->request->getPost());
|
||||
echo "</pre>" ;
|
||||
|
||||
dd();
|
||||
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->request->getPost('id_user'),
|
||||
//'group' => $this->request->getPost('group'),
|
||||
'first_name' => $this->request->getPost('first_name'),
|
||||
'last_name' => $this->request->getPost('last_name'),
|
||||
'date_birth' => $date_birth,
|
||||
'address' => $this->request->getPost('address'),
|
||||
'city' => $this->request->getPost('city'),
|
||||
'state' => $this->request->getPost('state'),
|
||||
'country' => $this->request->getPost('country'),
|
||||
'zip_code' => $this->request->getPost('zip_code'),
|
||||
'mobile' => $this->request->getPost('mobile'),
|
||||
'email' => $this->request->getPost('email'),
|
||||
'language' => $this->request->getPost('language'),
|
||||
'status' => $this->request->getPost('status'),
|
||||
'email_confirmed' => $this->request->getPost('email_confirmed')
|
||||
]);
|
||||
if(!empty($this->request->getPost('password'))){
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->request->getPost('id_user'),
|
||||
'password' => $phpass->HashPassword($this->request->getPost('password')),
|
||||
]);
|
||||
}
|
||||
|
||||
$user_token = $this->user_model
|
||||
->select('token')
|
||||
->where('id_user',$this->request->getPost('id_user'))->first();
|
||||
|
||||
|
||||
$this->group_user_model->delete(['user_token' => $user_token]);
|
||||
$groups = implode(",",$this->request->getPost('group')??[]);
|
||||
foreach ($groups as $group){
|
||||
$group_user_data = [
|
||||
'token_user' => $this->request->getPost('id_user'),
|
||||
'token_group' => $group
|
||||
];
|
||||
$this->group_user_model->insert($group_user_data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(empty($this->request->getPost('id_user'))){
|
||||
$session->setFlashdata('sweet', ['success',lang("App.user_alert_add")]);
|
||||
return redirect()->to('/user');
|
||||
}else{
|
||||
if($session->get('id_user') == $this->request->getPost('id_user')){
|
||||
$access_rules = $this->group_model->select('rules')->where('token',$this->request->getPost('group'))->first();
|
||||
$session->set('rules', html_entity_decode($access_rules['rules']));
|
||||
}
|
||||
$session->setFlashdata('sweet', ['success',lang("App.user_alert_edit")]);
|
||||
return redirect()->to('/user');
|
||||
}
|
||||
|
||||
}else{
|
||||
$session->setFlashdata('error','error');
|
||||
$this->add();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($token)
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/user');
|
||||
}
|
||||
$session = session();
|
||||
if(!empty($session->get('token'))){
|
||||
$this->user_model->where('token', $token)->delete();
|
||||
$this->activity_model->where('user', $token)->delete();
|
||||
$session->setFlashdata('sweet', ['success',lang("App.user_alert_delete")]);
|
||||
return redirect()->to('/user');
|
||||
}else{
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user