Esempio n. 1
0
 /**
  * @param string $content
  * @return $this
  */
 public function restorePassword($content = null)
 {
     $t = Token::_getInstance();
     if (!is_null($content)) {
         $t->_get(array('Content' => $content, 'Type' => 'restorePassword'))->_eq()->__($this->_('token', false));
         if ($this->countErrors() || is_null($this->_('token'))) {
             return $this->addError('password restoration', 0);
         }
         $this->_get($this->_('token')['UserID']);
         if (!input('json')) {
             return $this;
         }
         if ($this->_upsert(array('Email' => $this->_result['Email'], 'Password' => PasswordHash::_getInstance()->create_hash(input('password')), 'FirstName' => $this->_result['FirstName'], 'LastName' => $this->_result['LastName'], 'RoleID' => $this->_result['RoleID']))->countErrors()) {
             return $this;
         }
         $t->_drop();
         return $this->result(Lang::_getInstance()->getValue('passwordReset', 'User'));
     }
     if (!input('json')) {
         return $this->result(array());
     }
     $email = input('email');
     if ($this->_get(array('Email' => $email, 'Active' => true))->_eq()->countErrors() || empty($this->_result)) {
         return $this->addError('password restoration', 1);
     }
     $t->_upsert(array('Content' => $t->_generate(), 'Type' => 'restorePassword', 'UserID' => $this->_result['ID']))->__($this->_('token', false));
     Email::_getInstance()->send($email, 'restorePassword', array('token' => $this->_('token')['Content']));
     if ($this->countErrors()) {
         $t->_drop();
         return $this;
     }
     return $this->result(Lang::_getInstance()->getValue('passwordRestorationSent', 'User'));
 }