Opencart 3 ajax password recovery request?

I'm trying to send an Ajax request for password recovery.

In catalog/..../view/.../account/fotgotten. twig made a button <button type="button" id="forgot">send</button>

Immediately an Ajax request

$(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

F-iy 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; //закомментировал стандартный функционал
  }

As a result, I get the following error when requesting

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>
Author: Michael Miller, 2020-12-18

1 answers

Replace protected function validate() with public function validate() .

 0
Author: Andrew Hobbit, 2020-12-18 17:01:28