Example #1
0
 protected function password_reset_confirm()
 {
     global $lang, $config;
     if (!$this->is_password_reset_confirm) {
         return $this->account_login_status;
     }
     if ($this->account_login_status != LOGIN_UNDEFINED) {
         return $this->account_login_status;
     }
     // Проверяем поддержку сброса пароля
     if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
         return $this->account_login_status;
     }
     try {
         $code_unsafe = sys_get_param_str_unsafe('password_reset_code');
         if (empty($code_unsafe)) {
             throw new Exception(PASSWORD_RESTORE_ERROR_CODE_EMPTY, ERR_ERROR);
         }
         sn_db_transaction_start();
         $confirmation = $this->confirmation->db_confirmation_get_by_type_and_code(CONFIRM_PASSWORD_RESET, $code_unsafe);
         // OK 4.5
         if (empty($confirmation)) {
             throw new Exception(PASSWORD_RESTORE_ERROR_CODE_WRONG, ERR_ERROR);
         }
         if (SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) {
             throw new Exception(PASSWORD_RESTORE_ERROR_CODE_TOO_OLD, ERR_ERROR);
         }
         unset($this->account);
         $this->account = new Account($this->db);
         if (!$this->account->db_get_by_email($confirmation['email'])) {
             throw new Exception(PASSWORD_RESTORE_ERROR_CODE_OK_BUT_NO_ACCOUNT_FOR_EMAIL, ERR_ERROR);
         }
         $new_password_unsafe = $this->make_random_password();
         $salt_unsafe = $this->password_salt_generate();
         if (!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) {
             // Ошибка смены пароля
             throw new Exception(AUTH_ERROR_INTERNAL_PASSWORD_CHANGE_ON_RESTORE, ERR_ERROR);
         }
         $this->account_login_status = LOGIN_UNDEFINED;
         $this->remember_me = 1;
         $this->cookie_set();
         $this->login_cookie();
         if ($this->account_login_status == LOGIN_SUCCESS) {
             // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!!
             $message_header = sprintf($lang['log_lost_email_title'], $config->game_name);
             $message = sprintf($lang['log_lost_email_pass'], $config->game_name, $this->account->account_name, $new_password_unsafe);
             @($operation_result = mymail($confirmation['email'], $message_header, htmlspecialchars($message)));
             // $users_translated = classSupernova::$auth->db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id); // OK 4.5
             $users_translated = PlayerToAccountTranslate::db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id);
             // OK 4.5
             if (!empty($users_translated)) {
                 // Отправляем в лички письмо о сбросе пароля
                 // ПО ОПРЕДЕЛЕНИЮ в $users_translated только
                 //    - аккаунты, поддерживающие сброс пароля
                 //    - список аккаунтов, имеющих тот же емейл, что указан в Подтверждении
                 //    - игроки, привязанные только к этим аккаунтам
                 // Значит им всем сразу скопом можно отправлять сообщения
                 $message = sprintf($lang['sys_password_reset_message_body'], $new_password_unsafe);
                 $message = sys_bbcodeParse($message) . '<br><br>';
                 // msg_send_simple_message($found_provider->data[F_USER_ID], 0, SN_TIME_NOW, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['sys_login_register_message_title'], $message);
                 foreach ($users_translated as $user_id => $providers_list) {
                     msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['sys_login_register_message_title'], $message);
                 }
             } else {
                 // Фигня - может быть и пустой, если у нас есть только аккаунт, но нет пользователей
                 // throw new Exception(AUTH_PASSWORD_RESET_INSIDE_ERROR_NO_ACCOUNT_FOR_CONFIRMATION, ERR_ERROR);
             }
         }
         $this->confirmation->db_confirmation_delete_by_type_and_email(CONFIRM_PASSWORD_RESET, $confirmation['email']);
         // OK 4.5
         sn_db_transaction_commit();
         sys_redirect('overview.php');
     } catch (Exception $e) {
         sn_db_transaction_rollback();
         $this->account_login_status = $e->getMessage();
     }
     return $this->account_login_status;
 }