Ejemplo n.º 1
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     $GLOBALS['TL_LANGUAGE'] = $objPage->language;
     \System::loadLanguageFile('tl_member');
     $this->loadDataContainer('tl_member');
     // Set new password
     if (strlen(\Input::get('token'))) {
         $this->setNewPassword();
         return;
     }
     // Username widget
     if (!$this->reg_skipName) {
         $arrFields['username'] = $GLOBALS['TL_DCA']['tl_member']['fields']['username'];
         $arrFields['username']['name'] = 'username';
     }
     // E-mail widget
     $arrFields['email'] = $GLOBALS['TL_DCA']['tl_member']['fields']['email'];
     $arrFields['email']['name'] = 'email';
     // Captcha widget
     if (!$this->disableCaptcha) {
         $arrFields['captcha'] = array('name' => 'lost_password', 'label' => $GLOBALS['TL_LANG']['MSC']['securityQuestion'], 'inputType' => 'captcha', 'eval' => array('mandatory' => true));
     }
     $row = 0;
     $strFields = '';
     $doNotSubmit = false;
     // Initialize the widgets
     foreach ($arrFields as $arrField) {
         $strClass = $GLOBALS['TL_FFL'][$arrField['inputType']];
         // Continue if the class is not defined
         if (!class_exists($strClass)) {
             continue;
         }
         $arrField['eval']['tableless'] = $this->tableless;
         $arrField['eval']['required'] = $arrField['eval']['mandatory'];
         $objWidget = new $strClass($strClass::getAttributesFromDca($arrField, $arrField['name']));
         $objWidget->storeValues = true;
         $objWidget->rowClass = 'row_' . $row . ($row == 0 ? ' row_first' : '') . ($row % 2 == 0 ? ' even' : ' odd');
         ++$row;
         // Validate the widget
         if (\Input::post('FORM_SUBMIT') == 'tl_lost_password') {
             $objWidget->validate();
             if ($objWidget->hasErrors()) {
                 $doNotSubmit = true;
             }
         }
         $strFields .= $objWidget->parse();
     }
     $this->Template->fields = $strFields;
     $this->Template->hasError = $doNotSubmit;
     // Look for an account and send the password link
     if (\Input::post('FORM_SUBMIT') == 'tl_lost_password' && !$doNotSubmit) {
         if ($this->reg_skipName) {
             $objMember = \MemberModel::findActiveByEmailAndUsername(\Input::post('email', true), null);
         } else {
             $objMember = \MemberModel::findActiveByEmailAndUsername(\Input::post('email', true), \Input::post('username'));
         }
         if ($objMember === null) {
             sleep(2);
             // Wait 2 seconds while brute forcing :)
             $this->Template->error = $GLOBALS['TL_LANG']['MSC']['accountNotFound'];
         } else {
             $this->sendPasswordLink($objMember);
         }
     }
     $this->Template->formId = 'tl_lost_password';
     $this->Template->username = specialchars($GLOBALS['TL_LANG']['MSC']['username']);
     $this->Template->email = specialchars($GLOBALS['TL_LANG']['MSC']['emailAddress']);
     $this->Template->action = \Environment::get('indexFreeRequest');
     $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['requestPassword']);
     $this->Template->rowLast = 'row_' . count($arrFields) . ' row_last' . ($row % 2 == 0 ? ' even' : ' odd');
     $this->Template->tableless = $this->tableless;
 }