2012-03-07 26 views
0

おはよう!私は現在、CakePHPの1.3から2.0へのコードを移行しています。そして私はちょうど質問したい、どのように私はこのコードを(1.3から)2.0にすることができますか?ここでは、コードです:cakephp2.0での登録とログイン

function register() { 
if(!empty($this->data)) { 
     // unset unrequired validation rules 
     unset($this->User->validate['username']['check_user']); 

     // validate & save data 
     if($this->User->save($this->data)) { 
      $this->data['User']['Password'] = md5($this->data['User']['Password']);   
      $this->User->save($this->data); 
      // set Flash & redirect 
      $this->Session->setFlash('You have successfully registered.','default',array('class'=>'flash_good')); 
      $this->redirect(array('action'=>'login')); 
     } 
     else{ 
      //$this->Session->setFlash(__('The user could not be saved.' , true)); 
      //$this->redirect(array('action' => 'register')); 
     } 
    } 
} 

と、ここで私が解決しようとした私の試みコードです:

public function register() { 
    if($this->request->is('post')) { 
    //unset($this->User->validate['username']['check_user']); 

     // validate & save data 

     //$this->data['User']['Password'] = md5($this->data['User']['Password']);  
     $this->request->data('User.Password', $this->request->data('User.Password'));  
     // $this->User->save($this->data); 
     // set Flash & redirect 
     if($this->User->save($this->request->data)) { 
      $this->Session->setFlash('You have successfully registered.','default',array('class'=>'flash_good')); 
      $this->redirect(array('action'=>'login')); 
     } 
     else{ 
      //$this->Session->setFlash(__('The user could not be saved.' , true)); 
      //$this->redirect(array('action' => 'register')); 
     } 
    } 
} 

このコードは、ここで1.3

function login() { 
    //echo $_SESSION['User']['auth']; 
    if(!isset($_SESSION['User']['id'])){ 
     if(!empty($this->data)) { 
      if(($user = $this->User->validateLogin($this->data['User'])) == true) 
      { 
      //print_r(md5($this->data['User']['password'])); 
       $user = $this->User->find('first',array('conditions'=>array('Username'=>$this->data['User']['Username'],'Password'=>md5($this->data['User']['Password'])))); 
       //print_r ($user); 
       if(!empty($user)){ 
        $_SESSION['User']['id'] = $user['User']['id']; 
        $_SESSION['User']['name'] = $user['User']['Name']; 
        $_SESSION['User']['auth'] = $user['User']['auth']; 
        $this->redirect(array('controller'=>'ads','action'=>'index')); 
       }else{ 
        $this->Session->setFlash('Username/Password not match'); 
        $this->redirect(array('action'=>'login')); 
       } 
      } 
     } 
    } 
     else{ 
     $this->Session->setFlash('Login First.'); 
     $this->redirect(array('controller'=>'ads','action'=>'index')); 

    } 
} 

とで行われ、ログインのためであります2.0の私のコードですが、まだそれは動作していません。

public function login() { 

    if(!($this->Session->read('user_id'))){ 
     if($this->request->is('post')) {   
      //$user = $this->User->find('first',array('conditions'=>array('Username'=>$this->data['User']['Username'],'Password'=>md5($this->data['User']['Password'])))); 

       if(!empty($user)){ 
        $this->Session->write('user_id',$user['User']['id']); 
        $this->Session->write('name',$user['User']['Name']); 
        //$this->Session->write('name',$user['User']['Name']); 
        $this->redirect(array('controller'=>'ads','action'=>'index')); 
       }else{ 
        $this->Session->setFlash('Username/Password not match'); 
        $this->redirect(array('action'=>'login')); 
       } 

     } 
    }else{ 
     $this->redirect(array('controller'=>'ads','action'=>'index')); 
    } 
}//end login 

誰かが私の質問に答えることを願っています。前もって感謝します。

+0

私の質問に関するフォローアップ情報、私はあまりにもパスワードのmd5について懸念している、それは私が解決したいことです。ありがとう – bowmeow

答えて

関連する問題