From a7ca14bdc1e094f6006b7ec6ab2cf6b656a359ce Mon Sep 17 00:00:00 2001 From: Liesbeth ter Schure Date: Tue, 22 Mar 2022 10:05:04 +0100 Subject: [PATCH] send bijlage ook bij new ww --- application/config/email.php | 4 +++- .../controllers/shared/Organisaties.php | 5 ++-- application/controllers/shared/Users.php | 23 ++++++++++++++----- public/js/monpas/models/gebruikersmodel.js | 13 ++++++++--- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/application/config/email.php b/application/config/email.php index 22d3efe..6207905 100644 --- a/application/config/email.php +++ b/application/config/email.php @@ -24,4 +24,6 @@ $config['smtp_host'] = $_ENV['MAIL']['HOST']; $config['smtp_user'] = $_ENV['MAIL']['SMTP_USER']; $config['smtp_pass'] = $_ENV['MAIL']['SMTP_PASS']; $config['smtp_port'] = $_ENV['MAIL']['SMTP_PORT']; - +$config['mailtype']='html'; +$config['crlf']="\r\n"; +$config['newline']="\r\n"; diff --git a/application/controllers/shared/Organisaties.php b/application/controllers/shared/Organisaties.php index c375077..6e11c63 100644 --- a/application/controllers/shared/Organisaties.php +++ b/application/controllers/shared/Organisaties.php @@ -463,13 +463,12 @@ class Organisaties extends MY_Controller{ $orgID = $_POST['orgID']; $filename = $_FILES['file']['name']; - + $this->deleteOldBijlage($orgID); if ( ! $this->upload->do_upload('file')) $error = $this->upload->display_errors(); else { $error = FALSE; - $randomname = $this->upload->data('file_name')['file_name']; - $this->deleteOldBijlage($orgID); + $randomname = $this->upload->data('file_name'); $this->setNieuweBijlage($orgID, $randomname, $filename); } $this->json($error); diff --git a/application/controllers/shared/Users.php b/application/controllers/shared/Users.php index 67c9254..e8365b4 100644 --- a/application/controllers/shared/Users.php +++ b/application/controllers/shared/Users.php @@ -309,19 +309,22 @@ class Users extends MY_Controller{ } function SendNewWW(){ //TODO sanitize input - $userid = $this->uri->segment(4); - $ok = true; + $userid = $this->clean_input('userid'); + $orgid = $this->clean_input('orgid'); + $ok = true; $errortekst = ''; $user = $this->Users_model->get_record_by_id($userid); - $ww = random_string('alnum', 8); + $ww = random_string('alnum', 8); $saltedww = md5($user->zout.$ww); // update user $this->Users_model->update_record(array('wachtwoord'=>$saltedww),$userid); $data = array('username'=>$user->gnaam, 'password'=>$ww, 'fullname'=>$this->Users_model->get_fullname($userid)); - $html = $this->load->view( 'emails/newpassword_mail', $data, TRUE ); - if( $_ENV['ENVIRONMENT'] == 'production') + $html = $this->load->view( 'emails/newpassword_mail', $data, TRUE ); + $org = $this->getBijlage($orgid); + + if( $_ENV['ENVIRONMENT'] == 'production') { //Deze code wordt alleen op produktie gebruikt en stuurt de mail //naar Mailgun via een API (Codeigniter email library wordt niet gebruikt @@ -338,6 +341,11 @@ class Users extends MY_Controller{ 'filePath' => FCPATH . 'css/images/monpasklein.png'] ] ] ); + if( $org->randomname ) $mailData['attachment'][0] = [ + 'filename' => $org->bijlagefile, + 'filePath' => MYROOTPATH. 'docs/'.$org->randomname ]; + + $mg->messages()->send( $_ENV['MAIL']['DOMAIN'], $mailData ); }else { $this->load->library( 'email' ); @@ -347,7 +355,10 @@ class Users extends MY_Controller{ $this->email->subject( 'Inloggegevens MonPas' ); $this->email->message( $html ); $this->email->bcc( "rfranke@framework-ed.nl" ); - $this->email->send(); + + $this->email->attach(MYROOTPATH. 'docs/'.$org->randomname,'attachment', $org->bijlagefile); + $this->email->send(); + $result = $this->email->print_debugger(); } echo json_encode(array('ok'=>$ok, 'errortekst'=>$errortekst)); diff --git a/public/js/monpas/models/gebruikersmodel.js b/public/js/monpas/models/gebruikersmodel.js index 517eea0..1891bc9 100644 --- a/public/js/monpas/models/gebruikersmodel.js +++ b/public/js/monpas/models/gebruikersmodel.js @@ -112,9 +112,9 @@ ls.initGebruikersModel = function(){ otherUsers : ko.observableArray([]), functies :ko.observableArray([]), zoekstring : ko.observable(''), - titel : ko.observable({title: ko.observable(), status: ko.observable()} ), + titel : ko.observable({title: ko.observable(), status: ko.observable()} ), autorisatieopties : ko.observableArray([]), - focusop : ko.observable(1), //werkt weer eens niet + focusop : ko.observable(1), //werkt weer eens niet bezig : ko.observable(false), initBindings :function(){ @@ -320,12 +320,19 @@ ls.initGebruikersModel = function(){ fSendNewWW: function(){ var self = ls.GebruikersModel; - $.post("index.php/shared/users/sendnewww/" + self.selectedUser().userid, function(result){ + + if (self.bezig()) return + let sd = {userid: self.selectedUser().userid, + orgid : self.selectedOrg().id} + self.bezig(true) + $.post("index.php/shared/users/SendNewWW" ,sd, function(result){ if (result) { apprise("Er is een e-mail verstuurd naar " +self.selectedUser().email() + " met daarin het nieuwe wachtwoord."); } + self.bezig(false) },'json'); }, + fToggleGeopend : function(){ this.geopend(!this.geopend()); },