2011-10-27 44 views
0

任何人都可以看到此行的一個問題:在使用令牌時Use of undefined constant CAKE_SESSION_STRING - assumed 'CAKE_SESSION_STRING'CakePHP的MD5和蛋糕會話串

它仍然創建了一個令牌,但給出了錯誤,然後:$emailtoken = md5($user['User']['password'].CAKE_SESSION_STRING);

因爲它提供了以下錯誤它說,它是無效的:/

以下是完整的功能:

 function admin_resetpassword ($token = null) 
     { 
      // User submits their email address 
      if (!empty($this->data['User']['email'])) 
      { 
       // user submitted initial form 
       $user = $this->User->findByEmail($this->data['User']['email']); 
       if (empty($user)) 
       { 
        $this->Session->setFlash('Unknown email.'); 
        return; 
       } 
       else 
       { 
        $emailtoken = md5($user['User']['password'].CAKE_SESSION_STRING); 
        // send email (temp flash to test code) 
        $this->Session->setFlash($emailtoken); 
        return; 
       } 
      } 
// If the token is not empty on the url 
     if (!empty($token)) 
     { 
      $user = $this->User->find(array("MD5(User.password + '".CAKE_SESSION_STRING."')"=>$token)); 

      if (empty($user)) 
      { 
       $this->Session->setFlash('Invalid token.'); 
       return; 
      } 

      if (!empty($this->data['User']['password'])) 
      { 
       $user['User']['password'] = $this->data['User']['password']; 
       $this->user->save($user); 
       $this->Session->setFlash('New password set.'); 
       $this->redirect('/'); 
      } 

      $this->set('token', $token); 
      $this->render('newpassword2'); 
     } 


    } 

回答

0

問題CAKE_SESSION_STRING沒有定義(一個在錯誤中聲明)。 如果你想得到鹽或cipherSeed,使用Configure::read('Security.salt');$this-Session->id;但是你知道這個會話ID在一定的不活動期後會丟失,對吧?您將無法在稍後獲取該會話標識(除非將其保存在某處)。