Conversie codeigniter 4

This commit is contained in:
2026-01-09 11:41:28 +01:00
parent dbd8c8aed2
commit f0b9c6ad40
242 changed files with 20034 additions and 346 deletions
@@ -0,0 +1,36 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveCustomer {
private $customerID;
private $allowDelete = TRUE;
public function __construct( $userID )
{
$this->setCustomerID( $userID );
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setCustomerID( $customerID )
{
$this->customerID = $customerID;
}
private function handle()
{
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveExternal {
private $externalID;
private $allowDelete = TRUE;
public function __construct( $userID )
{
$this->setExternalID( $userID );
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setExternalID( $externalID )
{
$this->externalID = $externalID;
}
private function handle()
{
}
}
@@ -0,0 +1,42 @@
<?php
namespace App\Libraries\Beheer\Session;
use CodeIgniter\Session\Session;
class CreateUserSession
{
private Session $session;
private object $user;
private array $sessionArray = [];
public function __construct(Session $session)
{
$this->session = $session;
}
public function handle(object $user): void
{
$this->setUser($user);
$this->setSessionArray();
$this->createSession();
}
private function setUser(object $user): void
{
$this->user = $user;
}
private function setSessionArray(): void
{
$this->sessionArray = [
'userID' => $this->user->id,
'role' => $this->user->role
];
}
private function createSession(): void
{
$this->session->set($this->sessionArray);
}
}
@@ -0,0 +1,45 @@
<?php
namespace App\Libraries\Beheer\Session;
use CodeIgniter\Session\Session;
class RetrieveUserSession
{
private Session $session;
public function __construct(Session $session)
{
$this->session = $session;
}
public function handle(): void
{
$this->setUserID();
$this->setRole();
$this->setAuthenticated();
}
private function setUserID(): void
{
$userId = $this->session->get('userID');
if (!defined('USERID')) {
define('USERID', $userId);
}
}
private function setRole(): void
{
$role = $this->session->get('role');
if (!defined('ROLE')) {
define('ROLE', $role);
}
}
private function setAuthenticated(): void
{
if (!defined('AUTHENTICATED')) {
define('AUTHENTICATED', USERID ? true : false);
}
}
}
@@ -0,0 +1,101 @@
<?php
/**
* Send OTP Email Library
* Generates and sends a one-time password via email for two-factor authentication
*/
class SendOtpEmail
{
private $user;
private $otpCode;
private $sendResult = false;
public function __construct($user)
{
$this->user = $user;
$this->handle();
}
/**
* Get the result of the email send operation
* @return bool True if email was sent successfully
*/
public function getSendResult()
{
return $this->sendResult;
}
/**
* Get the generated OTP code (for testing purposes)
* @return string The OTP code
*/
public function getOtpCode()
{
return $this->otpCode;
}
/**
* Main handler for OTP email process
*/
private function handle()
{
$this->generateOTP();
$this->sendOTPEmail();
}
/**
* Generate a new OTP code
*/
private function generateOTP()
{
// Generate OTP valid for 10 minutes
$this->otpCode = \UserOtp_model::generateOTP($this->user->id, 10);
}
/**
* Send the OTP code via email
*/
private function sendOTPEmail()
{
$email = \Config\Services::email();
// Build email configuration directly from environment variables
$config = [
'protocol' => str_replace(',', '', $_ENV['PROTOCOL'] ?? 'smtp'),
'SMTPHost' => str_replace(',', '', $_ENV['SMTP_HOST'] ?? ''),
'SMTPUser' => str_replace(',', '', $_ENV['SMTP_USER'] ?? ''),
'SMTPPass' => str_replace(',', '', $_ENV['SMTP_PASS'] ?? ''),
'SMTPPort' => (int) str_replace(',', '', $_ENV['SMTP_PORT'] ?? 25),
'SMTPCrypto' => 'tls',
'SMTPTimeout' => 30,
'charset' => 'UTF-8',
'mailType' => 'html',
'newline' => "\r\n",
'CRLF' => "\r\n",
'wordWrap' => true,
];
$email->initialize($config);
$data = [
'username' => $this->user->username,
'firstname' => $this->user->firstname,
'middlename' => $this->user->middlename,
'lastname' => $this->user->lastname,
'otp_code' => $this->otpCode
];
$html = view('emails/twofactor_otp_email', ['user' => $data]);
$email->setFrom('noreply@dbois.nl', 'DBOIS');
$email->setTo($this->user->email);
$email->setSubject('DBOIS Tweefactorauthenticatie - Verificatiecode');
$email->setMessage($html);
$this->sendResult = $email->send();
if (!$this->sendResult) {
log_message('error', 'Failed to send 2FA OTP email to ' . $this->user->email . ': ' . $email->printDebugger());
}
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 26/12/2017
* Time: 12:39
*/
class CreateUser {
public function __construct()
{
}
}
@@ -0,0 +1,99 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 26/12/2017
* Time: 12:40
*/
class PasswordRecipe {
private $password = FALSE;
private $salt = FALSE;
private $saltedPassword;
public function __construct()
{
$this->handle();
}
public function getPassword()
{
return $this->password;
}
public function getSalt()
{
return $this->salt;
}
public function getSaltedPassword()
{
return $this->saltedPassword;
}
public function setPassword( $password )
{
$this->password = $password;
}
public function setSalt( $salt )
{
$this->salt = $salt;
}
private function handle()
{
$this->checkPassword();
$this->checkSalt();
$this->setSaltedPassword();
}
private function checkPassword()
{
if ( ! $this->password ) $this->createPassword();
if ( strlen( $this->password ) < 6 ) return;
}
private function checkSalt()
{
if ( ! $this->salt ) $this->createSalt();
}
private function createPassword()
{
$pass = $this->getRandomString( 8 );
$this->password = $pass;
}
private function createSalt()
{
$salt = $this->getRandomString( 18 );
$this->salt = sha1($salt);
}
private function setSaltedPassword()
{
$this->saltedPassword = User::getSaltedPassword( $this->password, $this->salt);
}
private function getRandomString( $length = 8 )
{
$rand = '';
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$alphaLength = strlen( $alphabet ) - 1; //put the length -1 in cache
for ( $i = 0; $i < $length; $i ++ )
{
$n = rand( 0, $alphaLength );
$rand .= $alphabet[ $n ];
}
return $rand;
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveUser {
private $userID;
private $allowDelete=FALSE;
public function __construct( $userID )
{
$this->setUserID($userID);
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setUserID( $userID )
{
$this->userID = $userID;
}
private function handle()
{
//$this->checkIfUserHasProjects();
}
}
@@ -0,0 +1,104 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 28/07/2018
* Time: 14:31
*/
class RequestPassword {
private $ci;
private $salt;
private $user;
private $password;
private $sendResult;
private $passwordRecipe;
private $saltedPassword;
public function __construct( $user )
{
$this->ci =& get_instance();
$this->user = $user;
$this->ci->load->library( 'email' );
$this->handle();
}
public function getSendResult()
{
return $this->sendResult;
}
private function handle()
{
$this->createPassword();
$this->setPassword();
$this->setSalt();
$this->setSaltedPassword();
$this->persistNewpassword();
$this->sendNewPassword();
}
private function createPassword()
{
$this->passwordRecipe = new PasswordRecipe();
}
private function setPassword()
{
$this->password = $this->passwordRecipe->getPassword();
}
private function setSalt()
{
$this->salt = $this->passwordRecipe->getsalt();
}
private function setSaltedPassword()
{
$this->saltedPassword = $this->passwordRecipe->getSaltedPassword();
}
private function persistNewPassword()
{
$data = [
'password' => $this->saltedPassword,
'salt' => $this->salt
];
User::whereId( $this->user->id )->update( $data );
}
private function sendNewPassword()
{
$data = [
'username' => $this->user->username,
'firstname' => $this->user->firstname,
'middlename' => $this->user->middlename,
'lastname' => $this->user->lastname,
'password' => $this->password
];
$html = $this->ci->load->view( 'emails/requestpassword_email', ['user'=>$data], true );
$this->ci->email->from( 'noreply@dbois.nl', 'DBOIS' );
$this->ci->email->to( $this->user->email );
$this->ci->email->subject( 'Nieuw wachtwoord DBOIS' );
$this->ci->email->message( $html );
$this->ci->email->set_mailtype("html");
$this->ci->email->set_newline("\r\n");
$this->sendResult = $this->ci->email->send();
if( ! $this->sendResult ) log_message( 'error', json_encode($this->ci->email->print_debugger()));
}
}
@@ -0,0 +1,72 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 14:10
*/
class UserCreation {
private $user;
private $passWordRecipe;
private $password;
private $saltedPassword;
private $salt;
public function __construct( $user )
{
$this->setUser( $user );
$this->handle();
}
public function getUser()
{
return $this->user;
}
public function getPassword()
{
return $this->password;
}
private function setUser( $user )
{
$this->user = $user;
}
private function handle()
{
$this->passWordRecipe = new PasswordRecipe();
$this->setPassword();
$this->setSalt();
$this->setSaltedPassword();
$this->enrichUser();
}
private function setPassword()
{
$this->password = $this->passWordRecipe->getPassword();
}
private function setSalt()
{
$this->salt = $this->passWordRecipe->getSalt();
}
private function setSaltedPassword()
{
$this->saltedPassword = $this->passWordRecipe->getSaltedPassword();
}
private function enrichUser()
{
$this->user['password'] = $this->saltedPassword;
$this->user['salt'] = $this->salt;
}
}