Conversie codeigniter 4
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user