blackseabreathe
@blackseabreathe
brackets

Opencart 3 ajax запрос на восстановление пароля?

Пытаюсь отправить Ajax запрос на восстановления пароля.

В catalog/..../view/.../account/fotgotten.twig сделал кнопку <button type="button" id="forgot">send</button>

Тут же Ajax запрос

$(document).on('click', '#forgot', function(){
$.ajax({
url: 'index.php?route=account/forgotten/validate', //отправляем запрос в catalog/controller/account/forgotten.php ф-ию validate, которая protected function - может дело в protected?
type: 'post', //зщые
data: $('#ff input[type=\'text\']'),  //данные
dataType: 'json',  //json
success: function(json) {
if (json['redirect']) {
location = json['redirect']; //если все ок, то направим на страницу входа (или любую другую укажу)
} else if (json['error']) {
if (json['error']['warning']) { 
$.jGrowl(json['error']['warning']); //показ ошибок если есть, а она всего одна может быть - есть ли такой email или нет
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); // ну и Ajax ошбки запроса
}
});
});
});


catalog/controller/account/forgotten

ф-ия validate

protected function validate() {
        
        $json = array(); //создаю массив json
        
		if (!isset($this->request->post['email'])) { //если нет данных
//			$this->error['warning'] = $this->language->get('error_email');  //закомментировал стандартный функционал
            $json['error']['warning'] = $this->language->get('error_email'); //то покажем ошибку
		} elseif (!$this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { //проверка на существование среди email юзеров
            $json['error']['warning'] = $this->language->get('error_email'); // текст ошибки если если false
//			$this->error['warning'] = $this->language->get('error_email'); //закомментировал стандартный функционал
		}
		
		// Check if customer has been approved.
		$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);

		if ($customer_info && !$customer_info['status']) {
            $json['error']['warning'] = $this->language->get('error_approved'); //отдаем текст ошибки
//			$this->error['warning'] = $this->language->get('error_approved'); //закомментировал стандартный функционал
		}
        
        $this->response->addHeader('Content-Type: application/json'); //json
		$this->response->setOutput(json_encode($json)); //json

//		return !$this->error; //закомментировал стандартный функционал
	}


по итогу при запросе получаю такую ошибку

Unrecognized token '<'
parsererror
<b>Warning</b>: call_user_func_array() expects parameter 1 to be a valid callback, cannot access protected method ControllerAccountForgotten::validate() in <b>/home/d/drobenfg/test.domrobensa.ru/storage/modification/system/engine/action.php</b> on line <b>79</b>
  • Вопрос задан
  • 122 просмотра
Пригласить эксперта
Ответы на вопрос 1
blackseabreathe
@blackseabreathe Автор вопроса
brackets
Решено!

Немного поправил ф-ию validate

public function validate() {
        
        $this->load->language('account/forgotten');

		$this->load->model('account/customer');
        
        $json = array();
        
        // Check if customer has been approved.
		$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
        
		if (!isset($this->request->post['email']) || empty($this->request->post['email'])) {
//			$this->error['warning'] = $this->language->get('error_email');
            $json['error']['warning'] = $this->language->get('error_email');
		} elseif (!$this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
            $json['error']['warning'] = $this->language->get('error_email');
//			$this->error['warning'] = $this->language->get('error_email');
		}

		elseif ($customer_info && !$customer_info['status']) {
            $json['error']['warning'] = $this->language->get('error_approved');
//			$this->error['warning'] = $this->language->get('error_approved');
		}
        
        else {
        $json['error']['warning'] = 'Письмо с инструкцией по восстановлению пароля отправлено на введенную почту. Если не пришло в течение 10 минут, проверьте папку спам';
        
        }
        
        
        
        $this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));

//		return !$this->error;
	}


Осталось понять как отправлять само письмо
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы