Issues (2407)

administration/controller/common/reset.php (3 issues)

1
<?php
2
3
/* 	Divine CMS - Open source CMS for widespread use.
4
    Copyright (c) 2019 Mykola Burakov ([email protected])
5
6
    See SOURCE.txt for other and additional information.
7
8
    This file is part of Divine CMS.
9
10
    This program is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    This program is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23
class ControllerCommonReset extends \Divine\Engine\Core\Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    private $error = array();
26
27
    public function index()
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
28
    {
29
        if ($this->user->isLogged() && isset($this->request->get['token']) && ($this->request->get['token'] == $this->session->data['token'])) {
30
            $this->response->redirect($this->url->link('common/dashboard', '', true));
31
        }
32
33
        if (!$this->config->get('config_password')) {
34
            $this->response->redirect($this->url->link('common/login', '', true));
35
        }
36
37
        if (isset($this->request->get['code'])) {
38
            $code = $this->request->get['code'];
39
        } else {
40
            $code = '';
41
        }
42
43
        $this->load->model('user/user');
44
45
        $user_info = $this->model_user_user->getUserByCode($code);
46
47
        if ($user_info) {
48
            $this->load->language('common/reset');
49
50
            $this->document->setTitle($this->language->get('heading_title'));
51
52
            if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
53
                $this->model_user_user->editPassword($user_info['user_id'], $this->request->post['password']);
54
55
                $this->session->data['success'] = $this->language->get('text_success');
56
57
                $this->response->redirect($this->url->link('common/login', '', true));
58
            }
59
60
            $data['heading_title'] = $this->language->get('heading_title');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
61
62
            $data['text_password'] = $this->language->get('text_password');
63
64
            $data['entry_password'] = $this->language->get('entry_password');
65
            $data['entry_confirm'] = $this->language->get('entry_confirm');
66
67
            $data['button_save'] = $this->language->get('button_save');
68
            $data['button_cancel'] = $this->language->get('button_cancel');
69
70
            $data['breadcrumbs'] = array();
71
72
            $data['breadcrumbs'][] = array(
73
                'text' => $this->language->get('text_home'),
74
                'href' => $this->url->link('common/dashboard', '', true)
75
            );
76
77
            $data['breadcrumbs'][] = array(
78
                'text' => $this->language->get('heading_title'),
79
                'href' => $this->url->link('common/reset', '', true)
80
            );
81
82
            if (isset($this->error['password'])) {
83
                $data['error_password'] = $this->error['password'];
84
            } else {
85
                $data['error_password'] = '';
86
            }
87
88
            if (isset($this->error['confirm'])) {
89
                $data['error_confirm'] = $this->error['confirm'];
90
            } else {
91
                $data['error_confirm'] = '';
92
            }
93
94
            $data['action'] = $this->url->link('common/reset', 'code=' . $code, true);
95
96
            $data['cancel'] = $this->url->link('common/login', '', true);
97
98
            if (isset($this->request->post['password'])) {
99
                $data['password'] = $this->request->post['password'];
100
            } else {
101
                $data['password'] = '';
102
            }
103
104
            if (isset($this->request->post['confirm'])) {
105
                $data['confirm'] = $this->request->post['confirm'];
106
            } else {
107
                $data['confirm'] = '';
108
            }
109
110
            $data['header'] = $this->load->controller('common/header');
111
            $data['footer'] = $this->load->controller('common/footer');
112
113
            $this->response->setOutput($this->load->view('common/reset', $data));
114
        } else {
115
            $this->load->model('setting/setting');
116
117
            $this->model_setting_setting->editSettingValue('config', 'config_password', '0');
118
119
            return new \Divine\Engine\Core\Action('common/login');
120
        }
121
    }
122
123
    protected function validate()
124
    {
125
        if ((\voku\helper\UTF8::strlen($this->request->post['password']) < 4) || (\voku\helper\UTF8::strlen($this->request->post['password']) > 20)) {
126
            $this->error['password'] = $this->language->get('error_password');
127
        }
128
129
        if ($this->request->post['confirm'] != $this->request->post['password']) {
130
            $this->error['confirm'] = $this->language->get('error_confirm');
131
        }
132
133
        return !$this->error;
134
    }
135
}
136