1: | <?php
2: | namespace Opencart\Catalog\Controller\Account;
3: | /**
4: | * Class Password
5: | *
6: | * @package Opencart\Catalog\Controller\Account
7: | */
8: | class Password extends \Opencart\System\Engine\Controller {
9: | /**
10: | * @return void
11: | */
12: | public function index(): void {
13: | $this->load->language('account/password');
14: |
15: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
16: | $this->session->data['redirect'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language'));
17: |
18: | $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
19: | }
20: |
21: | $this->document->setTitle($this->language->get('heading_title'));
22: |
23: | $data['breadcrumbs'] = [];
24: |
25: | $data['breadcrumbs'][] = [
26: | 'text' => $this->language->get('text_home'),
27: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
28: | ];
29: |
30: | $data['breadcrumbs'][] = [
31: | 'text' => $this->language->get('text_account'),
32: | 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
33: | ];
34: |
35: | $data['breadcrumbs'][] = [
36: | 'text' => $this->language->get('heading_title'),
37: | 'href' => $this->url->link('account/password', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
38: | ];
39: |
40: | $data['save'] = $this->url->link('account/password.save', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
41: | $data['back'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
42: |
43: | $data['column_left'] = $this->load->controller('common/column_left');
44: | $data['column_right'] = $this->load->controller('common/column_right');
45: | $data['content_top'] = $this->load->controller('common/content_top');
46: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
47: | $data['footer'] = $this->load->controller('common/footer');
48: | $data['header'] = $this->load->controller('common/header');
49: |
50: | $this->response->setOutput($this->load->view('account/password', $data));
51: | }
52: |
53: | /**
54: | * Save
55: | *
56: | * @return void
57: | */
58: | public function save(): void {
59: | $this->load->language('account/password');
60: |
61: | $json = [];
62: |
63: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
64: | $this->session->data['redirect'] = $this->url->link('account/password', 'language=' . $this->config->get('config_language'));
65: |
66: | $json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
67: | }
68: |
69: | if (!$json) {
70: | $keys = [
71: | 'password',
72: | 'confirm'
73: | ];
74: |
75: | foreach ($keys as $key) {
76: | if (!isset($this->request->post[$key])) {
77: | $this->request->post[$key] = '';
78: | }
79: | }
80: |
81: | if ((oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 6) || (oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) {
82: | $json['error']['password'] = $this->language->get('error_password');
83: | }
84: |
85: | if ($this->request->post['confirm'] != $this->request->post['password']) {
86: | $json['error']['confirm'] = $this->language->get('error_confirm');
87: | }
88: | }
89: |
90: | if (!$json) {
91: | $this->load->model('account/customer');
92: |
93: | $this->model_account_customer->editPassword($this->customer->getEmail(), $this->request->post['password']);
94: |
95: | $this->session->data['success'] = $this->language->get('text_success');
96: |
97: | $json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
98: | }
99: |
100: | $this->response->addHeader('Content-Type: application/json');
101: | $this->response->setOutput(json_encode($json));
102: | }
103: | }
104: |

OpenCart API API documentation generated by ApiGen dev-master