Passed
Pull Request — master (#81)
by Michael
02:51
created

changemail.php (3 issues)

1
<?php
2
/**
3
 * Extended User Profile
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             profile
15
 * @since               2.3.0
16
 * @author              Taiwen Jiang <[email protected]>
17
 */
18
19
use XoopsModules\Yogurt\IndexController;
20
use Xmf\Request;
21
22
$GLOBALS['xoopsOption']['template_main'] = 'yogurt_email.tpl';
23
require __DIR__ . '/header.php';
24
25
/**
26
 * Fetching numbers of groups friends videos pictures etc...
27
 */
28
$controller = new IndexController($xoopsDB, $xoopsUser, $xoopsModule);
0 ignored issues
show
The call to XoopsModules\Yogurt\IndexController::__construct() has too many arguments starting with $xoopsModule. ( Ignorable by Annotation )

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

28
$controller = /** @scrutinizer ignore-call */ new IndexController($xoopsDB, $xoopsUser, $xoopsModule);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
29
$nbSections = $controller->getNumbersSections();
30
31
/* @var XoopsConfigHandler $configHandler */
32
$configHandler             = xoops_getHandler('config');
33
$GLOBALS['xoopsConfigUser'] = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
34
35
if (!$GLOBALS['xoopsUser'] || 1 != $GLOBALS['xoopsConfigUser']['allow_chgmail']) {
36
    redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/', 2, _NOPERM);
37
}
38
39
if (!isset($_POST['submit']) || !isset($_POST['passwd'])) {
40
    //show change password form
41
    include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
42
    $form = new XoopsThemeForm(_MD_YOGURT_CHANGEMAIL, 'emailform', $_SERVER['REQUEST_URI'], 'post', true);
43
    $form->addElement(new XoopsFormPassword(_US_PASSWORD, 'passwd', 15, 50), true);
44
    $form->addElement(new XoopsFormText(_MD_YOGURT_NEWMAIL, 'newmail', 15, 50), true);
45
    $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
46
    $form->assign($GLOBALS['xoopsTpl']);
47
} else {
48
    $myts   = MyTextSanitizer::getInstance();
49
    $pass   = Request::getString('passwd', '', 'POST');
50
    $email  = Request::getString('newmail', '', 'POST');
51
    $errors = [];
52
    if (!password_verify($oldpass, $GLOBALS['xoopsUser']->getVar('pass', 'n'))) {
53
        $errors[] = _MA_YOGURT_WRONGPASSWORD;
0 ignored issues
show
The constant _MA_YOGURT_WRONGPASSWORD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
54
    }
55
    if (!checkEmail($email)) {
56
        $errors[] = _US_INVALIDMAIL;
57
    }
58
59
    if ($errors) {
60
        $msg = implode('<br>', $errors);
61
    } else {
62
        //update password
63
        $GLOBALS['xoopsUser']->setVar('email', Request::getString('newmail', '', 'POST'));
64
        /* @var XoopsMemberHandler $memberHandler */
65
        $memberHandler = xoops_getHandler('member');
66
        if ($memberHandler->insertUser($GLOBALS['xoopsUser'])) {
67
            $msg = _MD_YOGURT_EMAILCHANGED;
68
69
            //send email to new email address
70
            $xoopsMailer = xoops_getMailer();
71
            $xoopsMailer->useMail();
72
            $xoopsMailer->setTemplateDir($GLOBALS['xoopsModule']->getVar('dirname', 'n'));
73
            $xoopsMailer->setTemplate('emailchanged.tpl');
74
            $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']);
75
            $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']);
76
            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
77
            $xoopsMailer->assign('NEWEMAIL', $email);
78
            $xoopsMailer->setToEmails($email);
79
            $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']);
80
            $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']);
81
            $xoopsMailer->setSubject(sprintf(_MD_YOGURT_NEWEMAIL, $GLOBALS['xoopsConfig']['sitename']));
82
            $xoopsMailer->send();
83
        } else {
84
            $msg = implode('<br>', $GLOBALS['xoopsUser']->getErrors());
85
        }
86
    }
87
    redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/index.php?uid=' . $GLOBALS['xoopsUser']->getVar('uid'), 2, $msg);
88
}
89
90
$xoopsOption['xoops_pagetitle'] = sprintf(_MD_YOGURT_CHANGEMAIL, $xoopsModule->getVar('name'), $controller->nameOwner);
0 ignored issues
show
It seems like $controller->nameOwner can also be of type array and array; however, parameter $args of sprintf() does only seem to accept 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

90
$xoopsOption['xoops_pagetitle'] = sprintf(_MD_YOGURT_CHANGEMAIL, $xoopsModule->getVar('name'), /** @scrutinizer ignore-type */ $controller->nameOwner);
Loading history...
91
92
require __DIR__ . '/footer.php';
93
require dirname(__DIR__, 2) . '/footer.php';
94