Guest User

Untitled

a guest
Dec 18th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. <?php
  2. class ControllerAccountForgotten extends Controller {
  3. private $error = array();
  4.  
  5. public function index() {
  6. if ($this->customer->isLogged()) {
  7. $this->response->redirect($this->url->link('account/account', '', 'SSL'));
  8. }
  9.  
  10. $this->load->language('account/forgotten');
  11.  
  12. $this->document->setTitle($this->language->get('heading_title'));
  13.  
  14. $this->load->model('account/customer');
  15.  
  16. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  17. $this->load->language('mail/forgotten');
  18.  
  19. $password = substr(sha1(uniqid(mt_rand(), true)), 0, 10);
  20.  
  21. $this->model_account_customer->editPassword($this->request->post['email'], $password);
  22.  
  23. $subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));
  24. $message = sprintf($this->language->get('text_greeting'), $this->config->get('config_name')) . "\n\n";
  25. $teste = "<div style='background: #000;' class='teste'>" . $this->language->get('teste') . "<div>";
  26. $message .= $this->language->get('text_password') . "\n\n";
  27. $message .= $password;
  28. $message .= "";
  29.  
  30. $mail = new Mail($this->config->get('config_mail'));
  31. $mail->setTo($this->request->post['email']);
  32. $mail->setFrom($this->config->get('config_email'));
  33. $mail->setSender($this->config->get('config_name'));
  34. $mail->setSubject($subject);
  35. $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
  36. $mail->send();
  37.  
  38. $this->session->data['success'] = $this->language->get('text_success');
  39.  
  40. // Add to activity log
  41. $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
  42.  
  43. if ($customer_info) {
  44. $this->load->model('account/activity');
  45.  
  46. $activity_data = array(
  47. 'customer_id' => $customer_info['customer_id'],
  48. 'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
  49. );
  50.  
  51. $this->model_account_activity->addActivity('forgotten', $activity_data);
  52. }
  53.  
  54. $this->response->redirect($this->url->link('account/login', '', 'SSL'));
  55. }
  56.  
  57. $data['breadcrumbs'] = array();
  58.  
  59. $data['breadcrumbs'][] = array(
  60. 'text' => $this->language->get('text_home'),
  61. 'href' => $this->url->link('common/home')
  62. );
  63.  
  64. $data['breadcrumbs'][] = array(
  65. 'text' => $this->language->get('text_account'),
  66. 'href' => $this->url->link('account/account', '', 'SSL')
  67. );
  68.  
  69. $data['breadcrumbs'][] = array(
  70. 'text' => $this->language->get('text_forgotten'),
  71. 'href' => $this->url->link('account/forgotten', '', 'SSL')
  72. );
  73.  
  74. $data['heading_title'] = $this->language->get('heading_title');
  75.  
  76. $data['text_your_email'] = $this->language->get('text_your_email');
  77. $data['text_email'] = $this->language->get('text_email');
  78.  
  79. $data['entry_email'] = $this->language->get('entry_email');
  80.  
  81. $data['button_continue'] = $this->language->get('button_continue');
  82. $data['button_back'] = $this->language->get('button_back');
  83.  
  84. if (isset($this->error['warning'])) {
  85. $data['error_warning'] = $this->error['warning'];
  86. } else {
  87. $data['error_warning'] = '';
  88. }
  89.  
  90. $data['action'] = $this->url->link('account/forgotten', '', 'SSL');
  91.  
  92. $data['back'] = $this->url->link('account/login', '', 'SSL');
  93.  
  94. $data['column_left'] = $this->load->controller('common/column_left');
  95. $data['column_right'] = $this->load->controller('common/column_right');
  96. $data['content_top'] = $this->load->controller('common/content_top');
  97. $data['content_bottom'] = $this->load->controller('common/content_bottom');
  98. $data['footer'] = $this->load->controller('common/footer');
  99. $data['header'] = $this->load->controller('common/header');
  100.  
  101. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/forgotten.tpl')) {
  102. $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/forgotten.tpl', $data));
  103. } else {
  104. $this->response->setOutput($this->load->view('default/template/account/forgotten.tpl', $data));
  105. }
  106. }
  107.  
  108. protected function validate() {
  109. if (!isset($this->request->post['email'])) {
  110. $this->error['warning'] = $this->language->get('error_email');
  111. } elseif (!$this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
  112. $this->error['warning'] = $this->language->get('error_email');
  113. }
  114.  
  115. return !$this->error;
  116. }
  117. }
Add Comment
Please, Sign In to add comment