ControllerAccountReset   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 66
c 0
b 0
f 0
dl 0
loc 116
rs 10
wmc 14

2 Methods

Rating   Name   Duplication   Size   Complexity  
C index() 0 98 10
A validate() 0 11 4
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 ControllerAccountReset 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
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
28
    {
29
        if ($this->customer->isLogged()) {
30
            $this->response->redirect($this->url->link('account/account', '', true));
31
        }
32
33
        if (isset($this->request->get['code'])) {
34
            $code = $this->request->get['code'];
35
        } else {
36
            $code = '';
37
        }
38
39
        $this->load->model('account/customer');
40
41
        $customer_info = $this->model_account_customer->getCustomerByCode($code);
42
43
        if ($customer_info) {
44
            $this->load->language('account/reset');
45
46
            $this->document->setTitle($this->language->get('heading_title'));
47
48
            if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
49
                $this->model_account_customer->editPassword($customer_info['email'], $this->request->post['password']);
50
51
                $this->session->data['success'] = $this->language->get('text_success');
52
53
                $this->response->redirect($this->url->link('account/login', '', true));
54
            }
55
56
            $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...
57
58
            $data['text_password'] = $this->language->get('text_password');
59
60
            $data['entry_password'] = $this->language->get('entry_password');
61
            $data['entry_confirm'] = $this->language->get('entry_confirm');
62
63
            $data['button_continue'] = $this->language->get('button_continue');
64
            $data['button_back'] = $this->language->get('button_back');
65
66
            $data['breadcrumbs'] = array();
67
68
            $data['breadcrumbs'][] = array(
69
                'text' => $this->language->get('text_home'),
70
                'href' => $this->url->link('common/home')
71
            );
72
73
            $data['breadcrumbs'][] = array(
74
                'text' => $this->language->get('text_account'),
75
                'href' => $this->url->link('account/account', '', true)
76
            );
77
78
            $data['breadcrumbs'][] = array(
79
                'text' => $this->language->get('heading_title'),
80
                'href' => $this->url->link('account/reset', '', true)
81
            );
82
83
            if (isset($this->error['password'])) {
84
                $data['error_password'] = $this->error['password'];
85
            } else {
86
                $data['error_password'] = '';
87
            }
88
89
            if (isset($this->error['confirm'])) {
90
                $data['error_confirm'] = $this->error['confirm'];
91
            } else {
92
                $data['error_confirm'] = '';
93
            }
94
95
            $data['action'] = $this->url->link('account/reset', 'code=' . $code, true);
96
97
            $data['back'] = $this->url->link('account/login', '', true);
98
99
            if (isset($this->request->post['password'])) {
100
                $data['password'] = $this->request->post['password'];
101
            } else {
102
                $data['password'] = '';
103
            }
104
105
            if (isset($this->request->post['confirm'])) {
106
                $data['confirm'] = $this->request->post['confirm'];
107
            } else {
108
                $data['confirm'] = '';
109
            }
110
111
            $data['column'] = $this->load->controller('common/column');
112
            
113
            $data['content_top'] = $this->load->controller('common/content_top');
114
            $data['content_bottom'] = $this->load->controller('common/content_bottom');
115
            $data['footer'] = $this->load->controller('common/footer');
116
            $data['header'] = $this->load->controller('common/header');
117
118
            $this->response->setOutput($this->load->view('account/reset', $data));
119
        } else {
120
            $this->load->language('account/reset');
121
122
            $this->session->data['error'] = $this->language->get('error_code');
123
124
            return new \Divine\Engine\Core\Action('account/login');
125
        }
126
    }
127
128
    protected function validate()
129
    {
130
        if ((\voku\helper\UTF8::strlen($this->request->post['password']) < 4) || (\voku\helper\UTF8::strlen($this->request->post['password']) > 20)) {
131
            $this->error['password'] = $this->language->get('error_password');
132
        }
133
134
        if ($this->request->post['confirm'] != $this->request->post['password']) {
135
            $this->error['confirm'] = $this->language->get('error_confirm');
136
        }
137
138
        return !$this->error;
139
    }
140
}
141