diff --git a/application/config/email.php b/application/config/email.php new file mode 100644 index 0000000..97816b8 --- /dev/null +++ b/application/config/email.php @@ -0,0 +1,19 @@ +load->model( $models ); + $this->load->library( $libraries ); + } + + public function index() + { + + } + + public function getAllCustomers( $archive = 'F' ) + { + $users = Customer::getAllCustomers( $archive ); + + $this->json( $users ); + } + + public function saveCustomer() + { + $userValidation = new CustomerValidation(); + + if ( ! $userValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $userValidation->getErrorMessages()] ); + + $user = $this->input->post(); + + $userID = $user['id']; + unset( $user['id'] ); + + $userID = Customer::saveCustomer( $userID, $user ); + + $this->json( ['success' => TRUE, 'userID' => $userID] ); + } + + public function archiveCustomer( $userID, $status ) + { + Customer::whereId( $userID )->update( ['archive' => $status] ); + } + + public function removeCustomer( $userID ) + { + $removeCustomer = new RemoveCustomer( $userID ); + + if ( $removeCustomer->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + + Customer::removeCustomer( $userID ); + + $this->json( ['result' => TRUE] ); + } +} \ No newline at end of file diff --git a/application/controllers/beheer/usersController.php b/application/controllers/beheer/usersController.php index b5866f9..26da539 100644 --- a/application/controllers/beheer/usersController.php +++ b/application/controllers/beheer/usersController.php @@ -37,20 +37,63 @@ class usersController extends MY_Controller { if ( ! $userValidation->getValidationResult() ) return $this->json( [ - 'success'=> false, 'messages' =>$userValidation->getErrorMessages()] ); + 'success' => FALSE, 'messages' => $userValidation->getErrorMessages()] ); $user = $this->input->post(); $userID = $user['id']; - unset($user['id']); + unset( $user['id'] ); - if( $userID == 0 ) - { - createNewUser(); - } + if ( $userID == 0 ) $user = $this->newUser( $user ); - $userID = User::saveUser( $userID, $user); + $user['role'] = empty( $user['role'] ) ? NULL : $user['role']; - $this->json( ['success' => TRUE] ); + $userID = User::saveUser( $userID, $user ); + + $this->json( ['success' => TRUE, 'userID' => $userID] ); + } + + public function archiveUser( $userID, $status ) + { + User::whereId( $userID )->update( ['archive' => $status] ); + } + + public function removeUser( $userID ) + { + $removeUser = new RemoveUser( $userID ); + + if ( $removeUser->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + + User::removeUser( $userID ); + + $this->json( ['result' => TRUE] ); + } + + private function newUser( $user ) + { + $userCreation = new UserCreation( $user ); + + $user = $userCreation->getUser(); + + $password = $userCreation->getPassword(); + + $this->sendWelcomeEmail( $user, $password ); + + return $user; + } + + private function sendWelcomeEmail( $user, $password ) + { + $this->load->library( 'email' ); + + $html = $this->load->view( 'emails/welcome_email', [ + 'password' => $password, 'user' => $user], TRUE ); + + $this->email->from( 'noreply@debeleidsonderzoekers.nl', 'DBOIS' ); + $this->email->to( $user['email'] ); + $this->email->subject( 'Wachtwoord DBOIS' ); + $this->email->message( $html ); + + $this->email->send(); } } \ No newline at end of file diff --git a/application/libraries/beheer/user/PasswordRecipe.php b/application/libraries/beheer/user/PasswordRecipe.php index dfbc2d6..db3cf5b 100644 --- a/application/libraries/beheer/user/PasswordRecipe.php +++ b/application/libraries/beheer/user/PasswordRecipe.php @@ -8,8 +8,8 @@ class PasswordRecipe { - private $nakedPassword = false; - private $salt = false; + private $password = FALSE; + private $salt = FALSE; private $saltedPassword; public function __construct() @@ -17,9 +17,24 @@ class PasswordRecipe { $this->handle(); } - public function setNakedPassword( $nakedPassword ) + public function getPassword() { - $this->nakedPassword = $nakedPassword; + 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 ) @@ -29,52 +44,55 @@ class PasswordRecipe { private function handle() { - $this->checkNakedPassword(); + $this->checkPassword(); $this->checkSalt(); $this->setSaltedPassword(); } - private function checkNakedPassword() + private function checkPassword() { - if( ! $this->nakedPassword ) $this->createNakedPassword(); + if ( ! $this->password ) $this->createPassword(); - if( strlen($this->nakedPassword) < 6 ) return; + if ( strlen( $this->password ) < 6 ) return; } private function checkSalt() { - if( ! $this->salt ) $this->createSalt(); + if ( ! $this->salt ) $this->createSalt(); } - private function createNakedPassword() + private function createPassword() { - $pass = $this->getRandomString(8); + $pass = $this->getRandomString( 8 ); - $this->nakedPassword = $pass; + $this->password = $pass; } private function createSalt() { - $salt = $this->getRandomString(8); + $salt = $this->getRandomString( 18 ); - $this->salt = $salt; + $this->salt = sha1($salt); } private function setSaltedPassword() { - $this->saltedPassword = sha1($this->) + $this->saltedPassword = sha1( sha1( $this->password ) . $this->salt ); } - private function getRandomString( $length=8 ) + 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]; + $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; } -} \ No newline at end of file +} diff --git a/application/libraries/beheer/user/RemoveUser.php b/application/libraries/beheer/user/RemoveUser.php new file mode 100644 index 0000000..eb04c3b --- /dev/null +++ b/application/libraries/beheer/user/RemoveUser.php @@ -0,0 +1,36 @@ +setUserID($userID); + + $this->handle(); + } + + public function getAllowDelete() + { + return $this->allowDelete; + } + + private function setUserID( $userID ) + { + $this->userID = $userID; + } + + private function handle() + { + //$this->checkIfUserHasProjects(); + } + +} \ No newline at end of file diff --git a/application/libraries/beheer/user/UserCreation.php b/application/libraries/beheer/user/UserCreation.php new file mode 100644 index 0000000..c700fb9 --- /dev/null +++ b/application/libraries/beheer/user/UserCreation.php @@ -0,0 +1,72 @@ +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; + } +} \ No newline at end of file diff --git a/application/libraries/validation/inputValidations/CustomerValidation.php b/application/libraries/validation/inputValidations/CustomerValidation.php new file mode 100644 index 0000000..190248a --- /dev/null +++ b/application/libraries/validation/inputValidations/CustomerValidation.php @@ -0,0 +1,36 @@ + [ + 'validations' => 'required|alphaNumericSpaces', + 'fieldname' => 'name' + ], + 'contactperson' => [ + 'validations' => 'required|alphaNumericSpaces', + 'fieldname' => 'contactperson' + ], + 'email' => [ + 'validations' => 'email', + 'fieldname' => 'email' + ] + ]; + + public function __construct() + { + parent::__construct(); + + $this->ci =& get_instance(); + } +} \ No newline at end of file diff --git a/application/models/beheer/Customer_model.php b/application/models/beheer/Customer_model.php new file mode 100644 index 0000000..4ca6450 --- /dev/null +++ b/application/models/beheer/Customer_model.php @@ -0,0 +1,18 @@ +sql = " SELECT * FROM users - WHERE ucase( {$field} ) = '{strtoupper($fieldValue)}' + WHERE ucase( {$field} ) = '".strtoupper($fieldValue)."' AND id != {$recordID} "; $result = $this->get_query_row(); diff --git a/application/models/eloquent/BaseModel.php b/application/models/eloquent/BaseModel.php index 20612ea..b6e8383 100644 --- a/application/models/eloquent/BaseModel.php +++ b/application/models/eloquent/BaseModel.php @@ -27,7 +27,7 @@ class BaseModel extends Eloquent { protected $guarded = []; - protected $hidden = ['creation_date', 'last_update_date', 'created_by', 'updated_by']; + protected $hidden = ['creation_date', 'last_update_date', 'created_by', 'updated_by', 'password', 'salt']; protected static $oldValue; diff --git a/application/models/eloquent/Customer.php b/application/models/eloquent/Customer.php new file mode 100644 index 0000000..71c34e8 --- /dev/null +++ b/application/models/eloquent/Customer.php @@ -0,0 +1,47 @@ +whereArchive( 'F' ); + + $customers = $customers->get(); + + return $customers; + } + + public static function saveCustomer( $customerID, $customer ) + { + $customer = (array)$customer; + + if( $customerID == 0) + { + $customer = Customer::create($customer); + } + else + { + $customer = Customer::whereId($customerID)->update($customer); + } + + return $customer['id']; + } + + public static function removeCustomer($customerID) + { + Customer::whereId($customerID)->delete(); + } + + +} \ No newline at end of file diff --git a/application/models/eloquent/User.php b/application/models/eloquent/User.php index ad399dc..c62ef07 100644 --- a/application/models/eloquent/User.php +++ b/application/models/eloquent/User.php @@ -47,18 +47,23 @@ class User extends BaseModel { public static function saveUser( $userID, $user ) { + $user = (array)$user; + if( $userID == 0) { $user = User::create($user); } else { - $user = User::whereId($userID); - - $user->update($user); + $user = User::whereId($userID)->update($user); } - return $user->id; + return $user['id']; + } + + public static function removeUser($userID) + { + User::whereId($userID)->delete(); } diff --git a/application/views/emails/welcome_email.php b/application/views/emails/welcome_email.php new file mode 100644 index 0000000..f9ccf4f --- /dev/null +++ b/application/views/emails/welcome_email.php @@ -0,0 +1,375 @@ + + + + + + wachtwoord DBOIS + + + + + + + + + + + + +
+
+ + + + + + + +
+ Wachtwoord De Beleidsonderzoeker IS +
+ + + + + + + + + + + + + +
+ Hieronder vindt u uw gebruikersnaam wachtwoord om in te loggen op het + informatiesysteem van De Beleidsonderzoekers +
+

+ Beste +

+

+ Er is voor u een account aangemaakt is het informatiesysteem van de Beleidsonderzoekers, hieronder vindt u uw gebruikersnaam en wachtwoord waarmee u kun t inloggen in het systeem. +

+
+
+
+ + + + + +
+ + + + + + + + + +
gebruikersnaam
wacthwoord
+
+
+ + Ga naar de website + +
+
+
+ + diff --git a/application/views/pages/customers_view.php b/application/views/pages/customers_view.php new file mode 100644 index 0000000..85e6b5a --- /dev/null +++ b/application/views/pages/customers_view.php @@ -0,0 +1,7 @@ + -load->view('specials/notify_modal'); ?> -load->view('specials/notifyme_modal'); ?> +load->view('specials/tellme_modal'); ?>
diff --git a/application/views/pages/users_view.php b/application/views/pages/users_view.php index 5122fde..efc3388 100644 --- a/application/views/pages/users_view.php +++ b/application/views/pages/users_view.php @@ -4,17 +4,17 @@ - - - - - - - + + + + + + + - - + + @@ -22,19 +22,45 @@ - + diff --git a/application/views/partials/_css.php b/application/views/partials/_css.php index efe51c1..dfd0357 100644 --- a/application/views/partials/_css.php +++ b/application/views/partials/_css.php @@ -8,11 +8,10 @@ - - - - - + + + + diff --git a/application/views/partials/_js.php b/application/views/partials/_js.php index 78ee7a4..7d199aa 100644 --- a/application/views/partials/_js.php +++ b/application/views/partials/_js.php @@ -11,7 +11,6 @@ - @@ -52,8 +51,10 @@ + + diff --git a/application/views/partials/_modals.php b/application/views/partials/_modals.php index 039d929..912c72c 100644 --- a/application/views/partials/_modals.php +++ b/application/views/partials/_modals.php @@ -2,5 +2,6 @@ $this->load->view('modals/user_modal'); +$this->load->view('specials/tellme_modal'); ?> diff --git a/application/views/specials/notify_modal.php b/application/views/specials/notify_modal.php deleted file mode 100644 index 327549b..0000000 --- a/application/views/specials/notify_modal.php +++ /dev/null @@ -1,37 +0,0 @@ - \ No newline at end of file diff --git a/application/views/specials/notifyme_modal.php b/application/views/specials/tellme_modal.php similarity index 75% rename from application/views/specials/notifyme_modal.php rename to application/views/specials/tellme_modal.php index bf642dc..73d0891 100644 --- a/application/views/specials/notifyme_modal.php +++ b/application/views/specials/tellme_modal.php @@ -1,4 +1,4 @@ -
voornaamachternaamtussenvoegselgebruikersnaamemailrol voornaamachternaamtussenvoegselgebruikersnaamemailrol 
- - - + + + + + + + +
+ +
+ +
+
+ + +
+
+
+