shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

login.php (3331B)


      1 <?php
      2 class ControllerCheckoutLogin extends Controller {
      3 	public function index() {
      4 		$this->load->language('checkout/checkout');
      5 
      6 		$data['checkout_guest'] = ($this->config->get('config_checkout_guest') && !$this->config->get('config_customer_price') && !$this->cart->hasDownload());
      7 
      8 		if (isset($this->session->data['account'])) {
      9 			$data['account'] = $this->session->data['account'];
     10 		} else {
     11 			$data['account'] = 'register';
     12 		}
     13 
     14 		$data['forgotten'] = $this->url->link('account/forgotten', '', true);
     15 
     16 		$this->response->setOutput($this->load->view('checkout/login', $data));
     17 	}
     18 
     19 	public function save() {
     20 		$this->load->language('checkout/checkout');
     21 
     22 		$json = array();
     23 
     24 		if ($this->customer->isLogged()) {
     25 			$json['redirect'] = $this->url->link('checkout/checkout', '', true);
     26 		}
     27 
     28 		if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
     29 			$json['redirect'] = $this->url->link('checkout/cart');
     30 		}
     31 
     32 		if (!$json) {
     33 			$this->load->model('account/customer');
     34 
     35 			// Check how many login attempts have been made.
     36 			$login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);
     37 
     38 			if ($login_info && ($login_info['total'] >= $this->config->get('config_login_attempts')) && strtotime('-1 hour') < strtotime($login_info['date_modified'])) {
     39 				$json['error']['warning'] = $this->language->get('error_attempts');
     40 			}
     41 
     42 			// Check if customer has been approved.
     43 			$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
     44 
     45 			if ($customer_info && !$customer_info['status']) {
     46 				$json['error']['warning'] = $this->language->get('error_approved');
     47 			}
     48 
     49 			if (!isset($json['error'])) {
     50 				if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
     51 					$json['error']['warning'] = $this->language->get('error_login');
     52 
     53 					$this->model_account_customer->addLoginAttempt($this->request->post['email']);
     54 				} else {
     55 					$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
     56 				}
     57 			}
     58 		}
     59 
     60 		if (!$json) {
     61 			// Unset guest
     62 			unset($this->session->data['guest']);
     63 
     64 			// Default Shipping Address
     65 			$this->load->model('account/address');
     66 
     67 			if ($this->config->get('config_tax_customer') == 'payment') {
     68 				$this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
     69 			}
     70 
     71 			if ($this->config->get('config_tax_customer') == 'shipping') {
     72 				$this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
     73 			}
     74 
     75 			// Wishlist
     76 			if (isset($this->session->data['wishlist']) && is_array($this->session->data['wishlist'])) {
     77 				$this->load->model('account/wishlist');
     78 
     79 				foreach ($this->session->data['wishlist'] as $key => $product_id) {
     80 					$this->model_account_wishlist->addWishlist($product_id);
     81 
     82 					unset($this->session->data['wishlist'][$key]);
     83 				}
     84 			}
     85 
     86 			$json['redirect'] = $this->url->link('checkout/checkout', '', true);
     87 		}
     88 
     89 		$this->response->addHeader('Content-Type: application/json');
     90 		$this->response->setOutput(json_encode($json));
     91 	}
     92 }