Code Duplication    Length = 46-49 lines in 2 locations

src/controllers/RolesController.php 1 location

@@ 821-866 (lines=46) @@
818
     * @param mixed $confirm
819
     * @param mixed $msg
820
     */
821
    public function doChangePassword($confirm, $msg = '')
822
    {
823
        $data = $this->misc->getDatabaseAccessor();
824
825
        $server_info = $this->misc->getServerInfo();
826
827
        if ($confirm) {
828
            $_REQUEST['rolename'] = $server_info['username'];
829
            $this->printTrail('role');
830
            $this->printTitle($this->lang['strchangepassword'], 'pg.role.alter');
831
            $this->printMsg($msg);
832
833
            $this->coalesceArr($_POST, 'password', '');
834
835
            $this->coalesceArr($_POST, 'confirm', '');
836
837
            echo '<form action="'.\SUBFOLDER.'/src/views/roles" method="post">'.PHP_EOL;
838
            echo '<table>'.PHP_EOL;
839
            echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strpassword']}</th>".PHP_EOL;
840
            echo "\t\t<td><input type=\"password\" name=\"password\" size=\"32\" value=\"",
841
            htmlspecialchars($_POST['password']), "\" /></td>\n\t</tr>".PHP_EOL;
842
            echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strconfirm']}</th>".PHP_EOL;
843
            echo "\t\t<td><input type=\"password\" name=\"confirm\" size=\"32\" value=\"\" /></td>\n\t</tr>".PHP_EOL;
844
            echo '</table>'.PHP_EOL;
845
            echo '<p><input type="hidden" name="action" value="changepassword" />'.PHP_EOL;
846
            echo $this->misc->form;
847
            echo "<input type=\"submit\" name=\"ok\" value=\"{$this->lang['strok']}\" />".PHP_EOL;
848
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL;
849
            echo '</p></form>'.PHP_EOL;
850
        } else {
851
            // Check that password is minimum length
852
            if (strlen($_POST['password']) < $this->conf['min_password_length']) {
853
                $this->doChangePassword(true, $this->lang['strpasswordshort']);
854
            } elseif ($_POST['password'] != $_POST['confirm']) {
855
                // Check that password matches confirmation password
856
                $this->doChangePassword(true, $this->lang['strpasswordconfirm']);
857
            } else {
858
                $status = $data->changePassword($server_info['username'], $_POST['password']);
859
                if (0 == $status) {
860
                    $this->doAccount($this->lang['strpasswordchanged']);
861
                } else {
862
                    $this->doAccount($this->lang['strpasswordchangedbad']);
863
                }
864
            }
865
        }
866
    }
867
}
868

src/controllers/UsersController.php 1 location

@@ 241-289 (lines=49) @@
238
     * @param mixed $confirm
239
     * @param mixed $msg
240
     */
241
    public function doChangePassword($confirm, $msg = '')
242
    {
243
        $data = $this->misc->getDatabaseAccessor();
244
245
        $server_info = $this->misc->getServerInfo();
246
247
        if ($confirm) {
248
            $_REQUEST['user'] = $server_info['username'];
249
            $this->printTrail('user');
250
            $this->printTitle($this->lang['strchangepassword'], 'pg.user.alter');
251
            $this->printMsg($msg);
252
253
            $this->coalesceArr($_POST, 'password', '');
254
255
            $this->coalesceArr($_POST, 'confirm', '');
256
257
            echo '<form action="'.\SUBFOLDER.'/src/views/users" method="post">'.PHP_EOL;
258
            echo '<table>'.PHP_EOL;
259
            echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strpassword']}</th>".PHP_EOL;
260
            echo "\t\t<td><input type=\"password\" name=\"password\" size=\"32\" value=\"",
261
            htmlspecialchars($_POST['password']), "\" /></td>\n\t</tr>".PHP_EOL;
262
            echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strconfirm']}</th>".PHP_EOL;
263
            echo "\t\t<td><input type=\"password\" name=\"confirm\" size=\"32\" value=\"\" /></td>\n\t</tr>".PHP_EOL;
264
            echo '</table>'.PHP_EOL;
265
            echo '<p><input type="hidden" name="action" value="changepassword" />'.PHP_EOL;
266
            echo $this->misc->form;
267
            echo "<input type=\"submit\" name=\"ok\" value=\"{$this->lang['strok']}\" />".PHP_EOL;
268
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL;
269
            echo '</p></form>'.PHP_EOL;
270
        } else {
271
            // Check that password is minimum length
272
            if (strlen($_POST['password']) < $this->conf['min_password_length']) {
273
                $this->doChangePassword(true, $this->lang['strpasswordshort']);
274
            } elseif ($_POST['password'] != $_POST['confirm']) {
275
                // Check that password matches confirmation password
276
                $this->doChangePassword(true, $this->lang['strpasswordconfirm']);
277
            } else {
278
                $status = $data->changePassword(
279
                    $server_info['username'],
280
                    $_POST['password']
281
                );
282
                if (0 == $status) {
283
                    $this->doAccount($this->lang['strpasswordchanged']);
284
                } else {
285
                    $this->doAccount($this->lang['strpasswordchangedbad']);
286
                }
287
            }
288
        }
289
    }
290
291
    /**
292
     * Function to allow editing of a user.