Passed
Pull Request — master (#184)
by Michael
04:19
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'], $_POST['passwd'])) {
39
    $myts   = \MyTextSanitizer::getInstance();
40
    $pass   = Request::getString('passwd', '', 'POST');
41
    $email  = Request::getString('newmail', '', 'POST');
42
    $errors = [];
43
    if (!password_verify($oldpass, $GLOBALS['xoopsUser']->getVar('pass', 'n'))) {
44
        $errors[] = _MD_SUICO_WRONGPASSWORD;
45
    }
46
    if (!checkEmail($email)) {
47
        $errors[] = _US_INVALIDMAIL;
48
    }
49
    if ($errors) {
50
        $msg = implode('<br>', $errors);
51
    } else {
52
        //update password
53
        $GLOBALS['xoopsUser']->setVar('email', Request::getString('newmail', '', 'POST'));
54
        /* @var XoopsMemberHandler $memberHandler */
55
        $memberHandler = xoops_getHandler('member');
56
        if ($memberHandler->insertUser($GLOBALS['xoopsUser'])) {
57
            $msg = _MD_SUICO_EMAILCHANGED;
58
            //send email to new email address
59
            $xoopsMailer = xoops_getMailer();
60
            $xoopsMailer->useMail();
61
            $xoopsMailer->setTemplateDir($GLOBALS['xoopsModule']->getVar('dirname', 'n'));
62
            $xoopsMailer->setTemplate('emailchanged.tpl');
63
            $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']);
64
            $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']);
65
            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
66
            $xoopsMailer->assign('NEWEMAIL', $email);
67
            $xoopsMailer->setToEmails($email);
68
            $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']);
69
            $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']);
70
            $xoopsMailer->setSubject(sprintf(_MD_SUICO_NEWEMAIL, $GLOBALS['xoopsConfig']['sitename']));
71
            $xoopsMailer->send();
72
        } else {
73
            $msg = implode('<br>', $GLOBALS['xoopsUser']->getErrors());
74
        }
75
    }
76
    redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/index.php?uid=' . $GLOBALS['xoopsUser']->getVar('uid'), 2, $msg);
77
} else {
78
    //show change password form
79
    require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
80
    $form = new \XoopsThemeForm(_MD_SUICO_CHANGEMAIL, 'emailform', $_SERVER['REQUEST_URI'], 'post', true);
81
    $form->addElement(new \XoopsFormPassword(_US_PASSWORD, 'passwd', 15, 50), true);
82
    $form->addElement(new \XoopsFormText(_MD_SUICO_NEWMAIL, 'newmail', 15, 50), true);
83
    $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
84
    $form->assign($GLOBALS['xoopsTpl']);
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