From ddaa34bb7a1678ce80064eadcdd746a084174210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 9 Apr 2014 19:30:26 +0200 Subject: [PATCH] registration mit mail und aktivierung fertig --- app/Config/routes.php | 2 +- app/Controller/RegistrationController.php | 14 +++++++++++--- app/Model/DreamjobCompany.php | 2 +- app/Model/DreamjobWorker.php | 2 +- app/Model/User.php | 23 +++++++++++++++++++++++ app/View/Emails/html/registration.ctp | 3 ++- app/View/Emails/text/registration.ctp | 3 ++- app/View/Registration/active.ctp | 12 ++++++++++++ app/View/User/test.ctp | 4 ++++ 9 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 app/View/Registration/active.ctp diff --git a/app/Config/routes.php b/app/Config/routes.php index 00067ad..3345851 100755 --- a/app/Config/routes.php +++ b/app/Config/routes.php @@ -34,7 +34,7 @@ Router::connect('/registration', array('controller' => 'registration', 'action' => 'main')); Router::connect('/registration/user', array('controller' => 'registration', 'action' => 'worker')); Router::connect('/registration/company', array('controller' => 'registration', 'action' => 'company')); - Router::connect('/registration/active/:code', array('controller' => 'registration', 'action' => 'active'),array("code" => "(?i:code)")); + Router::connect('/registration/active/:code', array('controller' => 'registration', 'action' => 'active'),array("code" => ".+")); Router::connect('/profil', array('controller' => 'user', 'action' => 'profil')); Router::connect('/profil/page/:page', array('controller' => 'user', 'action' => 'profil'),array("page" => "[0-9]+")); diff --git a/app/Controller/RegistrationController.php b/app/Controller/RegistrationController.php index 7cc4c58..9e974c6 100644 --- a/app/Controller/RegistrationController.php +++ b/app/Controller/RegistrationController.php @@ -11,7 +11,7 @@ class RegistrationController extends AppController { * @var array */ public $componens = array('Email','MiconwareSession'); - public $uses = array('Mannerofaddress','DreamjobListGraducation','DreamjobListBranch','DreamjobWorker','DreamjobCompany'); + public $uses = array('Mannerofaddress','DreamjobListGraducation','DreamjobListBranch','DreamjobWorker','DreamjobCompany','User'); private function registrationMail($data,$key){ $Email = new CakeEmail('dreamjobMain'); @@ -145,8 +145,16 @@ class RegistrationController extends AppController { } } public function active(){ - $this->set('error', 'dreamjob.error.loggedin'); - $this->render('/Home/error'); + $this->MiconwareSession->init($this); + $this->MiconwareSession->initWeb($this); + if(!$this->MiconwareSession->isLoggedin() and !empty($this->request->params['code']) and !empty($this->request->query['mail']) ){ + $result = $this->User->activeLinkUser($this->request->query['mail'],$this->request->params['code']); + $this->set("result",$result); + $this->render('/Registration/active'); + }else{ + $this->set('error', 'dreamjob.error.loggedin'); + $this->render('/Home/error'); + } } } diff --git a/app/Model/DreamjobCompany.php b/app/Model/DreamjobCompany.php index 165347f..df2db92 100755 --- a/app/Model/DreamjobCompany.php +++ b/app/Model/DreamjobCompany.php @@ -74,7 +74,7 @@ class DreamjobCompany extends AppModel { } if ($result) { - $dataSource->rollback(); + $dataSource->commit(); return true; } else { $dataSource->rollback(); diff --git a/app/Model/DreamjobWorker.php b/app/Model/DreamjobWorker.php index c700b6a..aad831c 100755 --- a/app/Model/DreamjobWorker.php +++ b/app/Model/DreamjobWorker.php @@ -88,7 +88,7 @@ class DreamjobWorker extends AppModel { } if ($result) { - $dataSource->rollback(); + $dataSource->commit(); return true; } else { $dataSource->rollback(); diff --git a/app/Model/User.php b/app/Model/User.php index 906adb4..ed58189 100755 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -33,6 +33,29 @@ class User extends AppModel { * * @var array */ + public function activeLinkUser($mail,$key){ + $dataSource = $this->getDataSource(); + + $dataSource->begin(); + $data = $this->find('first',array('conditions' => array( + 'mail' => $mail, + 'code'=> 'a:'.$key + ))); + $result = false; + if(!empty($data) and count($data)>0){ + $this->id = $data['User']['id']; + $result = $this->saveField('code',''); + if($result) + $result = $this->saveField('is_active',true); + } + if($result) { + $dataSource->commit(); + return true; + } else { + $dataSource->rollback(); + } + return false; + } public $validate = array( 'id' => array( 'multiple' => array( diff --git a/app/View/Emails/html/registration.ctp b/app/View/Emails/html/registration.ctp index 95459d2..ddaab86 100644 --- a/app/View/Emails/html/registration.ctp +++ b/app/View/Emails/html/registration.ctp @@ -1,3 +1,4 @@ Html->link(__('dreamjob.regisration.active.link'),array('controller'=>'registration','action'=>'active','code'=>$key)); + echo $this->Html->link(__('dreamjob.regisration.active.link'),array('controller' => 'registration', 'action' => 'active','code'=>$key, + '?'=>array('mail'=>$data['User']['mail']))); ?> diff --git a/app/View/Emails/text/registration.ctp b/app/View/Emails/text/registration.ctp index 8715d39..6fe0d3a 100644 --- a/app/View/Emails/text/registration.ctp +++ b/app/View/Emails/text/registration.ctp @@ -1,3 +1,4 @@ Html->url(array('controller'=>'registration','action'=>'active','code'=>$key)); + echo $this->Html->url(array('controller'=>'registration','action'=>'active','code'=>$key + '?'=>array('mail'=>$data['User']['mail']))); ?> diff --git a/app/View/Registration/active.ctp b/app/View/Registration/active.ctp new file mode 100644 index 0000000..b1d6523 --- /dev/null +++ b/app/View/Registration/active.ctp @@ -0,0 +1,12 @@ + +
+

+ +
start('barleft'); Test, nicht fuer User geeignet. end(); +$key = "af4oi"; ?>
+ Html->link(__('dreamjob.regisration.active.link'),array('controller'=>'registration','action'=>'active','code'=>$key,'?'=>array('mail'=>'mueller@miconware.de'))); + ?>