Passed
Pull Request — master (#175)
by Michael
03:42
created

changemail.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Extended User Profile
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
16
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
17
 * @package             profile
18
 * @since               2.3.0
19
 * @author              Taiwen Jiang <[email protected]>
20
 */
21
22
use XoopsModules\Suico\IndexController;
23
use Xmf\Request;
24
25
$GLOBALS['xoopsOption']['template_main'] = 'suico_email.tpl';
26
require __DIR__ . '/header.php';
27
/**
28
 * Fetching numbers of groups friends videos pictures etc...
29
 */
30
$controller = new IndexController($xoopsDB, $xoopsUser, $xoopsModule);
31
$nbSections = $controller->getNumbersSections();
32
/* @var XoopsConfigHandler $configHandler */
33
$configHandler              = xoops_getHandler('config');
34
$GLOBALS['xoopsConfigUser'] = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
35
if (!$GLOBALS['xoopsUser'] || 1 != $GLOBALS['xoopsConfigUser']['allow_chgmail']) {
36
    redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/', 2, _NOPERM);
37
}
38
if (!isset($_POST['submit']) || !isset($_POST['passwd'])) {
39
    //show change password form
40
    include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
41
    $form = new XoopsThemeForm(_MD_SUICO_CHANGEMAIL, 'emailform', $_SERVER['REQUEST_URI'], 'post', true);
42
    $form->addElement(new XoopsFormPassword(_US_PASSWORD, 'passwd', 15, 50), true);
43
    $form->addElement(new XoopsFormText(_MD_SUICO_NEWMAIL, 'newmail', 15, 50), true);
44
    $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
45
    $form->assign($GLOBALS['xoopsTpl']);
46
} else {
47
    $myts   = MyTextSanitizer::getInstance();
48
    $pass   = Request::getString('passwd', '', 'POST');
49
    $email  = Request::getString('newmail', '', 'POST');
50
    $errors = [];
51
    if (!password_verify($oldpass, $GLOBALS['xoopsUser']->getVar('pass', 'n'))) {
52
        $errors[] = _MD_SUICO_WRONGPASSWORD;
53
    }
54
    if (!checkEmail($email)) {
55
        $errors[] = _US_INVALIDMAIL;
56
    }
57
    if ($errors) {
58
        $msg = implode('<br>', $errors);
59
    } else {
60
        //update password
61
        $GLOBALS['xoopsUser']->setVar('email', Request::getString('newmail', '', 'POST'));
62
        /* @var XoopsMemberHandler $memberHandler */
63
        $memberHandler = xoops_getHandler('member');
64
        if ($memberHandler->insertUser($GLOBALS['xoopsUser'])) {
65
            $msg = _MD_SUICO_EMAILCHANGED;
66
            //send email to new email address
67
            $xoopsMailer = xoops_getMailer();
68
            $xoopsMailer->useMail();
69
            $xoopsMailer->setTemplateDir($GLOBALS['xoopsModule']->getVar('dirname', 'n'));
70
            $xoopsMailer->setTemplate('emailchanged.tpl');
71
            $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']);
72
            $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']);
73
            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
74
            $xoopsMailer->assign('NEWEMAIL', $email);
75
            $xoopsMailer->setToEmails($email);
76
            $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']);
77
            $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']);
78
            $xoopsMailer->setSubject(sprintf(_MD_SUICO_NEWEMAIL, $GLOBALS['xoopsConfig']['sitename']));
79
            $xoopsMailer->send();
80
        } else {
81
            $msg = implode('<br>', $GLOBALS['xoopsUser']->getErrors());
82
        }
83
    }
84
    redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/index.php?uid=' . $GLOBALS['xoopsUser']->getVar('uid'), 2, $msg);
85
}
86
$xoopsOption['xoops_pagetitle'] = sprintf(_MD_SUICO_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

86
$xoopsOption['xoops_pagetitle'] = sprintf(_MD_SUICO_CHANGEMAIL, $xoopsModule->getVar('name'), /** @scrutinizer ignore-type */ $controller->nameOwner);
Loading history...
87
require __DIR__ . '/footer.php';
88
require dirname(__DIR__, 2) . '/footer.php';
89