Conversie codeigniter 4
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class AuthorisationController extends BaseController
|
||||
{
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
die('NO ACCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Default action
|
||||
}
|
||||
|
||||
public function getRoleAuthorisations(): ResponseInterface
|
||||
{
|
||||
$roleAuthorisations = \Role::getPagesAccessByRole();
|
||||
|
||||
return $this->json($roleAuthorisations);
|
||||
}
|
||||
|
||||
public function toggleAuhorisation(): ResponseInterface
|
||||
{
|
||||
$pageID = $this->cleanInput('pageID');
|
||||
$roleLevel = $this->cleanInput('roleLevel');
|
||||
$access = $this->cleanInput('access');
|
||||
|
||||
$page = \Page::find($pageID);
|
||||
|
||||
if ($access == 'F') {
|
||||
$roleLevel = -$roleLevel;
|
||||
}
|
||||
|
||||
$page->pagelevel = $page->pagelevel + $roleLevel;
|
||||
|
||||
$page->save();
|
||||
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class CustomersController extends BaseController
|
||||
{
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
die('NO ACCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Default action
|
||||
}
|
||||
|
||||
public function getAllCustomers(string $archive = 'F'): ResponseInterface
|
||||
{
|
||||
$customers = \Customer::getAllCustomers($archive);
|
||||
|
||||
return $this->json($customers);
|
||||
}
|
||||
|
||||
public function saveCustomer(): ResponseInterface
|
||||
{
|
||||
$customerValidation = new \CustomerValidation();
|
||||
|
||||
if (!$customerValidation->getValidationResult()) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'messages' => $customerValidation->getErrorMessages()
|
||||
]);
|
||||
}
|
||||
|
||||
$customer = $this->request->getPost();
|
||||
|
||||
$customerID = $customer['id'];
|
||||
unset($customer['id']);
|
||||
|
||||
$customerID = \Customer::saveCustomer($customerID, $customer);
|
||||
|
||||
return $this->json(['success' => true, 'customerID' => $customerID]);
|
||||
}
|
||||
|
||||
public function archiveCustomer(int $customerID, string $status): ResponseInterface
|
||||
{
|
||||
\Customer::whereId($customerID)->update(['archive' => $status]);
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function removeCustomer(int $customerID): ResponseInterface
|
||||
{
|
||||
$removeCustomer = new \RemoveCustomer($customerID);
|
||||
|
||||
if ($removeCustomer->getAllowDelete() === false) {
|
||||
return $this->json(['result' => false]);
|
||||
}
|
||||
|
||||
\Customer::removeCustomer($customerID);
|
||||
|
||||
return $this->json(['result' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class EmployeeTargetController extends BaseController
|
||||
{
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
die('NO ACCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Default action
|
||||
}
|
||||
|
||||
public function getEmployeeTargets(int $employeeID): ResponseInterface
|
||||
{
|
||||
$employeeTargets = \Employeetarget::whereUserId($employeeID)
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
return $this->json($employeeTargets);
|
||||
}
|
||||
|
||||
public function saveEmployeeTarget(): ResponseInterface
|
||||
{
|
||||
$employeeTargetValidation = new \EmployeeTargetValidation();
|
||||
|
||||
if (!$employeeTargetValidation->getValidationResult()) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'messages' => $employeeTargetValidation->getErrorMessages()
|
||||
]);
|
||||
}
|
||||
|
||||
$target = $this->request->getPost();
|
||||
|
||||
$targetID = $target['id'];
|
||||
unset($target['id']);
|
||||
|
||||
$target['endmonth'] = $target['endmonth'] ? $target['endmonth'] : null;
|
||||
$target['endyear'] = $target['endyear'] ? $target['endyear'] : null;
|
||||
|
||||
$targetID = \Employeetarget::saveTarget($targetID, $target);
|
||||
|
||||
return $this->json(['success' => true, 'targetID' => $targetID]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class ExternalsController extends BaseController
|
||||
{
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
die('NO ACCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Default action
|
||||
}
|
||||
|
||||
public function getAllExternals(string $archive = 'F'): ResponseInterface
|
||||
{
|
||||
$externals = \External::getAllExternals($archive);
|
||||
|
||||
return $this->json($externals);
|
||||
}
|
||||
|
||||
public function saveExternal(): ResponseInterface
|
||||
{
|
||||
$externalValidation = new \ExternalValidation();
|
||||
|
||||
if (!$externalValidation->getValidationResult()) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'messages' => $externalValidation->getErrorMessages()
|
||||
]);
|
||||
}
|
||||
|
||||
$external = $this->request->getPost();
|
||||
|
||||
$externalID = $external['id'];
|
||||
unset($external['id']);
|
||||
|
||||
$externalID = \External::saveExternal($externalID, $external);
|
||||
|
||||
return $this->json(['success' => true, 'externalID' => $externalID]);
|
||||
}
|
||||
|
||||
public function archiveExternal(int $externalID, string $status): ResponseInterface
|
||||
{
|
||||
\External::whereId($externalID)->update(['archive' => $status]);
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function removeExternal(int $externalID): ResponseInterface
|
||||
{
|
||||
$removeExternal = new \RemoveExternal($externalID);
|
||||
|
||||
if ($removeExternal->getAllowDelete() === false) {
|
||||
return $this->json(['result' => false]);
|
||||
}
|
||||
|
||||
\External::removeExternal($externalID);
|
||||
|
||||
return $this->json(['result' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class RolesController extends BaseController
|
||||
{
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
die('NO ACCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Default action
|
||||
}
|
||||
|
||||
public function getAllRoles(string $archive = 'F'): ResponseInterface
|
||||
{
|
||||
$roles = \Role::getAllRoles($archive);
|
||||
|
||||
return $this->json($roles);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use App\Libraries\TwoFactorAuth;
|
||||
|
||||
/**
|
||||
* Two-Factor Authentication Settings Controller
|
||||
* Allows users to manage their 2FA settings
|
||||
*/
|
||||
class TwoFactorController extends BaseController
|
||||
{
|
||||
protected TwoFactorAuth $twoFactorAuth;
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
// Ensure user is authenticated
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
header('Location: ' . site_url('login'));
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->twoFactorAuth = new TwoFactorAuth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show 2FA settings page
|
||||
*/
|
||||
public function index(): string
|
||||
{
|
||||
$data = [
|
||||
'user' => $this->user,
|
||||
'version' => $this->version
|
||||
];
|
||||
|
||||
return view('pages/beheer/twofactor/settings_view', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable 2FA for the user
|
||||
* POST parameters:
|
||||
* - method: 'email' or 'authenticator'
|
||||
*/
|
||||
public function enable(): ResponseInterface
|
||||
{
|
||||
$method = $this->cleanInput('method');
|
||||
|
||||
if (!in_array($method, ['email', 'authenticator'])) {
|
||||
return $this->json(['success' => false, 'message' => 'Ongeldige methode']);
|
||||
}
|
||||
|
||||
$secret = null;
|
||||
$qrCodeUrl = null;
|
||||
|
||||
// If authenticator method, generate secret
|
||||
if ($method === 'authenticator') {
|
||||
$secret = $this->twoFactorAuth->generateSecret();
|
||||
$qrCodeUrl = $this->twoFactorAuth->getQRCodeUrl(
|
||||
$secret,
|
||||
$this->user->username,
|
||||
'DBOIS'
|
||||
);
|
||||
}
|
||||
|
||||
// Update user record
|
||||
\User::whereId($this->user->id)->update([
|
||||
'two_factor_enabled' => 'T',
|
||||
'two_factor_method' => $method,
|
||||
'two_factor_secret' => $secret
|
||||
]);
|
||||
|
||||
$response = [
|
||||
'success' => true,
|
||||
'message' => 'Tweefactorauthenticatie ingeschakeld',
|
||||
'method' => $method
|
||||
];
|
||||
|
||||
if ($method === 'authenticator') {
|
||||
$response['secret'] = $secret;
|
||||
$response['qrCodeUrl'] = $qrCodeUrl;
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify authenticator setup
|
||||
* POST parameters:
|
||||
* - code: The 6-digit code from Google Authenticator
|
||||
*/
|
||||
public function verifySetup(): ResponseInterface
|
||||
{
|
||||
$code = $this->cleanInput('code');
|
||||
|
||||
if (!$this->user->two_factor_secret) {
|
||||
return $this->json(['success' => false, 'message' => 'Geen geheim gevonden']);
|
||||
}
|
||||
|
||||
$isValid = $this->twoFactorAuth->verifyCode($this->user->two_factor_secret, $code);
|
||||
|
||||
if ($isValid) {
|
||||
return $this->json(['success' => true, 'message' => 'Code geverifieerd']);
|
||||
} else {
|
||||
return $this->json(['success' => false, 'message' => 'Ongeldige code']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable 2FA for the user
|
||||
*/
|
||||
public function disable(): ResponseInterface
|
||||
{
|
||||
\User::whereId($this->user->id)->update([
|
||||
'two_factor_enabled' => 'F',
|
||||
'two_factor_method' => null,
|
||||
'two_factor_secret' => null
|
||||
]);
|
||||
|
||||
// Clean up any existing OTP codes
|
||||
\UserOtp::where('user_id', $this->user->id)->delete();
|
||||
|
||||
return $this->json([
|
||||
'success' => true,
|
||||
'message' => 'Tweefactorauthenticatie uitgeschakeld'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change 2FA method
|
||||
* POST parameters:
|
||||
* - method: 'email' or 'authenticator'
|
||||
*/
|
||||
public function changeMethod(): ResponseInterface
|
||||
{
|
||||
$method = $this->cleanInput('method');
|
||||
|
||||
if (!in_array($method, ['email', 'authenticator'])) {
|
||||
return $this->json(['success' => false, 'message' => 'Ongeldige methode']);
|
||||
}
|
||||
|
||||
// If user is not enabled for 2FA, they should use enable endpoint
|
||||
if ($this->user->two_factor_enabled !== 'T') {
|
||||
return $this->json(['success' => false, 'message' => '2FA is niet ingeschakeld']);
|
||||
}
|
||||
|
||||
$secret = null;
|
||||
$qrCodeUrl = null;
|
||||
|
||||
// If switching to authenticator, generate new secret
|
||||
if ($method === 'authenticator') {
|
||||
$secret = $this->twoFactorAuth->generateSecret();
|
||||
$qrCodeUrl = $this->twoFactorAuth->getQRCodeUrl(
|
||||
$secret,
|
||||
$this->user->username,
|
||||
'DBOIS'
|
||||
);
|
||||
}
|
||||
|
||||
\User::whereId($this->user->id)->update([
|
||||
'two_factor_method' => $method,
|
||||
'two_factor_secret' => $secret
|
||||
]);
|
||||
|
||||
$response = [
|
||||
'success' => true,
|
||||
'message' => '2FA methode gewijzigd',
|
||||
'method' => $method
|
||||
];
|
||||
|
||||
if ($method === 'authenticator') {
|
||||
$response['secret'] = $secret;
|
||||
$response['qrCodeUrl'] = $qrCodeUrl;
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current 2FA status
|
||||
*/
|
||||
public function status(): ResponseInterface
|
||||
{
|
||||
$response = [
|
||||
'enabled' => $this->user->two_factor_enabled === 'T',
|
||||
'method' => $this->user->two_factor_method
|
||||
];
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class UsersController extends BaseController
|
||||
{
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
die('NO ACCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Default action
|
||||
}
|
||||
|
||||
public function getAllUsers(string $archive = 'F'): ResponseInterface
|
||||
{
|
||||
$users = \User::getAllUsers($archive);
|
||||
return $this->json($users);
|
||||
}
|
||||
|
||||
public function getUser(int $userID): ResponseInterface
|
||||
{
|
||||
$user = \User::find($userID);
|
||||
return $this->json($user);
|
||||
}
|
||||
|
||||
public function getCurrentUser(): ResponseInterface
|
||||
{
|
||||
return $this->json($this->user);
|
||||
}
|
||||
|
||||
public function getUserWithprojects(): ResponseInterface
|
||||
{
|
||||
$usersWithProjects = \User::getUserWithprojects();
|
||||
return $this->json($usersWithProjects);
|
||||
}
|
||||
|
||||
public function getUserActiveProjects(int $userID): ResponseInterface
|
||||
{
|
||||
$userActiveProjects = \User::getUserActiveProjects($userID);
|
||||
return $this->json($userActiveProjects);
|
||||
}
|
||||
|
||||
public function getUniqueprojectEmployees(): ResponseInterface
|
||||
{
|
||||
$projectEmployees = \User::getUniqueProjectUsers();
|
||||
return $this->json($projectEmployees);
|
||||
}
|
||||
|
||||
public function getUniqueEmployeesWithActivity(string $archive): ResponseInterface
|
||||
{
|
||||
$projectEmployees = \Projectemployee::getUniqueEmployeesWithActivity($archive);
|
||||
return $this->json($projectEmployees);
|
||||
}
|
||||
|
||||
public function saveUser(): ResponseInterface
|
||||
{
|
||||
$userValidation = new \UserValidation();
|
||||
|
||||
if (!$userValidation->getValidationResult()) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'messages' => $userValidation->getErrorMessages()
|
||||
]);
|
||||
}
|
||||
|
||||
$user = $this->request->getPost();
|
||||
|
||||
$userID = $user['id'];
|
||||
unset($user['id']);
|
||||
|
||||
if ($userID == 0) {
|
||||
$user = $this->newUser($user);
|
||||
}
|
||||
|
||||
$user['role'] = empty($user['role']) ? null : $user['role'];
|
||||
|
||||
$userID = \User::saveUser($userID, $user);
|
||||
|
||||
return $this->json(['success' => true, 'userID' => $userID]);
|
||||
}
|
||||
|
||||
public function savePassword(): ResponseInterface
|
||||
{
|
||||
$password = $this->cleanInput('password');
|
||||
|
||||
$user = \User::find(USERID);
|
||||
|
||||
$saltedPassword = \User::getSaltedPassword($password, $user->salt);
|
||||
|
||||
\User::whereId(USERID)->update(['password' => $saltedPassword]);
|
||||
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function archiveUser(int $userID, string $status): ResponseInterface
|
||||
{
|
||||
\User::whereId($userID)->update(['archive' => $status]);
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function removeUser(int $userID): ResponseInterface
|
||||
{
|
||||
$removeUser = new \RemoveUser($userID);
|
||||
|
||||
if ($removeUser->getAllowDelete() === false) {
|
||||
return $this->json(['result' => false]);
|
||||
}
|
||||
|
||||
\User::removeUser($userID);
|
||||
|
||||
return $this->json(['result' => true]);
|
||||
}
|
||||
|
||||
private function newUser(array $user): array
|
||||
{
|
||||
$userCreation = new \UserCreation($user);
|
||||
|
||||
$user = $userCreation->getUser();
|
||||
$password = $userCreation->getPassword();
|
||||
|
||||
$this->sendWelcomeEmail($user, $password);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function sendWelcomeEmail(array $user, string $password): bool
|
||||
{
|
||||
$email = \Config\Services::email();
|
||||
|
||||
$html = view('emails/welcome_email', [
|
||||
'password' => $password,
|
||||
'user' => $user
|
||||
]);
|
||||
|
||||
$email->setFrom('noreply@debeleidsonderzoekers.nl', 'DBOIS');
|
||||
$email->setTo($user['email']);
|
||||
$email->setSubject('Wachtwoord DBOIS');
|
||||
$email->setMessage($html);
|
||||
|
||||
return $email->send();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class VatController extends BaseController
|
||||
{
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
die('NO ACCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Default action
|
||||
}
|
||||
|
||||
public function getVats(string $archive): ResponseInterface
|
||||
{
|
||||
$vats = \Vat::getVats($archive);
|
||||
|
||||
return $this->json($vats);
|
||||
}
|
||||
|
||||
public function addVat(): ResponseInterface
|
||||
{
|
||||
\Vat::create([]);
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function saveVat(int $vatID): ResponseInterface
|
||||
{
|
||||
$vatrate = $this->request->getPost('vatrate');
|
||||
\Vat::whereId($vatID)->update(['vatrate' => $vatrate]);
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function removeVat(int $vatID): ResponseInterface
|
||||
{
|
||||
$removeVat = new \RemoveVat($vatID);
|
||||
|
||||
$allowRemove = $removeVat->getRemoveAllowed();
|
||||
|
||||
if ($allowRemove === false) {
|
||||
return $this->json(['result' => false]);
|
||||
}
|
||||
|
||||
\Vat::whereId($vatID)->delete();
|
||||
|
||||
return $this->json(['result' => true]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user