Ejemplo n.º 1
0
 /**
  * Set the new password
  */
 protected function setNewPassword()
 {
     $objMember = \MemberModel::findByActivation(\Input::get('token'));
     if ($objMember === null || $objMember->login == '') {
         $this->strTemplate = 'mod_message';
         /** @var \FrontendTemplate|object $objTemplate */
         $objTemplate = new \FrontendTemplate($this->strTemplate);
         $this->Template = $objTemplate;
         $this->Template->type = 'error';
         $this->Template->message = $GLOBALS['TL_LANG']['MSC']['accountError'];
         return;
     }
     // Define the form field
     $arrField = $GLOBALS['TL_DCA']['tl_member']['fields']['password'];
     /** @var \Widget $strClass */
     $strClass = $GLOBALS['TL_FFL']['password'];
     // Fallback to default if the class is not defined
     if (!class_exists($strClass)) {
         $strClass = 'FormPassword';
     }
     /** @var \Widget $objWidget */
     $objWidget = new $strClass($strClass::getAttributesFromDca($arrField, 'password'));
     // Set row classes
     $objWidget->rowClass = 'row_0 row_first even';
     $objWidget->rowClassConfirm = 'row_1 odd';
     $this->Template->rowLast = 'row_2 row_last even';
     /** @var SessionInterface $objSession */
     $objSession = \System::getContainer()->get('session');
     // Validate the field
     if (strlen(\Input::post('FORM_SUBMIT')) && \Input::post('FORM_SUBMIT') == $objSession->get('setPasswordToken')) {
         $objWidget->validate();
         // Set the new password and redirect
         if (!$objWidget->hasErrors()) {
             $objSession->set('setPasswordToken', '');
             $objMember->tstamp = time();
             $objMember->activation = '';
             $objMember->password = $objWidget->value;
             $objMember->save();
             // HOOK: set new password callback
             if (isset($GLOBALS['TL_HOOKS']['setNewPassword']) && is_array($GLOBALS['TL_HOOKS']['setNewPassword'])) {
                 foreach ($GLOBALS['TL_HOOKS']['setNewPassword'] as $callback) {
                     $this->import($callback[0]);
                     $this->{$callback}[0]->{$callback}[1]($objMember, $objWidget->value, $this);
                 }
             }
             // Redirect to the jumpTo page
             if (($objTarget = $this->objModel->getRelated('reg_jumpTo')) !== null) {
                 $this->redirect($this->generateFrontendUrl($objTarget->row()));
             }
             // Confirm
             $this->strTemplate = 'mod_message';
             /** @var \FrontendTemplate|object $objTemplate */
             $objTemplate = new \FrontendTemplate($this->strTemplate);
             $this->Template = $objTemplate;
             $this->Template->type = 'confirm';
             $this->Template->message = $GLOBALS['TL_LANG']['MSC']['newPasswordSet'];
             return;
         }
     }
     $strToken = md5(uniqid(mt_rand(), true));
     $objSession->set('setPasswordToken', $strToken);
     $this->Template->formId = $strToken;
     $this->Template->fields = $objWidget->parse();
     $this->Template->action = \Environment::get('indexFreeRequest');
     $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['setNewPassword']);
 }
Ejemplo n.º 2
0
 /**
  * Activate an account
  */
 protected function activateAcount()
 {
     $this->strTemplate = 'mod_message';
     /** @var FrontendTemplate|object $objTemplate */
     $objTemplate = new \FrontendTemplate($this->strTemplate);
     $this->Template = $objTemplate;
     $objMember = \MemberModel::findByActivation(\Input::get('token'));
     if ($objMember === null) {
         $this->Template->type = 'error';
         $this->Template->message = $GLOBALS['TL_LANG']['MSC']['accountError'];
         return;
     }
     // Update the account
     $objMember->disable = '';
     $objMember->activation = '';
     $objMember->save();
     // HOOK: post activation callback
     if (isset($GLOBALS['TL_HOOKS']['activateAccount']) && is_array($GLOBALS['TL_HOOKS']['activateAccount'])) {
         foreach ($GLOBALS['TL_HOOKS']['activateAccount'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback[0]}->{$callback[1]}($objMember, $this);
         }
     }
     // Log activity
     $this->log('User account ID ' . $objMember->id . ' (' . $objMember->email . ') has been activated', __METHOD__, TL_ACCESS);
     // Redirect to the jumpTo page
     if (($objTarget = $this->objModel->getRelated('reg_jumpTo')) !== null) {
         $this->redirect($this->generateFrontendUrl($objTarget->row()));
     }
     // Confirm activation
     $this->Template->type = 'confirm';
     $this->Template->message = $GLOBALS['TL_LANG']['MSC']['accountActivated'];
 }