Test Setup Failed
Push — master ( 7fc67e...984264 )
by Lio
10:31 queued 17s
created

changepass.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
/**
4
 * Extended User Profile
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
14
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @since               2.3.0
16
 * @author              Jan Pedersen
17
 * @author              Taiwen Jiang <[email protected]>
18
 */
19
20
use Xmf\Request;
21
use XoopsModules\Suico\IndexController;
22
23
$GLOBALS['xoopsOption']['template_main'] = 'suico_changepass.tpl';
24
require __DIR__ . '/header.php';
25
/**
26
 * Fetching numbers of groups friends videos pictures etc...
27
 */
28
$controller = new IndexController($xoopsDB, $xoopsUser, $xoopsModule);
29
$nbSections = $controller->getNumbersSections();
30
if (!$GLOBALS['xoopsUser']) {
31
    redirect_header(XOOPS_URL, 2, _NOPERM);
32
}
33
$xoopsOption['xoops_pagetitle'] = sprintf(_MD_SUICO_CHANGEPASSWORD, $xoopsModule->getVar('name'), $controller->nameOwner);
0 ignored issues
show
It seems like $controller->nameOwner can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
$xoopsOption['xoops_pagetitle'] = sprintf(_MD_SUICO_CHANGEPASSWORD, $xoopsModule->getVar('name'), /** @scrutinizer ignore-type */ $controller->nameOwner);
Loading history...
34
if (isset($_POST['submit'])) {
35
    /** @var XoopsConfigHandler $configHandler */
36
    $configHandler              = xoops_getHandler('config');
37
    $GLOBALS['xoopsConfigUser'] = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
38
    $myts                       = \MyTextSanitizer::getInstance();
39
    $oldpass                    = Request::getString('oldpass', '', 'POST');
40
    $password                   = Request::getString('newpass', '', 'POST');
41
    $vpass                      = Request::getString('vpass', '', 'POST');
42
    $errors                     = [];
43
    if (!password_verify($oldpass, $GLOBALS['xoopsUser']->getVar('pass', 'n'))) {
44
        $errors[] = _MD_SUICO_WRONGPASSWORD;
45
    }
46
    if (mb_strlen($password) < $GLOBALS['xoopsConfigUser']['minpass']) {
47
        $errors[] = sprintf(_US_PWDTOOSHORT, $GLOBALS['xoopsConfigUser']['minpass']);
48
    }
49
    if ($password != $vpass) {
50
        $errors[] = _US_PASSNOTSAME;
51
    }
52
    if ($errors) {
53
        $msg = implode('<br>', $errors);
54
    } else {
55
        //update password
56
        $GLOBALS['xoopsUser']->setVar('pass', password_hash($password, PASSWORD_DEFAULT));
57
        /** @var XoopsMemberHandler $memberHandler */
58
        $memberHandler = xoops_getHandler('member');
59
        $msg           = _MD_SUICO_ERRORDURINGSAVE;
60
        if ($memberHandler->insertUser($GLOBALS['xoopsUser'])) {
61
            $msg = _MD_SUICO_PASSWORDCHANGED;
62
        }
63
    }
64
    redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/index.php?uid=' . $GLOBALS['xoopsUser']->getVar('uid'), 2, $msg);
65
} else {
66
    //show change password form
67
    require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
68
    $form = new \XoopsThemeForm(_MD_SUICO_CHANGEPASSWORD, 'form', $_SERVER['REQUEST_URI'], 'post', true);
69
    $form->addElement(new \XoopsFormPassword(_MD_SUICO_OLDPASSWORD, 'oldpass', 15, 50), true);
70
    $form->addElement(new \XoopsFormPassword(_MD_SUICO_NEWPASSWORD, 'newpass', 15, 50), true);
71
    $form->addElement(new \XoopsFormPassword(_US_VERIFYPASS, 'vpass', 15, 50), true);
72
    $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
73
    $form->assign($GLOBALS['xoopsTpl']);
74
    $xoBreadcrumbs[] = ['title' => _MD_SUICO_CHANGEPASSWORD];
75
}
76
require __DIR__ . '/footer.php';
77
require \dirname(__DIR__, 2) . '/footer.php';
78