コード例 #1
0
ファイル: TimeHelper.php プロジェクト: mrbadao/api-official
 /**
  * Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
  *
  * @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|DateTimeZone $timezone   User's timezone string or DateTimeZone object
  *
  * @return int Unix timestamp
  * @see  CakeTime::toUnix()
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 public function toUnix($dateString, $timezone = NULL)
 {
     return $this->_engine->toUnix($dateString, $timezone);
 }
コード例 #2
0
 /**
  * The function to reset a password
  * @param type $key The LostPasswordKey to use
  */
 public function reset_password($key = null)
 {
     if ($key == null) {
         $this->Session->setFlash("A valid password reset key was not given.", 'default', array(), 'error');
         $this->redirect('/');
     } else {
         $passwordkey = $this->User->LostPasswordKey->findByKey($key);
         if (empty($passwordkey)) {
             $this->Session->setFlash("The key given was invalid", 'default', array(), 'error');
             $this->redirect('lost_password');
         } else {
             if ($this->request->is('post')) {
                 //Check if the key has expired
                 App::uses('CakeTime', 'Utility');
                 $keytime = CakeTime::toUnix($passwordkey['LostPasswordKey']['created']);
                 if ($keytime + 1800 >= time()) {
                     if ($this->request->data['User']['password'] == $this->request->data['User']['password_confirm']) {
                         //if the passwords match
                         $this->User->id = $passwordkey['User']['id'];
                         if ($this->User->save($this->request->data)) {
                             $this->User->LostPasswordKey->delete($passwordkey['LostPasswordKey']);
                             $this->Session->setFlash("Your password has been reset. You can now login.", 'default', array(), 'success');
                             $this->log("[UsersController.reset_password] password reset for user[" . $passwordkey['User']['id'] . "]", 'devtrack');
                             $this->redirect('/login');
                         } else {
                             $this->Session->setFlash("There was problem resetting your password. Please try again.", 'default', array(), 'error');
                         }
                     } else {
                         $this->Session->setFlash("Your passwords do not match. Please try again.", 'default', array(), 'error');
                     }
                 } else {
                     $this->Session->setFlash("The key given was invalid", 'default', array(), 'error');
                     $this->redirect('lost_password');
                 }
             }
         }
     }
 }