Post by Alaque123 » Wed Jul 08, 2020 5:45 pm

SyntaxError: Unexpected token < in JSON at position 0 OK <b>Notice</b>: Undefined index: approved in <b>C: \wampp\htdocs\default2\catalog\controller\extension\quickcheckout\login.php</b> on line <b>35</b>{"error":("warning:"error_approved"}}



I get the following error when logging in during payment. I can't publish my site because of this error






this is my login controller file

Code: Select all


<?php  
class ControllerExtensionQuickCheckoutLogin extends Controller { 
	public function index() {
		$data = $this->load->language('checkout/checkout');
		$data = array_merge($data, $this->load->language('extension/quickcheckout/checkout'));
		
		$data['forgotten'] = $this->url->link('account/forgotten', '', true);
		
		return $this->load->view('extension/quickcheckout/login', $data);
	}
	
	public function validate() {
		$this->load->language('checkout/checkout');
		$this->load->language('extension/quickcheckout/checkout');
		
		$json = array();
		
		if ($this->customer->isLogged()) {
			$json['redirect'] = $this->url->link('extension/quickcheckout/checkout', '', true);			
		}
		
		if (!$json) {
			$this->load->model('account/customer');
			
			// Check how many login attempts have been made.
			$login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);
					
			if ($login_info && ($login_info['total'] > $this->config->get('config_login_attempts')) && strtotime('-1 hour') < strtotime($login_info['date_modified'])) {
				$json['error']['warning'] = $this->language->get('error_attempts');
			}
			
			// Check if customer has been approved.
			$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);

			if ($customer_info && !$customer_info['approved']) {
				$json['error']['warning'] = $this->language->get('error_approved');
			}
			
			if (!$json) {
				if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
					$json['error']['warning'] = $this->language->get('error_login');
					
					$this->model_account_customer->addLoginAttempt($this->request->post['email']);
				} else {
					$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
					
					// Add to activity log
					if ($this->config->get('config_customer_activity')) {
						$this->load->model('account/activity');

						$activity_data = array(
							'customer_id' => $this->customer->getId(),
							'name'        => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
						);

						$this->model_account_activity->addActivity('login', $activity_data);
					}
				}
			}
		}
		
		if (!$json) {
			$json['redirect'] = $this->url->link('extension/quickcheckout/checkout', '', true);
		}
		
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));		
	}
}

Newbie

Posts

Joined
Tue Feb 04, 2020 8:33 am

Post by letxobnav » Wed Jul 08, 2020 6:08 pm

start by stop displaying notices and rely on your error logs for that.
That is an error message complaining about the format (not json) of a php notice which states that the field $customer_info['approved'] is not defined.

Because you display notices, php will produce those and since those are not json encoded, the javascript will produce an alert stating that fact.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by paulfeakins » Thu Jul 09, 2020 5:45 pm

letxobnav wrote:
Wed Jul 08, 2020 6:08 pm
start by stop
Indeed.

But as letxobnav says, turn off Notices and Warnings in PHP. There's plenty on Google about how to do that.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom
Who is online

Users browsing this forum: No registered users and 38 guests