08.24 php saved
PhpNut
Tags add more
security  
Note
After using security component, page is blank after POST.
  1. <?php
  2. /**
  3. * @author Kunthar
  4. * @name AccountsController
  5. * @package accounts
  6. * @todo Protector will be added, i18n will be implemented, all constants will be converted to __d(), mailer, 
  7. *
  8. **/
  9.  
  10. class AccountsController extends AppController {
  11.  
  12.     var $name = 'Accounts';
  13.     var $components = array('SwiftMailer', 'Krumo', 'Protector', 'Conf', 'Security' );
  14.     var $cacheAction = false;   
  15.    
  16.     /**
  17.      *@example smtp connection methods
  18.      * $this->SwiftMailer->smtp_host   = 'localhost';
  19.      * $this->SwiftMailer->smtp_type   = 'open';
  20.      * $this->SwiftMailer->username  = 'user@mail.com';
  21.      * $this->SwiftMailer->password  = 'passwd';
  22.      */
  23.     function beforeFilter(){
  24.        
  25.     $this->Security->requireAuth('add', 'login');
  26.     $this->Security->requirePost('add', 'login');
  27.    
  28.     // Before filter startup tan sonra başlıyor, bu durumda burada kullanılacak her comp için kendisini başlatmak gerekiyor...
  29.     $this->Conf->startup(&$this);
  30.     $this->Conf->set('app.foo','php',array('dallama','java','zopa'));
  31.     $this->Conf->set('weee.bar','chocolat',null,'true','true');
  32.     $this->Conf->set('app.foo','Cake sucks!');
  33.    
  34.     }
  35.        
  36.     function mailToRegistrant(){
  37.        
  38.         $this->log('mailToRegistrant starts', 3);
  39.         $this->SwiftMailer->connection  = 'native';
  40.         if($this->SwiftMailer->connect())
  41.         {
  42.         $this->SwiftMailer->addTo('to',"kunthar@gmail.com","Kunthar");
  43.         $this->SwiftMailer->addTo('from',"shop@mira-soft.com","Shop test mail");
  44.  
  45.         if(!$this->SwiftMailer->sendView("Someone registers :)  " . $this->Session->read('account.email'),"email",'both'))
  46.         {
  47.         $this->log('Mail failed errors: ', 3);
  48.         echo "The mailer failed to Send. Errors:";
  49.         pr($this->SwiftMailer->errors());
  50.         }
  51.         $this->log('Mail sent okay. cHECK Inbox');
  52.         //pr($this->SwiftMailer->transactions());
  53.         }
  54.         else
  55.         {
  56.         $this->log('The mailer failed to connect. ', 3);
  57.         echo "The mailer failed to connect. Errors:";
  58.         pr($this->SwiftMailer->errors());
  59.         }  
  60.         }
  61.    
  62.     function login()
  63.     {
  64.     //Don't show the error message if no data has been submitted.
  65.     $this->set('error', false);
  66.    
  67.     // Check if we're already logged in
  68.     if($user = $this->Session->read('Account'))
  69.     {
  70.     $this->Session->setFlash(__d('default','Zaten giriş yapmışsınız, hoşgeldiniz'.$user['email'], false));
  71.     $this->redirect('/account/dashboard/' . $user['id']);
  72.     }
  73.     // If a user has submitted form data:
  74.     if (!empty($this->data))
  75.     {
  76.     $someone = $this->Account->findByEmail($this->data['Account']['email']);
  77.     $this->data['Account']['account_pass'] = $this->data['Account']['account_pass'];
  78.     if(!empty($someone['Account']['account_pass']) && $someone['Account']['account_pass'] == $this->data['Account']['account_pass'] && $someone['Account']['account'] == '1')
  79.     {
  80.  
  81.     $this->Session->setFlash('Hoşgeldiniz... Lütfen bekleyin.');
  82.     $this->Session->write('Account', $someone['Account']);
  83.     $this->redirect('/front/' . $someone['Account']['id']);
  84.     // The user is trying to retrieve their password so send a copy of the
  85.     // password to the email address provided.
  86.     } else {
  87.     // else, they supplied incorrect data:
  88.     $this->Session->setFlash('Girdiğiniz bilgi eksik ya da yanlış, lütfen tekrar deneyiniz.');
  89.     $this->redirect('/accounts/login');
  90.     }
  91.     }
  92.     }
  93.    
  94.     function logout()
  95.     {
  96.     $this->Session->delete('Account');
  97.     $this->redirect('/');
  98.     }
  99.  
  100.    
  101.     function add(){
  102.         $this->set('title', 'Kaydolun bedava hediyeler kazanin- FotoWeb24');
  103.         $this->set('error', false)
  104.  
  105.       // Let the validations begins
  106.       if (!empty($this->data))
  107.       {
  108.         //Datayı model datasına eşle, validation için kullanıldı
  109.         $this->Account->data = $this->data;
  110.  
  111.       // Modelde ele alınamayacak validation işlerini hallet, modelde ayrica valiaditon rules var.
  112.       if (empty($this->data['Account']['first_name']) || ($this->data['Account']['first_name'] == null)){
  113.             $this->set('error', true);  
  114.           $this->set('fn_error', SH_FIRSTNAME_ERROR);
  115.       }
  116.       if (empty($this->data['Account']['last_name']) || ($this->data['Account']['last_name'] == null)){
  117.              $this->set('ln_error', SH_LASTNAME_ERROR);
  118.              $this->set('error', true);
  119.       }
  120.       
  121.         // Cake 1.2 style validation
  122.         if ($this->Account->validates())
  123.         {
  124.           if ($this->Account->findByEmail($this->data['Account']['email']))
  125.           {
  126.           $this->set('email_exist_error', SH_EMAIL_EXIST);  
  127.           $this->set('error', true);
  128.           }
  129.           if ($this->data['Account']['account_pass'] != $this->data['Account']['account_pass2']){
  130.              $this->set('pw_error', SH_PASSWORDS_NOT_MATCH);
  131.              $this->set('error', true);
  132.           }
  133.          if (empty($this->data['Account']['accepted']) || ($this->data['Account']['accepted'] == null)){
  134.              $this->set('accept_error', SH_ACCEPT_ERROR);
  135.              $this->set('error', true);
  136.           }
  137.           else {
  138.             $this->data['Account']['account_pass'] = sha1($this->data['Account']['account_pass']);
  139.             if ($this->Account->save($this->data))
  140.             {
  141.               /**
  142.                * @todo aro aco will be added, void_leenux bro gonna handle this
  143.                */
  144.               //$aro = new Aro();
  145.               //$aro->create($this->Account->id, 'Accounts', $this->data['Account']['email']);
  146.               $this->Session->write('account.email', $this->data['Account']['email']);
  147.               $this->Session->write('account.id', $this->Account->getLastInsertID());
  148.               //$this->mailToRegistrant();
  149.               $this->redirect('/front');
  150.               
  151.               
  152.             } else {
  153.               $this->flash(SH_REGISTER_ERROR, '/registration');
  154.             }
  155.           }
  156.         } else {
  157.           $this->validateErrors($this->Account);
  158.         }
  159.       }
  160.     }
  161.     function registration() {
  162.         $this->set('title', 'Kaydolun bedava hediyeler kazanin- FotoWeb24');
  163.         $this->set('error', false)
  164.        
  165.     }
  166.  
  167.  
  168.  
  169. }
  170.  
  171. ?>
Parsed in 0.299 seconds, using GeSHi 1.0.7.14

Modify this Paste