1: | <?php
2: | namespace Opencart\Catalog\Controller\Account;
3: | /**
4: | * Class Forgotten
5: | *
6: | * @package Opencart\Catalog\Controller\Account
7: | */
8: | class Forgotten extends \Opencart\System\Engine\Controller {
9: | /**
10: | * @return void
11: | */
12: | public function index(): void {
13: | $this->load->language('account/forgotten');
14: |
15: | if ($this->customer->isLogged()) {
16: | $this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true));
17: | }
18: |
19: | $this->document->setTitle($this->language->get('heading_title'));
20: |
21: | $data['breadcrumbs'] = [];
22: |
23: | $data['breadcrumbs'][] = [
24: | 'text' => $this->language->get('text_home'),
25: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
26: | ];
27: |
28: | $data['breadcrumbs'][] = [
29: | 'text' => $this->language->get('text_account'),
30: | 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
31: | ];
32: |
33: | $data['breadcrumbs'][] = [
34: | 'text' => $this->language->get('text_forgotten'),
35: | 'href' => $this->url->link('account/forgotten', 'language=' . $this->config->get('config_language'))
36: | ];
37: |
38: | $data['confirm'] = $this->url->link('account/forgotten.confirm', 'language=' . $this->config->get('config_language'));
39: |
40: | $data['back'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'));
41: |
42: | $data['column_left'] = $this->load->controller('common/column_left');
43: | $data['column_right'] = $this->load->controller('common/column_right');
44: | $data['content_top'] = $this->load->controller('common/content_top');
45: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
46: | $data['footer'] = $this->load->controller('common/footer');
47: | $data['header'] = $this->load->controller('common/header');
48: |
49: | $this->response->setOutput($this->load->view('account/forgotten', $data));
50: | }
51: |
52: | /**
53: | * Confirm
54: | *
55: | * @return void
56: | */
57: | public function confirm(): void {
58: | $this->load->language('account/forgotten');
59: |
60: | $json = [];
61: |
62: | if ($this->customer->isLogged()) {
63: | $json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
64: | }
65: |
66: | if (!$json) {
67: | $keys = ['email'];
68: |
69: | foreach ($keys as $key) {
70: | if (!isset($this->request->post[$key])) {
71: | $this->request->post[$key] = '';
72: | }
73: | }
74: |
75: | $this->load->model('account/customer');
76: |
77: | $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
78: |
79: | if (!$customer_info) {
80: | $json['error'] = $this->language->get('error_not_found');
81: | }
82: | }
83: |
84: | if (!$json) {
85: | $this->model_account_customer->editCode($this->request->post['email'], oc_token(40));
86: |
87: | $this->session->data['success'] = $this->language->get('text_success');
88: |
89: | $json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
90: | }
91: |
92: | $this->response->addHeader('Content-Type: application/json');
93: | $this->response->setOutput(json_encode($json));
94: | }
95: |
96: | /**
97: | * Reset
98: | *
99: | * @return void
100: | */
101: | public function reset(): void {
102: | $this->load->language('account/forgotten');
103: |
104: | if (isset($this->request->get['email'])) {
105: | $email = (string)$this->request->get['email'];
106: | } else {
107: | $email = '';
108: | }
109: |
110: | if (isset($this->request->get['code'])) {
111: | $code = (string)$this->request->get['code'];
112: | } else {
113: | $code = '';
114: | }
115: |
116: | if ($this->customer->isLogged()) {
117: | $this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true));
118: | }
119: |
120: | $this->load->model('account/customer');
121: |
122: | $customer_info = $this->model_account_customer->getCustomerByEmail($email);
123: |
124: | if (!$customer_info || !$customer_info['code'] || $customer_info['code'] !== $code) {
125: | $this->model_account_customer->editCode($email, '');
126: |
127: | $this->session->data['error'] = $this->language->get('error_code');
128: |
129: | $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
130: | }
131: |
132: | $this->document->setTitle($this->language->get('heading_reset'));
133: |
134: | $data['breadcrumbs'] = [];
135: |
136: | $data['breadcrumbs'][] = [
137: | 'text' => $this->language->get('text_home'),
138: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
139: | ];
140: |
141: | $data['breadcrumbs'][] = [
142: | 'text' => $this->language->get('text_account'),
143: | 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
144: | ];
145: |
146: | $data['breadcrumbs'][] = [
147: | 'text' => $this->language->get('heading_title'),
148: | 'href' => $this->url->link('account/forgotten.reset', 'language=' . $this->config->get('config_language'))
149: | ];
150: |
151: | $this->session->data['reset_token'] = oc_token(26);
152: |
153: | $data['save'] = $this->url->link('account/forgotten.password', 'language=' . $this->config->get('config_language') . '&email=' . urlencode($email) . '&code=' . $code . '&reset_token=' . $this->session->data['reset_token']);
154: | $data['back'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'));
155: |
156: | $data['column_left'] = $this->load->controller('common/column_left');
157: | $data['column_right'] = $this->load->controller('common/column_right');
158: | $data['content_top'] = $this->load->controller('common/content_top');
159: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
160: | $data['footer'] = $this->load->controller('common/footer');
161: | $data['header'] = $this->load->controller('common/header');
162: |
163: | $this->response->setOutput($this->load->view('account/forgotten_reset', $data));
164: | }
165: |
166: | /**
167: | * Password
168: | *
169: | * @return void
170: | */
171: | public function password(): void {
172: | $this->load->language('account/forgotten');
173: |
174: | $json = [];
175: |
176: | if (isset($this->request->get['email'])) {
177: | $email = (string)$this->request->get['email'];
178: | } else {
179: | $email = '';
180: | }
181: |
182: | if (isset($this->request->get['code'])) {
183: | $code = (string)$this->request->get['code'];
184: | } else {
185: | $code = '';
186: | }
187: |
188: | if ($this->customer->isLogged()) {
189: | $json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
190: | }
191: |
192: | if (!isset($this->request->get['reset_token']) || !isset($this->session->data['reset_token']) || ($this->request->get['reset_token'] != $this->session->data['reset_token'])) {
193: | $this->session->data['error'] = $this->language->get('error_session');
194: |
195: | $json['redirect'] = $this->url->link('account/forgotten', 'language=' . $this->config->get('config_language'), true);
196: | }
197: |
198: | $this->load->model('account/customer');
199: |
200: | $customer_info = $this->model_account_customer->getCustomerByEmail($email);
201: |
202: | if (!$customer_info || !$customer_info['code'] || $customer_info['code'] !== $code) {
203: | // Reset token
204: | $this->model_account_customer->editCode($email, '');
205: |
206: | $this->session->data['error'] = $this->language->get('error_code');
207: |
208: | $json['redirect'] = $this->url->link('account/forgotten', 'language=' . $this->config->get('config_language'), true);
209: | }
210: |
211: | if (!$json) {
212: | $keys = [
213: | 'password',
214: | 'confirm'
215: | ];
216: |
217: | foreach ($keys as $key) {
218: | if (!isset($this->request->post[$key])) {
219: | $this->request->post[$key] = '';
220: | }
221: | }
222: |
223: | 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)) {
224: | $json['error']['password'] = $this->language->get('error_password');
225: | }
226: |
227: | if ($this->request->post['confirm'] != $this->request->post['password']) {
228: | $json['error']['confirm'] = $this->language->get('error_confirm');
229: | }
230: | }
231: |
232: | if (!$json) {
233: | $this->model_account_customer->editPassword($customer_info['email'], $this->request->post['password']);
234: |
235: | $this->session->data['success'] = $this->language->get('text_success');
236: |
237: | unset($this->session->data['reset_token']);
238: |
239: | $json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
240: | }
241: |
242: | $this->response->addHeader('Content-Type: application/json');
243: | $this->response->setOutput(json_encode($json));
244: | }
245: | }
246: |

OpenCart API API documentation generated by ApiGen dev-master