public function verification() { // Redirect if user is not logged if (!$this->auth->isLogged()) { $this->response->redirect($this->url->link('account/account/login', 'redirect=' . base64_encode($this->url->getCurrentLink()))); } // Redirect if user is already verified if ($this->auth->isVerified()) { $this->response->redirect($this->url->link('account/account')); } $this->document->setTitle(tt('Account verification')); $data = array(); $code = md5(PROJECT_NAME . $this->auth->getId()); // Create a new BitCoin Address try { $bitcoin = new BitCoin(BITCOIN_RPC_USERNAME, BITCOIN_RPC_PASSWORD, BITCOIN_RPC_HOST, BITCOIN_RPC_PORT); $address = $bitcoin->getaccountaddress(BITCOIN_USER_VERIFICATION_PREFIX . $this->auth->getId()); } catch (Exception $e) { $this->security_log->write('BitCoin connection error ' . $e->error); exit; } if ('POST' == $this->request->getRequestMethod() && $this->_validateVerification()) { // Save verification request into the DB if ($this->model_account_user->addVerificationRequest($this->auth->getId(), $this->currency->getId(), FEE_USER_VERIFICATION, 'pending', $code, $this->request->post['proof'])) { // Add notification $this->model_account_notification->addNotification($this->auth->getId(), DEFAULT_LANGUAGE_ID, 'common', tt('Your verification request was sent successfully'), tt('We will process the request as quickly as possible.')); // Admin alert $this->mail->setTo(MAIL_EMAIL_SUPPORT_ADDRESS); $this->mail->setSubject(sprintf(tt('Account Verification Request - %s'), PROJECT_NAME)); $this->mail->setText(tt('A new verification was requested.')); $this->mail->send(); // Success message $this->session->setUserMessage(array('success' => tt('Your verification request was sent successfully!'))); } } $data['error'] = $this->_error; $data['action'] = $this->url->link('account/account/verification'); $data['proof'] = isset($this->request->post['proof']) ? $this->request->post['proof'] : false; $data['accept_1'] = isset($this->request->post['accept_1']) ? $this->request->post['accept_1'] : false; $data['accept_2'] = isset($this->request->post['accept_2']) ? $this->request->post['accept_2'] : false; // Step 1 $data['payment_instruction'] = sprintf(tt('Send exactly %s to this address:'), $this->currency->format(FEE_USER_VERIFICATION)); $data['payment_address'] = $address; $data['payment_qr_href'] = $this->url->link('common/image/qr', 'code=' . $address); $data['payment_wallet_href'] = sprintf('bitcoin:%s?amount=%s&label=%s Verification Request for Account ID %s', $address, FEE_USER_VERIFICATION, PROJECT_NAME, $this->auth->getId()); // Step 3 $data['confirmation_code'] = $code; $data['href_cancel'] = $this->url->link('account/account'); $data['footer'] = $this->load->controller('common/footer'); $data['header'] = $this->load->controller('common/header'); $data['alert_danger'] = $this->load->controller('common/alert/danger'); $data['alert_success'] = $this->load->controller('common/alert/success'); $data['alert_warning'] = $this->load->controller('common/alert/warning'); $data['module_account'] = $this->load->controller('module/account'); $data['module_breadcrumbs'] = $this->load->controller('module/breadcrumbs', array(array('name' => tt('Home'), 'href' => $this->url->link('common/home'), 'active' => false), array('name' => tt('Account'), 'href' => $this->url->link('account/account'), 'active' => false), array('name' => tt('Verification'), 'href' => $this->url->link('account/account/verification'), 'active' => true))); // Renter the template $this->response->setOutput($this->load->view('account/account/verification.tpl', $data)); }
public function create() { // Only for logged users if (!$this->auth->isLogged()) { $this->security_log->write('Try to order product from guest request'); exit; } // Check request if (!$this->request->isAjax()) { $this->security_log->write('Try to order product without ajax request'); exit; } // Check dependencies if (!isset($this->request->post['product_id'])) { $this->security_log->write('Try to order product without product_id parameter'); exit; } // Check dependencies if (!isset($this->request->post['license']) || !in_array($this->request->post['license'], array('regular', 'exclusive'))) { $this->security_log->write('Try to order product without license parameter'); exit; } // Try to get product if (!($product_info = $this->model_catalog_product->getProduct((int) $this->request->post['product_id'], $this->auth->getId(), ORDER_APPROVED_STATUS_ID))) { $this->security_log->write('Try to order not exists product'); exit; } // Try to get denied product if (!$product_info->status) { $this->security_log->write('Try to order product ' . (int) $this->request->post['product_id'] . ' with status ' . $product_info->status); exit; } // Check if product already ordered if ($product_info->order_status_id == ORDER_APPROVED_STATUS_ID) { $this->security_log->write('Try to order ordered product'); exit; } // Check if order self product if ($product_info->user_id == $this->auth->getId()) { $this->security_log->write('Try to order self product'); exit; } // Check regular price if ($this->request->post['license'] == 'regular' && ($product_info->regular_price > 0 || $product_info->special_regular_price > 0)) { $amount = (double) $product_info->special_regular_price > 0 ? $product_info->special_regular_price : $product_info->regular_price; // Check exclusive price } else { if ($this->request->post['license'] == 'exclusive' && ($product_info->exclusive_price > 0 || $product_info->special_exclusive_price > 0)) { $amount = (double) $product_info->special_exclusive_price > 0 ? $product_info->special_exclusive_price : $product_info->exclusive_price; // License parameter error } else { $this->security_log->write('Try to purchase product by undefined license'); exit; } } // Init variables $json = array('status' => false); // Create a new order in DB if (!($order_id = $this->model_common_order->createOrder($this->auth->getId(), $product_info->product_id, $this->request->post['license'], $amount, FEE_PER_ORDER, ORDER_PENDING_STATUS_ID, DEFAULT_CURRENCY_ID))) { $this->security_log->write('Can not create the order'); exit; } // Create a new BitCoin Address try { $bitcoin = new BitCoin(BITCOIN_RPC_USERNAME, BITCOIN_RPC_PASSWORD, BITCOIN_RPC_HOST, BITCOIN_RPC_PORT); // Set response if (false !== $bitcoin->status && ($address = $bitcoin->getaccountaddress(BITCOIN_ORDER_PREFIX . $order_id))) { $json = array('status' => true, 'address' => $address, 'text' => sprintf(tt('Send exactly %s to this address:'), $this->currency->format($amount)), 'href' => 'bitcoin:' . $address . '?amount=' . $amount . '&label=' . PROJECT_NAME . ' Order #' . $order_id, 'src' => $this->url->link('common/image/qr', 'code=' . $address)); } } catch (Exception $e) { $this->security_log->write($bitcoin->error . '/' . $e->getMessage()); } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); }