예제 #1
0
 /**
  * Форма смены пароля, емайла
  */
 protected function EventAccount()
 {
     /**
      * Устанавливаем title страницы
      */
     E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('settings_menu_profile'));
     $this->sMenuSubItemSelect = 'account';
     /**
      * Если нажали кнопку "Сохранить"
      */
     if (isPost('submit_account_edit')) {
         E::ModuleSecurity()->ValidateSendForm();
         $bError = false;
         /**
          * Проверка мыла
          */
         if (F::CheckVal(F::GetRequestStr('mail'), 'mail')) {
             if (($oUserMail = E::ModuleUser()->GetUserByMail(F::GetRequestStr('mail'))) && $oUserMail->getId() != $this->oUserCurrent->getId()) {
                 E::ModuleMessage()->AddError(E::ModuleLang()->Get('settings_profile_mail_error_used'), E::ModuleLang()->Get('error'));
                 $bError = true;
             }
         } else {
             E::ModuleMessage()->AddError(E::ModuleLang()->Get('settings_profile_mail_error'), E::ModuleLang()->Get('error'));
             $bError = true;
         }
         /**
          * Проверка на смену пароля
          */
         if ($sPassword = $this->GetPost('password')) {
             if (($nMinLen = Config::Get('module.security.password_len')) < 3) {
                 $nMinLen = 3;
             }
             if (F::CheckVal($sPassword, 'password', $nMinLen)) {
                 if ($sPassword == $this->GetPost('password_confirm')) {
                     if (E::ModuleSecurity()->CheckSalted($this->oUserCurrent->getPassword(), $this->GetPost('password_now'), 'pass')) {
                         $this->oUserCurrent->setPassword($sPassword, true);
                     } else {
                         $bError = true;
                         E::ModuleMessage()->AddError(E::ModuleLang()->Get('settings_profile_password_current_error'), E::ModuleLang()->Get('error'));
                     }
                 } else {
                     $bError = true;
                     E::ModuleMessage()->AddError(E::ModuleLang()->Get('settings_profile_password_confirm_error'), E::ModuleLang()->Get('error'));
                 }
             } else {
                 $bError = true;
                 E::ModuleMessage()->AddError(E::ModuleLang()->Get('settings_profile_password_new_error', array('num' => $nMinLen)), E::ModuleLang()->Get('error'));
             }
         }
         /**
          * Ставим дату последнего изменения
          */
         $this->oUserCurrent->setProfileDate(F::Now());
         /**
          * Запускаем выполнение хуков
          */
         E::ModuleHook()->Run('settings_account_save_before', array('oUser' => $this->oUserCurrent, 'bError' => &$bError));
         /**
          * Сохраняем изменения
          */
         if (!$bError) {
             if (E::ModuleUser()->Update($this->oUserCurrent)) {
                 E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('settings_account_submit_ok'));
                 /**
                  * Подтверждение смены емайла
                  */
                 if (F::GetRequestStr('mail') && F::GetRequestStr('mail') != $this->oUserCurrent->getMail()) {
                     if ($oChangemail = E::ModuleUser()->MakeUserChangemail($this->oUserCurrent, F::GetRequestStr('mail'))) {
                         if ($oChangemail->getMailFrom()) {
                             E::ModuleMessage()->AddNotice(E::ModuleLang()->Get('settings_profile_mail_change_from_notice'));
                         } else {
                             E::ModuleMessage()->AddNotice(E::ModuleLang()->Get('settings_profile_mail_change_to_notice'));
                         }
                     }
                 }
                 E::ModuleHook()->Run('settings_account_save_after', array('oUser' => $this->oUserCurrent));
             } else {
                 E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'));
             }
         }
     }
 }
 /**
  * Форма смены пароля, емайла
  */
 protected function EventAccount()
 {
     /**
      * Устанавливаем title страницы
      */
     $this->Viewer_AddHtmlTitle($this->Lang_Get('settings_menu_profile'));
     $this->sMenuSubItemSelect = 'account';
     /**
      * Если нажали кнопку "Сохранить"
      */
     if (isPost('submit_account_edit')) {
         $this->Security_ValidateSendForm();
         $bError = false;
         /**
          * Проверка мыла
          */
         if (func_check(getRequestStr('mail'), 'mail')) {
             if ($oUserMail = $this->User_GetUserByMail(getRequestStr('mail')) and $oUserMail->getId() != $this->oUserCurrent->getId()) {
                 $this->Message_AddError($this->Lang_Get('settings_profile_mail_error_used'), $this->Lang_Get('error'));
                 $bError = true;
             }
         } else {
             $this->Message_AddError($this->Lang_Get('settings_profile_mail_error'), $this->Lang_Get('error'));
             $bError = true;
         }
         /**
          * Проверка на смену пароля
          */
         if (getRequestStr('password', '') != '') {
             if (func_check(getRequestStr('password'), 'password', 5)) {
                 if (getRequestStr('password') == getRequestStr('password_confirm')) {
                     if (func_encrypt(getRequestStr('password_now')) == $this->oUserCurrent->getPassword()) {
                         $this->oUserCurrent->setPassword(func_encrypt(getRequestStr('password')));
                     } else {
                         $bError = true;
                         $this->Message_AddError($this->Lang_Get('settings_profile_password_current_error'), $this->Lang_Get('error'));
                     }
                 } else {
                     $bError = true;
                     $this->Message_AddError($this->Lang_Get('settings_profile_password_confirm_error'), $this->Lang_Get('error'));
                 }
             } else {
                 $bError = true;
                 $this->Message_AddError($this->Lang_Get('settings_profile_password_new_error'), $this->Lang_Get('error'));
             }
         }
         /**
          * Ставим дату последнего изменения
          */
         $this->oUserCurrent->setProfileDate(date("Y-m-d H:i:s"));
         /**
          * Запускаем выполнение хуков
          */
         $this->Hook_Run('settings_account_save_before', array('oUser' => $this->oUserCurrent, 'bError' => &$bError));
         /**
          * Сохраняем изменения
          */
         if (!$bError) {
             if ($this->User_Update($this->oUserCurrent)) {
                 $this->Message_AddNoticeSingle($this->Lang_Get('settings_account_submit_ok'));
                 /**
                  * Подтверждение смены емайла
                  */
                 if (getRequestStr('mail') and getRequestStr('mail') != $this->oUserCurrent->getMail()) {
                     if ($oChangemail = $this->User_MakeUserChangemail($this->oUserCurrent, getRequestStr('mail'))) {
                         if ($oChangemail->getMailFrom()) {
                             $this->Message_AddNotice($this->Lang_Get('settings_profile_mail_change_from_notice'));
                         } else {
                             $this->Message_AddNotice($this->Lang_Get('settings_profile_mail_change_to_notice'));
                         }
                     }
                 }
                 $this->Hook_Run('settings_account_save_after', array('oUser' => $this->oUserCurrent));
             } else {
                 $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
             }
         }
     }
 }