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