diversen opmerkingen
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user