Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
dd05e37c8a
@ -45,6 +45,9 @@ class Database extends Config
|
|||||||
'numberNative' => false,
|
'numberNative' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public array $book_stack = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This database connection is used when
|
* This database connection is used when
|
||||||
* running PHPUnit database tests.
|
* running PHPUnit database tests.
|
||||||
@ -75,6 +78,29 @@ class Database extends Config
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
// Initialize book_stack configuration with environment variables
|
||||||
|
$this->book_stack = [
|
||||||
|
'DSN' => '',
|
||||||
|
'hostname' => getenv('bookStack_hostname'),
|
||||||
|
'username' => getenv('bookStack_username'),
|
||||||
|
'password' => getenv('bookStack_password'),
|
||||||
|
'database' => getenv('bookStack_database'),
|
||||||
|
'DBDriver' => 'MySQLi',
|
||||||
|
'DBPrefix' => '',
|
||||||
|
'pConnect' => false,
|
||||||
|
'DBDebug' => true,
|
||||||
|
'charset' => 'utf8',
|
||||||
|
'DBCollat' => 'utf8_general_ci',
|
||||||
|
'swapPre' => '',
|
||||||
|
'encrypt' => false,
|
||||||
|
'compress' => false,
|
||||||
|
'strictOn' => false,
|
||||||
|
'failover' => [],
|
||||||
|
'port' => 3306,
|
||||||
|
'foreignKeys' => true,
|
||||||
|
'busyTimeout' => 1000,
|
||||||
|
];
|
||||||
|
|
||||||
// Ensure that we always set the database group to 'tests' if
|
// Ensure that we always set the database group to 'tests' if
|
||||||
// we are currently running an automated test suite, so that
|
// we are currently running an automated test suite, so that
|
||||||
// we don't overwrite live data on accident.
|
// we don't overwrite live data on accident.
|
||||||
@ -82,4 +108,5 @@ class Database extends Config
|
|||||||
$this->defaultGroup = 'tests';
|
$this->defaultGroup = 'tests';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -508,21 +508,25 @@ class RestAuthenticationController extends AdminController
|
|||||||
// TokenController.php
|
// TokenController.php
|
||||||
public function bookstackLoginToken()
|
public function bookstackLoginToken()
|
||||||
{
|
{
|
||||||
// $user = session()->get('user');
|
$session = \Config\Services::session();
|
||||||
// $secret = getenv('BOOKSTACK_TOKEN_SECRET');
|
$user_data = session()->get('userData');
|
||||||
$user = 'staff@staff.com';
|
$user = $user_data->email;
|
||||||
$secret = '5a8c1e9b18e6a94f724f6a6b36b6f26d9eec0e4a15e88b6e3e2d5efad23a8f4f';
|
$secret = getenv('bookstack.token');
|
||||||
|
// $user = 'staff@staff.com';
|
||||||
|
$name = $user_data->first_name ?? 'User';
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'email' => $user,
|
'email' => $user,
|
||||||
'name' => 'Hi',
|
'name' => $name,
|
||||||
'exp' => time() + 60 // expires in 1 minute
|
'exp' => time() + (60 * 60 * 24) // expires in 1 day
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// dd($payload);
|
||||||
$token = base64_encode(json_encode($payload));
|
$token = base64_encode(json_encode($payload));
|
||||||
$signature = hash_hmac('sha256', $token, $secret);
|
$signature = hash_hmac('sha256', $token, $secret);
|
||||||
|
$bookStackUrl = getenv('bookstack.baseURL');
|
||||||
|
|
||||||
$url = 'https://localhost/PHP828APPS/manual/bookstack/public/autologin?token=' . urlencode($token) . '&sig=' . $signature;
|
$url = $bookStackUrl . urlencode($token) . '&sig=' . $signature;
|
||||||
return redirect()->to($url);
|
return redirect()->to($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ use App\Models\UserModel;
|
|||||||
use App\Models\RoleModel;
|
use App\Models\RoleModel;
|
||||||
use App\Models\TeamModel;
|
use App\Models\TeamModel;
|
||||||
use App\Models\UserTeamsModel;
|
use App\Models\UserTeamsModel;
|
||||||
|
use App\Helpers\BookStackUserHelper;
|
||||||
|
|
||||||
|
|
||||||
class UserController extends AdminController
|
class UserController extends AdminController
|
||||||
@ -21,6 +22,7 @@ class UserController extends AdminController
|
|||||||
protected $roleModel;
|
protected $roleModel;
|
||||||
protected $teamModel;
|
protected $teamModel;
|
||||||
protected $userTeamsModel;
|
protected $userTeamsModel;
|
||||||
|
protected $bookStack;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -31,6 +33,7 @@ class UserController extends AdminController
|
|||||||
$this->roleModel = new RoleModel();
|
$this->roleModel = new RoleModel();
|
||||||
$this->teamModel = new TeamModel();
|
$this->teamModel = new TeamModel();
|
||||||
$this->userTeamsModel = new UserTeamsModel();
|
$this->userTeamsModel = new UserTeamsModel();
|
||||||
|
$this->bookStack = new BookStackUserHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function list()
|
public function list()
|
||||||
@ -60,10 +63,17 @@ class UserController extends AdminController
|
|||||||
$userData['created_by'] = get_session_userid();
|
$userData['created_by'] = get_session_userid();
|
||||||
$temp_team = $userData['team'];
|
$temp_team = $userData['team'];
|
||||||
unset($userData['team']);
|
unset($userData['team']);
|
||||||
|
|
||||||
$insert = $this->userModel->insert($userData);
|
$insert = $this->userModel->insert($userData);
|
||||||
|
|
||||||
if ($insert) {
|
$bookStackData = [
|
||||||
|
'name' => $userData['first_name'],
|
||||||
|
'email' => $userData['email'],
|
||||||
|
|
||||||
|
];
|
||||||
|
$this->bookStack->createEditUser($bookStackData);
|
||||||
|
|
||||||
|
if ($insert) {
|
||||||
$teamData['user_id'] = $insert;
|
$teamData['user_id'] = $insert;
|
||||||
foreach ($teams as $value) {
|
foreach ($teams as $value) {
|
||||||
$teamData['team_id'] = $value;
|
$teamData['team_id'] = $value;
|
||||||
@ -137,10 +147,20 @@ class UserController extends AdminController
|
|||||||
unset($userData['csrf_test_name']);
|
unset($userData['csrf_test_name']);
|
||||||
unset($userData['PrimaryKey']);
|
unset($userData['PrimaryKey']);
|
||||||
|
|
||||||
|
$existingData = $this->userModel->where('id',$id)->first();;
|
||||||
|
|
||||||
// Update data in the 'users' table based on the $id
|
// Update data in the 'users' table based on the $id
|
||||||
$userData['updated_by'] = get_session_userid();
|
$userData['updated_by'] = get_session_userid();
|
||||||
$update = $this->userModel->where('id', $id)->set($userData)->update();
|
$update = $this->userModel->where('id', $id)->set($userData)->update();
|
||||||
|
|
||||||
|
$bookStackData = [
|
||||||
|
'name' => $userData['first_name'],
|
||||||
|
'email' => $userData['email'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->bookStack->createEditUser($bookStackData,$existingData);
|
||||||
|
|
||||||
|
|
||||||
if ($update) {
|
if ($update) {
|
||||||
|
|
||||||
if ($teams) {
|
if ($teams) {
|
||||||
@ -211,7 +231,11 @@ class UserController extends AdminController
|
|||||||
public function deactive($id = null)
|
public function deactive($id = null)
|
||||||
{
|
{
|
||||||
$model = new UserModel();
|
$model = new UserModel();
|
||||||
|
|
||||||
|
$emailToDelete = $model->where('id', $id)->first();
|
||||||
$deactive = $model->where('id', $id)->set(['is_active' => 0])->update();
|
$deactive = $model->where('id', $id)->set(['is_active' => 0])->update();
|
||||||
|
|
||||||
|
$this->bookStack->deleteUser($emailToDelete);
|
||||||
if($deactive)
|
if($deactive)
|
||||||
{
|
{
|
||||||
// $db = \Config\Database::connect();
|
// $db = \Config\Database::connect();
|
||||||
|
|||||||
77
app/Helpers/BookStackUserHelper.php
Normal file
77
app/Helpers/BookStackUserHelper.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\BookStackUserModel;
|
||||||
|
use App\Models\BookStackRoleModel;
|
||||||
|
|
||||||
|
class BookStackUserHelper {
|
||||||
|
|
||||||
|
protected $userModel;
|
||||||
|
protected $roleModel;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->userModel = new BookStackUserModel();
|
||||||
|
$this->roleModel = new BookStackRoleModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createEditUser($data,$preData = null) {
|
||||||
|
// This function will handle the creation or editing of a user
|
||||||
|
// It will check if the user already exists and update or create accordingly
|
||||||
|
// The $data parameter should contain all necessary user information
|
||||||
|
// For example: ['name' => 'johndoe', 'email' => 'johndoe@doe.com']
|
||||||
|
|
||||||
|
if (!empty($preData)) {
|
||||||
|
|
||||||
|
$isExistingUser = $this->userModel->where('email', $preData['email'])->first();
|
||||||
|
|
||||||
|
if ($isExistingUser) {
|
||||||
|
$id = $isExistingUser['id'];
|
||||||
|
$update = $this->userModel->where('id', $id)->set($data)->update();
|
||||||
|
return $update;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$password = 'password';
|
||||||
|
$hashedPassword = ['password' => password_hash($password, PASSWORD_DEFAULT)];
|
||||||
|
|
||||||
|
$slug = ['slug' => $this->createSlug($data['name'])];
|
||||||
|
|
||||||
|
// array_push($data,$hashedPassword,$slug);
|
||||||
|
|
||||||
|
$data['password'] = $hashedPassword['password'];
|
||||||
|
$data['slug'] = $slug['slug'];
|
||||||
|
|
||||||
|
// dd($data);
|
||||||
|
$this->userModel->insert($data);
|
||||||
|
$userId = $this->userModel->insertID();
|
||||||
|
|
||||||
|
if (!empty($userId)) {
|
||||||
|
|
||||||
|
$roleData = [
|
||||||
|
'user_id' => $userId,
|
||||||
|
'role_id' => 3 // 3 is the default role ID for viewers
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->roleModel->insert($roleData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createSlug($string) {
|
||||||
|
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteUser($data) {
|
||||||
|
|
||||||
|
$isExistingUser = $this->userModel->where('email', $data['email'])->first();
|
||||||
|
if ($isExistingUser) {
|
||||||
|
$id = $isExistingUser['id'];
|
||||||
|
$delete = $this->userModel->where('id', $id)->delete();
|
||||||
|
$this->roleModel->where('user_id', $id)->delete();
|
||||||
|
return $delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Models/BookStackRoleModel.php
Normal file
19
app/Models/BookStackRoleModel.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class BookStackRoleModel extends Model
|
||||||
|
{
|
||||||
|
protected $DBGroup = 'book_stack';
|
||||||
|
protected $table = 'role_user';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $useAutoIncrement = true;
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $useSoftDelete = false;
|
||||||
|
protected $protectFields = true;
|
||||||
|
protected $allowedFields = [
|
||||||
|
'user_id','role_id'
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
19
app/Models/BookStackUserModel.php
Normal file
19
app/Models/BookStackUserModel.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class BookStackUserModel extends Model
|
||||||
|
{
|
||||||
|
protected $DBGroup = 'book_stack';
|
||||||
|
protected $table = 'users';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $useAutoIncrement = true;
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $useSoftDelete = false;
|
||||||
|
protected $protectFields = true;
|
||||||
|
protected $allowedFields = [
|
||||||
|
'name','email','password','slug'
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
@ -849,9 +849,9 @@
|
|||||||
<?php if (in_array(get_role_id(), [1,2,3,5])) { ?>
|
<?php if (in_array(get_role_id(), [1,2,3,5])) { ?>
|
||||||
<li>
|
<li>
|
||||||
<a id="app_content_management" href="#sidebarDashboardsmenu" data-toggle="collapse" class="waves-effect" style="color: grey;">
|
<a id="app_content_management" href="#sidebarDashboardsmenu" data-toggle="collapse" class="waves-effect" style="color: grey;">
|
||||||
<i class="fa fa-info-circle" aria-hidden="true"></i>
|
<i class="fa fa-edit" aria-hidden="true"></i>
|
||||||
<span class="badge badge-success badge-pill float-right">2</span>
|
<span class="badge badge-success badge-pill float-right">2</span>
|
||||||
<span> App Content Management </span>
|
<span>App Content Mgmt</span>
|
||||||
</a>
|
</a>
|
||||||
<div class="collapse" id="sidebarDashboardsmenu">
|
<div class="collapse" id="sidebarDashboardsmenu">
|
||||||
<ul class="nav-second-level">
|
<ul class="nav-second-level">
|
||||||
@ -865,7 +865,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
<li>
|
||||||
|
<a id="user_manual" href="<?= base_url("autobookstackLogin") ?>" class="waves-effect" target="_blank" rel="noopener noreferrer">
|
||||||
|
<i class="fa fa-info-circle" aria-hidden="true"></i>
|
||||||
|
<span>User Manual</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<!-- End Sidebar -->
|
<!-- End Sidebar -->
|
||||||
|
|||||||
0
writable/venbaehn_nhance_manual
Normal file
0
writable/venbaehn_nhance_manual
Normal file
Loading…
Reference in New Issue
Block a user