PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/controller/common/reset.php

https://bitbucket.org/jjasko/opencart_serbian
PHP | 111 lines | 85 code | 26 blank | 0 comment | 22 complexity | 88c97b5ca30c05514b35f18c2f4cc563 MD5 | raw file
  1. <?php
  2. class ControllerCommonReset extends Controller {
  3. private $error = array();
  4. public function index() {
  5. if ($this->user->isLogged()) {
  6. $this->redirect($this->url->link('common/home', '', 'SSL'));
  7. }
  8. if (isset($this->request->get['code'])) {
  9. $code = $this->request->get['code'];
  10. } else {
  11. $code = '';
  12. }
  13. $this->load->model('user/user');
  14. $user_info = $this->model_user_user->getUserByCode($code);
  15. if ($user_info) {
  16. $this->load->language('common/reset');
  17. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  18. $this->model_user_user->editPassword($user_info['user_id'], $this->request->post['password']);
  19. $this->session->data['success'] = $this->language->get('text_success');
  20. $this->redirect($this->url->link('common/login', '', 'SSL'));
  21. }
  22. $this->data['breadcrumbs'] = array();
  23. $this->data['breadcrumbs'][] = array(
  24. 'text' => $this->language->get('text_home'),
  25. 'href' => $this->url->link('common/home'),
  26. 'separator' => false
  27. );
  28. $this->data['breadcrumbs'][] = array(
  29. 'text' => $this->language->get('text_reset'),
  30. 'href' => $this->url->link('common/reset', '', 'SSL'),
  31. 'separator' => $this->language->get('text_separator')
  32. );
  33. $this->data['heading_title'] = $this->language->get('heading_title');
  34. $this->data['text_password'] = $this->language->get('text_password');
  35. $this->data['entry_password'] = $this->language->get('entry_password');
  36. $this->data['entry_confirm'] = $this->language->get('entry_confirm');
  37. $this->data['button_save'] = $this->language->get('button_save');
  38. $this->data['button_cancel'] = $this->language->get('button_cancel');
  39. if (isset($this->error['password'])) {
  40. $this->data['error_password'] = $this->error['password'];
  41. } else {
  42. $this->data['error_password'] = '';
  43. }
  44. if (isset($this->error['confirm'])) {
  45. $this->data['error_confirm'] = $this->error['confirm'];
  46. } else {
  47. $this->data['error_confirm'] = '';
  48. }
  49. $this->data['action'] = $this->url->link('common/reset', 'code=' . $code, 'SSL');
  50. $this->data['cancel'] = $this->url->link('common/login', '', 'SSL');
  51. if (isset($this->request->post['password'])) {
  52. $this->data['password'] = $this->request->post['password'];
  53. } else {
  54. $this->data['password'] = '';
  55. }
  56. if (isset($this->request->post['confirm'])) {
  57. $this->data['confirm'] = $this->request->post['confirm'];
  58. } else {
  59. $this->data['confirm'] = '';
  60. }
  61. $this->template = 'common/reset.tpl';
  62. $this->children = array(
  63. 'common/header',
  64. 'common/footer'
  65. );
  66. $this->response->setOutput($this->render());
  67. } else {
  68. return $this->forward('common/login');
  69. }
  70. }
  71. private function validate() {
  72. if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
  73. $this->error['password'] = $this->language->get('error_password');
  74. }
  75. if ($this->request->post['confirm'] != $this->request->post['password']) {
  76. $this->error['confirm'] = $this->language->get('error_confirm');
  77. }
  78. if (!$this->error) {
  79. return true;
  80. } else {
  81. return false;
  82. }
  83. }
  84. }
  85. ?>