PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/admin/controller/common/reset.php

https://github.com/opencartlite/opencart
PHP | 105 lines | 81 code | 24 blank | 0 comment | 23 complexity | 7533cde813187dd30121e8d630e9f2e7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-3.0
  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 (!$this->config->get('config_password')) {
  9. $this->redirect($this->url->link('common/login', '', 'SSL'));
  10. }
  11. if (isset($this->request->get['code'])) {
  12. $code = $this->request->get['code'];
  13. } else {
  14. $code = '';
  15. }
  16. $this->load->model('user/user');
  17. $user_info = $this->model_user_user->getUserByCode($code);
  18. if ($user_info) {
  19. $this->data += $this->language->load('common/reset');
  20. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  21. $this->model_user_user->editPassword($user_info['user_id'], $this->request->post['password']);
  22. $this->session->data['success'] = $this->language->get('text_success');
  23. $this->redirect($this->url->link('common/login', '', 'SSL'));
  24. }
  25. $this->data['breadcrumbs'] = array();
  26. $this->data['breadcrumbs'][] = array(
  27. 'text' => $this->language->get('text_home'),
  28. 'href' => $this->url->link('common/home')
  29. );
  30. $this->data['breadcrumbs'][] = array(
  31. 'text' => $this->language->get('text_reset'),
  32. 'href' => $this->url->link('common/reset', '', 'SSL')
  33. );
  34. if (isset($this->error['password'])) {
  35. $this->data['error_password'] = $this->error['password'];
  36. } else {
  37. $this->data['error_password'] = '';
  38. }
  39. if (isset($this->error['confirm'])) {
  40. $this->data['error_confirm'] = $this->error['confirm'];
  41. } else {
  42. $this->data['error_confirm'] = '';
  43. }
  44. $this->data['action'] = $this->url->link('common/reset', 'code=' . $code, 'SSL');
  45. $this->data['cancel'] = $this->url->link('common/login', '', 'SSL');
  46. if (isset($this->request->post['password'])) {
  47. $this->data['password'] = $this->request->post['password'];
  48. } else {
  49. $this->data['password'] = '';
  50. }
  51. if (isset($this->request->post['confirm'])) {
  52. $this->data['confirm'] = $this->request->post['confirm'];
  53. } else {
  54. $this->data['confirm'] = '';
  55. }
  56. $this->template = 'common/reset.tpl';
  57. $this->children = array(
  58. 'common/header',
  59. 'common/footer'
  60. );
  61. $this->response->setOutput($this->render());
  62. } else {
  63. $this->model_setting_setting->editSettingValue('config', 'config_password', '0');
  64. return $this->forward('common/login');
  65. }
  66. }
  67. protected function validate() {
  68. if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
  69. $this->error['password'] = $this->language->get('error_password');
  70. }
  71. if ($this->request->post['confirm'] != $this->request->post['password']) {
  72. $this->error['confirm'] = $this->language->get('error_confirm');
  73. }
  74. if (!$this->error) {
  75. return true;
  76. } else {
  77. return false;
  78. }
  79. }
  80. }
  81. ?>