PageRenderTime 57ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/controller/affiliate/forgotten.php

https://bitbucket.org/monobasic/shop.volero.ch
PHP | 121 lines | 93 code | 28 blank | 0 comment | 11 complexity | 225f22ce6e73f1c207a7009fbc0d3719 MD5 | raw file
  1. <?php
  2. class ControllerAffiliateForgotten extends Controller {
  3. private $error = array();
  4. public function index() {
  5. if ($this->affiliate->isLogged()) {
  6. $this->redirect($this->url->link('affiliate/account', '', 'SSL'));
  7. }
  8. $this->language->load('affiliate/forgotten');
  9. $this->document->setTitle($this->language->get('heading_title'));
  10. $this->load->model('affiliate/affiliate');
  11. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  12. $this->language->load('mail/forgotten');
  13. $password = substr(md5(rand()), 0, 7);
  14. $this->model_affiliate_affiliate->editPassword($this->request->post['email'], $password);
  15. $subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));
  16. $message = sprintf($this->language->get('text_greeting'), $this->config->get('config_name')) . "\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->hostname = $this->config->get('config_smtp_host');
  23. $mail->username = $this->config->get('config_smtp_username');
  24. $mail->password = $this->config->get('config_smtp_password');
  25. $mail->port = $this->config->get('config_smtp_port');
  26. $mail->timeout = $this->config->get('config_smtp_timeout');
  27. $mail->setTo($this->request->post['email']);
  28. $mail->setFrom($this->config->get('config_email'));
  29. $mail->setSender($this->config->get('config_name'));
  30. $mail->setSubject($subject);
  31. $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
  32. $mail->send();
  33. $this->session->data['success'] = $this->language->get('text_success');
  34. $this->redirect($this->url->link('affiliate/login', '', 'SSL'));
  35. }
  36. $this->data['breadcrumbs'] = array();
  37. $this->data['breadcrumbs'][] = array(
  38. 'text' => $this->language->get('text_home'),
  39. 'href' => $this->url->link('common/home'),
  40. 'separator' => false
  41. );
  42. $this->data['breadcrumbs'][] = array(
  43. 'text' => $this->language->get('text_account'),
  44. 'href' => $this->url->link('affiliate/account', '', 'SSL'),
  45. 'separator' => $this->language->get('text_separator')
  46. );
  47. $this->data['breadcrumbs'][] = array(
  48. 'text' => $this->language->get('text_forgotten'),
  49. 'href' => $this->url->link('affiliate/forgotten', '', 'SSL'),
  50. 'separator' => $this->language->get('text_separator')
  51. );
  52. $this->data['heading_title'] = $this->language->get('heading_title');
  53. $this->data['text_your_email'] = $this->language->get('text_your_email');
  54. $this->data['text_email'] = $this->language->get('text_email');
  55. $this->data['entry_email'] = $this->language->get('entry_email');
  56. $this->data['button_continue'] = $this->language->get('button_continue');
  57. $this->data['button_back'] = $this->language->get('button_back');
  58. if (isset($this->error['warning'])) {
  59. $this->data['error_warning'] = $this->error['warning'];
  60. } else {
  61. $this->data['error_warning'] = '';
  62. }
  63. $this->data['action'] = $this->url->link('affiliate/forgotten', '', 'SSL');
  64. $this->data['back'] = $this->url->link('affiliate/login', '', 'SSL');
  65. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/affiliate/forgotten.tpl')) {
  66. $this->template = $this->config->get('config_template') . '/template/affiliate/forgotten.tpl';
  67. } else {
  68. $this->template = 'default/template/affiliate/forgotten.tpl';
  69. }
  70. $this->children = array(
  71. 'common/column_left',
  72. 'common/column_right',
  73. 'common/content_top',
  74. 'common/content_bottom',
  75. 'common/footer',
  76. 'common/header'
  77. );
  78. $this->response->setOutput($this->render());
  79. }
  80. private function validate() {
  81. if (!isset($this->request->post['email'])) {
  82. $this->error['warning'] = $this->language->get('error_email');
  83. } elseif (!$this->model_affiliate_affiliate->getTotalAffiliatesByEmail($this->request->post['email'])) {
  84. $this->error['warning'] = $this->language->get('error_email');
  85. }
  86. if (!$this->error) {
  87. return true;
  88. } else {
  89. return false;
  90. }
  91. }
  92. }
  93. ?>