1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
//------------------------------------------------------------------------------ |
4
|
|
|
// |
5
|
|
|
// eTraxis - Records tracking web-based system |
6
|
|
|
// Copyright (C) 2005-2011 Artem Rodygin |
7
|
|
|
// |
8
|
|
|
// This program is free software: you can redistribute it and/or modify |
9
|
|
|
// it under the terms of the GNU General Public License as published by |
10
|
|
|
// the Free Software Foundation, either version 3 of the License, or |
11
|
|
|
// (at your option) any later version. |
12
|
|
|
// |
13
|
|
|
// This program is distributed in the hope that it will be useful, |
14
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
// GNU General Public License for more details. |
17
|
|
|
// |
18
|
|
|
// You should have received a copy of the GNU General Public License |
19
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
// |
21
|
|
|
//------------------------------------------------------------------------------ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @package eTraxis |
25
|
|
|
* @ignore |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/**#@+ |
29
|
|
|
* Dependency. |
30
|
|
|
*/ |
31
|
|
|
require_once('../engine/engine.php'); |
32
|
|
|
require_once('../dbo/accounts.php'); |
33
|
|
|
/**#@-*/ |
34
|
|
|
|
35
|
|
|
init_page(LOAD_TAB); |
36
|
|
|
|
37
|
|
|
if ($_SESSION[VAR_LDAPUSER]) |
38
|
|
|
{ |
39
|
|
|
debug_write_log(DEBUG_NOTICE, 'LDAP user cannot change a password.'); |
40
|
|
|
exit; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$error = NO_ERROR; |
44
|
|
|
|
45
|
|
|
// settings form is submitted |
46
|
|
|
|
47
|
|
|
if (try_request('submitted') == 'passwordform') |
48
|
|
|
{ |
49
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are submitted.'); |
50
|
|
|
|
51
|
|
|
$password1 = ustrcut($_REQUEST['password1'], MAX_ACCOUNT_PASSWORD); |
52
|
|
|
$password2 = ustrcut($_REQUEST['password2'], MAX_ACCOUNT_PASSWORD); |
53
|
|
|
|
54
|
|
|
$error = password_validate($password1, $password2); |
55
|
|
|
|
56
|
|
|
if ($error == NO_ERROR) |
57
|
|
|
{ |
58
|
|
|
$error = password_change($_SESSION[VAR_USERID], $password1); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
switch ($error) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
case NO_ERROR: |
64
|
|
|
header('HTTP/1.0 200 OK'); |
65
|
|
|
break; |
66
|
|
|
|
67
|
|
|
case ERROR_INCOMPLETE_FORM: |
68
|
|
|
send_http_error(get_html_resource(RES_ALERT_REQUIRED_ARE_EMPTY_ID)); |
69
|
|
|
break; |
70
|
|
|
|
71
|
|
|
case ERROR_PASSWORDS_DO_NOT_MATCH: |
72
|
|
|
send_http_error(get_html_resource(RES_ALERT_PASSWORDS_DO_NOT_MATCH_ID)); |
73
|
|
|
break; |
74
|
|
|
|
75
|
|
|
case ERROR_PASSWORD_TOO_SHORT: |
76
|
|
|
send_http_error(ustrprocess(get_html_resource(RES_ALERT_PASSWORD_TOO_SHORT_ID), MIN_PASSWORD_LENGTH)); |
77
|
|
|
break; |
78
|
|
|
|
79
|
|
|
default: |
80
|
|
|
send_http_error(get_html_resource(RES_ALERT_UNKNOWN_ERROR_ID)); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
exit; |
84
|
|
|
} |
85
|
|
|
else |
86
|
|
|
{ |
87
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are being requested.'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// local JS functions |
91
|
|
|
|
92
|
|
|
$resTitle = get_js_resource(RES_SETTINGS_ID); |
93
|
|
|
$resError = get_js_resource(RES_ERROR_ID); |
94
|
|
|
$resMessage = get_js_resource(RES_ALERT_SUCCESSFULLY_SAVED_ID); |
95
|
|
|
$resOK = get_js_resource(RES_OK_ID); |
96
|
|
|
|
97
|
|
|
$uri = ustr2html(try_cookie(COOKIE_URI, '../settings/index.php')); |
98
|
|
|
clear_cookie(COOKIE_URI); |
99
|
|
|
|
100
|
|
|
$xml = <<<JQUERY |
101
|
|
|
<script> |
102
|
|
|
|
103
|
|
|
function passwordRefresh () |
104
|
|
|
{ |
105
|
|
|
window.open("{$uri}", "_parent"); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function passwordSuccess () |
109
|
|
|
{ |
110
|
|
|
jqAlert("{$resTitle}", "{$resMessage}", "{$resOK}", "passwordRefresh()"); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
function passwordError (XMLHttpRequest) |
114
|
|
|
{ |
115
|
|
|
jqAlert("{$resError}", XMLHttpRequest.responseText, "{$resOK}"); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
</script> |
119
|
|
|
JQUERY; |
120
|
|
|
|
121
|
|
|
// generate contents |
122
|
|
|
|
123
|
|
|
$xml .= '<form name="passwordform" action="password.php" success="passwordSuccess" error="passwordError">' |
124
|
|
|
. '<group>' |
125
|
|
|
. '<control name="password1">' |
126
|
|
|
. '<label>' . get_html_resource(RES_PASSWORD_ID) . '</label>' |
127
|
|
|
. '<passbox maxlen="' . MAX_ACCOUNT_PASSWORD . '"/>' |
128
|
|
|
. '</control>' |
129
|
|
|
. '<control name="password2">' |
130
|
|
|
. '<label>' . get_html_resource(RES_PASSWORD_CONFIRM_ID) . '</label>' |
131
|
|
|
. '<passbox maxlen="' . MAX_ACCOUNT_PASSWORD . '"/>' |
132
|
|
|
. '</control>' |
133
|
|
|
. '</group>' |
134
|
|
|
. '<button default="true">' . get_html_resource(RES_SAVE_ID) . '</button>' |
135
|
|
|
. '<note>' . ustrprocess(get_html_resource(RES_ALERT_PASSWORD_TOO_SHORT_ID), MIN_PASSWORD_LENGTH) . '</note>' |
136
|
|
|
. '</form>'; |
137
|
|
|
|
138
|
|
|
echo(xml2html($xml)); |
139
|
|
|
|
140
|
|
|
?> |
141
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.