PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/catalog/controller/account/forgotten.php

https://gitlab.com/firstrate/firstrate
PHP | 130 lines | 95 code | 34 blank | 1 comment | 12 complexity | 050d68498c9ddd884d6cb8b81787b57d MD5 | raw file
  1. <?php
  2. class ControllerAccountForgotten extends Controller {
  3. private $error = array();
  4. public function index() {
  5. if ($this->customer->isLogged()) {
  6. $this->response->redirect($this->url->link('account/account', '', 'SSL'));
  7. }
  8. $this->language->load('account/forgotten');
  9. $this->document->setTitle($this->language->get('heading_title'));
  10. $this->load->model('account/customer');
  11. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  12. $this->load->language('mail/forgotten');
  13. $password = substr(sha1(uniqid(mt_rand(), true)), 0, 10);
  14. $this->model_account_customer->editPassword($this->request->post['email'], $password);
  15. $subject = sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
  16. $message = sprintf($this->language->get('text_greeting'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')) . "\n\n";
  17. $message .= $this->language->get('text_password') . "\n\n";
  18. $message .= $password;
  19. $mail = new Mail();
  20. $mail->protocol = $this->config->get('config_mail_protocol');
  21. $mail->parameter = $this->config->get('config_mail_parameter');
  22. $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
  23. $mail->smtp_username = $this->config->get('config_mail_smtp_username');
  24. $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
  25. $mail->smtp_port = $this->config->get('config_mail_smtp_port');
  26. $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
  27. $mail->setTo($this->request->post['email']);
  28. $mail->setFrom($this->config->get('config_email'));
  29. $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
  30. $mail->setSubject($subject);
  31. $mail->setText($message);
  32. $mail->send();
  33. $this->session->data['success'] = $this->language->get('text_success');
  34. // Add to activity log
  35. $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
  36. if ($customer_info) {
  37. $this->load->model('account/activity');
  38. $activity_data = array(
  39. 'customer_id' => $customer_info['customer_id'],
  40. 'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
  41. );
  42. $this->model_account_activity->addActivity('forgotten', $activity_data);
  43. }
  44. $this->response->redirect($this->url->link('account/login', '', 'SSL'));
  45. }
  46. $data['breadcrumbs'] = array();
  47. $data['breadcrumbs'][] = array(
  48. 'text' => $this->language->get('text_home'),
  49. 'href' => $this->url->link('common/home')
  50. );
  51. $data['breadcrumbs'][] = array(
  52. 'text' => $this->language->get('text_account'),
  53. 'href' => $this->url->link('account/account', '', 'SSL')
  54. );
  55. $data['breadcrumbs'][] = array(
  56. 'text' => $this->language->get('text_forgotten'),
  57. 'href' => $this->url->link('account/forgotten', '', 'SSL')
  58. );
  59. $data['heading_title'] = $this->language->get('heading_title');
  60. $data['text_your_email'] = $this->language->get('text_your_email');
  61. $data['text_email'] = $this->language->get('text_email');
  62. $data['entry_email'] = $this->language->get('entry_email');
  63. $data['button_continue'] = $this->language->get('button_continue');
  64. $data['button_back'] = $this->language->get('button_back');
  65. if (isset($this->error['warning'])) {
  66. $data['error_warning'] = $this->error['warning'];
  67. } else {
  68. $data['error_warning'] = '';
  69. }
  70. $data['action'] = $this->url->link('account/forgotten', '', 'SSL');
  71. $data['back'] = $this->url->link('account/login', '', 'SSL');
  72. $data['column_left'] = $this->load->controller('common/column_left');
  73. $data['column_right'] = $this->load->controller('common/column_right');
  74. $data['content_top'] = $this->load->controller('common/content_top');
  75. $data['content_bottom'] = $this->load->controller('common/content_bottom');
  76. $data['footer'] = $this->load->controller('common/footer');
  77. $data['header'] = $this->load->controller('common/header');
  78. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/forgotten.tpl')) {
  79. $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/forgotten.tpl', $data));
  80. } else {
  81. $this->response->setOutput($this->load->view('default/template/account/forgotten.tpl', $data));
  82. }
  83. }
  84. protected function validate() {
  85. if (!isset($this->request->post['email'])) {
  86. $this->error['warning'] = $this->language->get('error_email');
  87. } elseif (!$this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
  88. $this->error['warning'] = $this->language->get('error_email');
  89. }
  90. $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
  91. if ($customer_info && !$customer_info['approved']) {
  92. $this->error['warning'] = $this->language->get('error_approved');
  93. }
  94. return !$this->error;
  95. }
  96. }