From 34f07e3120cd413e634ee49bd38219743b168ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Tue, 8 Apr 2014 19:28:07 +0200 Subject: [PATCH] erste Mailversuche + registration sollte fertig sein + auser aktivierung --- app/Config/email.php | 103 ++++++++++++++++++ .../Component/MiconwareSessionComponent.php | 5 +- app/Controller/RegistrationController.php | 91 ++++++++++++++-- app/Model/DreamjobCompany.php | 36 +++++- app/Model/DreamjobWorker.php | 48 +++++++- app/View/Emails/html/simple_message.ctp | 6 + app/View/Emails/text/simple_message.ctp | 6 + app/View/Job/application_send.ctp | 2 +- app/webroot/js/dreamjob.js | 14 +-- 9 files changed, 286 insertions(+), 25 deletions(-) create mode 100755 app/Config/email.php create mode 100644 app/View/Emails/html/simple_message.ctp create mode 100644 app/View/Emails/text/simple_message.ctp diff --git a/app/Config/email.php b/app/Config/email.php new file mode 100755 index 0000000..d158f0c --- /dev/null +++ b/app/Config/email.php @@ -0,0 +1,103 @@ + The name of a supported transport; valid options are as follows: + * Mail - Send using PHP mail function + * Smtp - Send using SMTP + * Debug - Do not send the email, just return the result + * + * You can add custom transports (or override existing transports) by adding the + * appropriate file to app/Network/Email. Transports should be named 'YourTransport.php', + * where 'Your' is the name of the transport. + * + * from => + * The origin email. See CakeEmail::from() about the valid values + * + */ +class EmailConfig { + + public $default = array( + 'transport' => 'Mail', + 'from' => 'you@localhost', + //'charset' => 'utf-8', + //'headerCharset' => 'utf-8', + ); + + public $dreamjobMain = array( + 'transport' => 'Mail', + 'from' => array('noreply@dreamjob.cc'=>'Dreamjob-Site'), + 'replyTo' => array('service@dreamjob.cc'=>'[Dreamjob] Service'), + 'emailFormat'=>'both', + 'charset' => 'utf-8', + 'headerCharset' => 'utf-8', + ); + + public $smtp = array( + 'transport' => 'Smtp', + 'from' => array('site@localhost' => 'My Site'), + 'host' => 'localhost', + 'port' => 25, + 'timeout' => 30, + 'username' => 'user', + 'password' => 'secret', + 'client' => null, + 'log' => false, + //'charset' => 'utf-8', + //'headerCharset' => 'utf-8', + ); + + public $fast = array( + 'from' => 'you@localhost', + 'sender' => null, + 'to' => null, + 'cc' => null, + 'bcc' => null, + 'replyTo' => null, + 'readReceipt' => null, + 'returnPath' => null, + 'messageId' => true, + 'subject' => null, + 'message' => null, + 'headers' => null, + 'viewRender' => null, + 'template' => false, + 'layout' => false, + 'viewVars' => null, + 'attachments' => null, + 'emailFormat' => null, + 'transport' => 'Smtp', + 'host' => 'localhost', + 'port' => 25, + 'timeout' => 30, + 'username' => 'user', + 'password' => 'secret', + 'client' => null, + 'log' => true, + //'charset' => 'utf-8', + //'headerCharset' => 'utf-8', + ); + +} diff --git a/app/Controller/Component/MiconwareSessionComponent.php b/app/Controller/Component/MiconwareSessionComponent.php index 5dc479d..3bf2d76 100755 --- a/app/Controller/Component/MiconwareSessionComponent.php +++ b/app/Controller/Component/MiconwareSessionComponent.php @@ -117,8 +117,9 @@ class MiconwareSessionComponent extends Component { )); } - - + public static function generateKey($length=8){ + return base64_encode(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)); + } /** * PasswordHasg diff --git a/app/Controller/RegistrationController.php b/app/Controller/RegistrationController.php index f1bde10..ed57dcf 100644 --- a/app/Controller/RegistrationController.php +++ b/app/Controller/RegistrationController.php @@ -1,6 +1,7 @@ to($data['User']['mail']); + $Email->subject('Welcome to our really cool thing'); + $Email->template('simple_message'); + $Email->viewVars(array('data'=>$data)); + return $Email->send(); + } public function main() { $this->MiconwareSession->init($this); @@ -30,11 +40,38 @@ class RegistrationController extends AppController { if ($this->request->is('post')){ if($this->request->data['DreamjobCompany']['agb']) { unset($this->request->data['DreamjobCompany']['agb']); - $result = $this->DreamjobCompany->registration($this->request->data); - if ($result) { - $this->MiconwareSession->setFlash('dreamjob.registration.done','flash',array('alert'=>'success')); - }else{ - $this->MiconwareSession->setFlash('dreamjob.registration.error','flash',array('alert'=>'danger')); + if($this->request->data['User']['password1'] == $this->request->data['User']['password2']) { + $data = array(); + $data['User']['password'] = $this->MiconwareSession->create_hash($this->request->data['User']['password1']); + $data['User']['mail'] = $this->request->data['User']['mail']; + $data['DreamjobUser']['city'] = $this->request->data['DreamjobUser']['city']; + $data['DreamjobUser']['street'] = $this->request->data['DreamjobUser']['street']; + $data['DreamjobUser']['postcode'] = $this->request->data['DreamjobUser']['postcode']; + $data['AppUser']['nickname'] = $this->request->data['AppUser']['nickname']; + + $data['DreamjobCompany']['corporateform'] = $this->request->data['DreamjobCompany']['corporateform']; + $data['DreamjobCompany']['owner'] = $this->request->data['DreamjobCompany']['owner']; + $data['DreamjobCompany']['branch_id'] = $this->request->data['DreamjobCompany']['branch_id']; + $data['DreamjobCompany']['headcount'] = $this->request->data['DreamjobCompany']['headcount']; + $data['DreamjobCompany']['bank_details'] = ''; + //$data['DreamjobCompany']['bank_details'] = $this->request->data['DreamjobCompany']['bank_details']; + $data['DreamjobCompany']['website'] = $this->request->data['DreamjobCompany']['website']; + $data['User']['code'] = "a:".$this->MiconwareSession->generateKey(); + + $result = $this->DreamjobCompany->registration($data); + if($result){ + $result = $this->registrationMail($data); + if($result){ + $this->log("Registratrion Mail:"+$data['User']['mail']); + } + } + if ($result) { + $this->MiconwareSession->setFlash('dreamjob.registration.done','flash',array('alert'=>'success')); + }else{ + $this->MiconwareSession->setFlash('dreamjob.registration.error','flash',array('alert'=>'danger')); + } + }else if($this->request->data['User']['password1']!='' or $this->request->data['User']['password2']!=''){ + $this->MiconwareSession->setFlash(__('dreamjob.error.password.notEqual'),'flash',array('alert'=>'danger')); } }else{ $this->MiconwareSession->setFlash('dreamjob.agb.error.notAccept','flash',array('alert'=>'danger')); @@ -55,11 +92,41 @@ class RegistrationController extends AppController { if ($this->request->is('post')){ if($this->request->data['DreamjobWorker']['agb']) { unset($this->request->data['DreamjobWorker']['agb']); - $result = $this->DreamjobWorker->registration($this->request->data); - if ($result) { - $this->MiconwareSession->setFlash('dreamjob.registration.done','flash',array('alert'=>'success')); - }else{ - $this->MiconwareSession->setFlash('dreamjob.registration.error','flash',array('alert'=>'danger')); + if($this->request->data['User']['password1'] == $this->request->data['User']['password2']) { + $data = array(); + $data['User']['password'] = $this->MiconwareSession->create_hash($this->request->data['User']['password1']); + $data['User']['mail'] = $this->request->data['User']['mail']; + $data['DreamjobUser']['city'] = $this->request->data['DreamjobUser']['city']; + $data['DreamjobUser']['street'] = $this->request->data['DreamjobUser']['street']; + $data['DreamjobUser']['postcode'] = $this->request->data['DreamjobUser']['postcode']; + $data['AppUser']['bday'] = $this->request->data['AppUser']['bday']; + $data['AppUser']['first_name'] = $this->request->data['AppUser']['first_name']; + $data['AppUser']['last_name'] = $this->request->data['AppUser']['last_name']; + //WORKER + $data['AppUser']['mannerofaddress_id'] = $this->request->data['AppUser']['mannerofaddress_id']; + $data['DreamjobWorker']['country'] = $this->request->data['DreamjobWorker']['country']; + $data['DreamjobWorker']['iam'] = $this->request->data['DreamjobWorker']['iam']; + $data['DreamjobWorker']['graducation_id'] = $this->request->data['DreamjobWorker']['graducation_id']; + $data['DreamjobWorker']['searchhidden'] = true; + $data['DreamjobWorker']['workexperience'] = $this->request->data['DreamjobWorker']['workexperience']; + + $data['User']['code'] = "a:".$this->MiconwareSession->generateKey(); + + $result = $this->DreamjobWorker->registration($data); + + if($result){ + $result = $this->registrationMail($data); + if($result){ + $this->log("Registratrion Mail:"+$data['User']['mail']); + } + } + if ($result) { + $this->MiconwareSession->setFlash('dreamjob.registration.done','flash',array('alert'=>'success')); + }else{ + $this->MiconwareSession->setFlash('dreamjob.registration.error','flash',array('alert'=>'danger')); + } + }else if($this->request->data['User']['password1']!='' or $this->request->data['User']['password2']!=''){ + $this->MiconwareSession->setFlash(__('dreamjob.error.password.notEqual'),'flash',array('alert'=>'danger')); } }else{ $this->MiconwareSession->setFlash('dreamjob.agb.error.notAccept','flash',array('alert'=>'danger')); diff --git a/app/Model/DreamjobCompany.php b/app/Model/DreamjobCompany.php index da0ad3c..165347f 100755 --- a/app/Model/DreamjobCompany.php +++ b/app/Model/DreamjobCompany.php @@ -38,11 +38,43 @@ class DreamjobCompany extends AppModel { public $displayField = 'djaccount_ptr_id'; - public function registration($data){ + public function registration($data){ $dataSource = $this->getDataSource(); + $dataSource->begin(); + + if($data['AppUser']['nickname']) + $data['User']['nickname'] = $data['AppUser']['nickname']; + else + $data['AppUser']['nickname'] = $data['User']['nickname']; + + + + + $this->User->create(array('User'=>$data['User'])); + $result=$this->User->save(); + if($result){ + $data['User']['id']=$this->User->id; + $data['AppUser']['user_id']=$this->User->id; + $this->AppUser->create(array('AppUser'=>$data['AppUser'])); + $result=$this->AppUser->save(); + } + + if($result){ + $data['AppUser']['id']=$this->AppUser->id; + $data['DreamjobUser']['micapplication_ptr_id']=$this->AppUser->id; + $this->DreamjobUser->create(array('DreamjobUser'=>$data['DreamjobUser'])); + $result=$this->DreamjobUser->save(); + } + + if($result){ + $data['DreamjobCompany']['djaccount_ptr_id']=$this->AppUser->id; + $this->create(array('DreamjobCompany'=>$data['DreamjobCompany'])); + $result=$this->save(); + } + if ($result) { - $dataSource->commit(); + $dataSource->rollback(); return true; } else { $dataSource->rollback(); diff --git a/app/Model/DreamjobWorker.php b/app/Model/DreamjobWorker.php index 5639e78..c700b6a 100755 --- a/app/Model/DreamjobWorker.php +++ b/app/Model/DreamjobWorker.php @@ -40,9 +40,55 @@ class DreamjobWorker extends AppModel { public function registration($data){ $dataSource = $this->getDataSource(); + $dataSource->begin(); + + if($data['AppUser']['mannerofaddress_id']) + $data['User']['mannerofaddress_id'] = $data['AppUser']['mannerofaddress_id']; + else + $data['AppUser']['mannerofaddress_id'] = $data['User']['mannerofaddress_id']; + + if($data['AppUser']['first_name']) + $data['User']['first_name'] = $data['AppUser']['first_name']; + else + $data['AppUser']['first_name'] = $data['User']['first_name']; + + if($data['AppUser']['last_name']) + $data['User']['last_name'] = $data['AppUser']['last_name']; + else + $data['AppUser']['last_name'] = $data['User']['last_name']; + + if($data['AppUser']['bday']) + $data['User']['bday'] = $data['AppUser']['bday']; + else + $data['AppUser']['bday'] = $data['User']['bday']; + + + + $this->User->create(array('User'=>$data['User'])); + $result=$this->User->save(); + if($result){ + $data['User']['id']=$this->User->id; + $data['AppUser']['user_id']=$this->User->id; + $this->AppUser->create(array('AppUser'=>$data['AppUser'])); + $result=$this->AppUser->save(); + } + + if($result){ + $data['AppUser']['id']=$this->AppUser->id; + $data['DreamjobUser']['micapplication_ptr_id']=$this->AppUser->id; + $this->DreamjobUser->create(array('DreamjobUser'=>$data['DreamjobUser'])); + $result=$this->DreamjobUser->save(); + } + + if($result){ + $data['DreamjobWorker']['djaccount_ptr_id']=$this->AppUser->id; + $this->create(array('DreamjobWorker'=>$data['DreamjobWorker'])); + $result=$this->save(); + } + if ($result) { - $dataSource->commit(); + $dataSource->rollback(); return true; } else { $dataSource->rollback(); diff --git a/app/View/Emails/html/simple_message.ctp b/app/View/Emails/html/simple_message.ctp new file mode 100644 index 0000000..301bab3 --- /dev/null +++ b/app/View/Emails/html/simple_message.ctp @@ -0,0 +1,6 @@ + diff --git a/app/View/Emails/text/simple_message.ctp b/app/View/Emails/text/simple_message.ctp new file mode 100644 index 0000000..301bab3 --- /dev/null +++ b/app/View/Emails/text/simple_message.ctp @@ -0,0 +1,6 @@ + diff --git a/app/View/Job/application_send.ctp b/app/View/Job/application_send.ctp index 1563d89..becd5ad 100644 --- a/app/View/Job/application_send.ctp +++ b/app/View/Job/application_send.ctp @@ -30,7 +30,7 @@
Form->checkbox('agb');?> - Html->link(__("dreamjob.agb.accept"),array('controller'=>'home','action'=>'agb'),array('ref'=>'external'));?> + Html->link(__("dreamjob.agb.accept"),array('controller'=>'home','action'=>'agb'),array('data-target'=>'#popup','data-toggle'=>"modal",'title'=>__('dreamjob.agb'),"ref"=>"eventOff"));?>

Form->button(__('dreamjob.application.send'),array('div' => false,'class'=>"btn btn-primary ",'type' => 'submit'));?> diff --git a/app/webroot/js/dreamjob.js b/app/webroot/js/dreamjob.js index 065b805..4c5499f 100755 --- a/app/webroot/js/dreamjob.js +++ b/app/webroot/js/dreamjob.js @@ -10,15 +10,15 @@ ajaxStart: function() { $body.addClass("loading"); }, ajaxStop: function() { $body.removeClass("loading"); } }); + $("#popup").modal({'remote':false,'show':false}); + $("#popup").on('show.bs.modal',function(e){ + $.ajax({url:$(e.relatedTarget).attr("href"),success:function(data){ + $("#popup .modal-title").html($(e.relatedTarget).attr("title")); + $("#popup .modal-body").html($("#container div.box",data).html()); + } ,error:function(data){}}); + }); function event(where){ $("#alert .alert").alert(); - $("#popup").modal({'remote':false,'show':false}); - $("#popup").on('show.bs.modal',function(e){ - $.ajax({url:$(e.relatedTarget).attr("href"),success:function(data){ - $("#popup .modal-title").html($(e.relatedTarget).attr("title")); - $("#popup .modal-body").html($("#container div.box",data).html()); - } ,error:function(data){}}); - }); $(where+'.dropdown-toggle').dropdown();