-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchangemail.php
83 lines (76 loc) · 3.8 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
<?php
/**
* Extended User Profile
*
* @copyright The ImpressCMS Project http://www.impresscms.org/
* @license LICENSE.txt
* @license GNU General Public License (GPL) http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* @package modules
* @since 1.2
* @author Jan Pedersen
* @author The SmartFactory <www.smartfactory.ca>
* @author Sina Asghari (aka stranger) <[email protected]>
* @version $Id$
*/
include '../../mainfile.php';
if (!icms::$user || !$icmsConfigUser['allow_chgmail']) redirect_header(ICMS_URL.'/modules/'.basename(dirname(__FILE__)), 3, _NOPERM);
$profile_template = 'profile_changemail.html';
include 'header.php';
if (!isset($_POST['submit']) && !isset($_REQUEST['oldmail'])) {
//show change email form
$form = new icms_form_Theme(_MD_PROFILE_CHANGEMAIL, 'form', $_SERVER['REQUEST_URI'], 'post', true);
$form->addElement(new icms_form_elements_Text(_MD_PROFILE_NEWMAIL, 'newmail', 15, 50), true);
$form->addElement(new icms_form_elements_Button('', 'submit', _SUBMIT, 'submit'));
$form->assign($icmsTpl);
} else {
//compute unique key
$key = md5(substr(icms::$user->getVar('pass'), 0, 5));
if (!isset($_REQUEST['oldmail'])) {
if (!icms_core_DataFilter::checkVar($_POST['newmail'], 'email', 0, 1)) {
redirect_header(ICMS_URL.'/modules/'.basename(dirname(__FILE__)).'changemail.php', 2, _MD_PROFILE_INVALIDMAIL);
}
//send email to new email address with key
$icmsMailer = new icms_messaging_Handler();
$icmsMailer->useMail();
$icmsMailer->setTemplateDir(ICMS_ROOT_PATH.'/modules/'.basename(dirname(__FILE__)).'/language/'.$icmsConfig['language'].'/mail_template');
$icmsMailer->setTemplate('changemail.tpl');
$icmsMailer->assign('SITENAME', $icmsConfig['sitename']);
$icmsMailer->assign('X_UNAME', icms::$user->getVar('uname'));
$icmsMailer->assign('ADMINMAIL', $icmsConfig['adminmail']);
$icmsMailer->assign('SITEURL', ICMS_URL);
$icmsMailer->assign('IP', $_SERVER['REMOTE_ADDR']);
$icmsMailer->assign('NEWEMAIL_LINK', ICMS_URL.'/modules/'.basename(dirname(__FILE__)).'/changemail.php?code='.$key.'&oldmail='.icms::$user->getVar('email'));
$icmsMailer->assign('NEWEMAIL', $_POST['newmail']);
$icmsMailer->setToEmails($_POST['newmail']);
$icmsMailer->setFromEmail($icmsConfig['adminmail']);
$icmsMailer->setFromName($icmsConfig['sitename']);
$icmsMailer->setSubject(sprintf(_MD_PROFILE_NEWEMAILREQ,$icmsConfig['sitename']));
if ($icmsMailer->send()) {
//set proposed email as the user's newemail
$profile_profile_handler = icms_getModuleHandler('profile', basename(dirname(__FILE__)), 'profile');
$profile = $profile_profile_handler->get(icms::$user->getVar('uid'));
$profile->setVar('newemail', $_POST['newmail']);
if ($profile_profile_handler->insert($profile)) redirect_header(ICMS_URL.'/', 2, _MD_PROFILE_NEWMAILMSGSENT);
} else {
//relevant error messages
echo $icmsMailer->getErrors();
}
} else {
//check unique key
if (!isset($_GET['code'])) redirect_header(ICMS_URL, 2, _MD_PROFILE_CONFCODEMISSING);
$code = trim($_GET['code']);
if ($code != $key) redirect_header (ICMS_URL.'/modules/'.basename(dirname(__FILE__)), 3, _MD_PROFILE_CONFCODEWRONG);
//change email address to the proposed on
$profile_profile_handler = icms_getModuleHandler('profile', basename(dirname(__FILE__)), 'profile');
$profile = $profile_profile_handler->get(icms::$user->getVar('uid'));
icms::$user->setVar('email', $profile->getVar('newemail'));
//update user data
if (icms::handler('icms_member')->insertUser(icms::$user, true)) {
redirect_header(ICMS_URL.'/modules/'.basename(dirname(__FILE__)), 2, _MD_PROFILE_EMAILCHANGED);
} else {
echo implode('<br />', icms::$user->getErrors());
}
}
}
$icmsTpl->assign('profile_category_path', _MD_PROFILE_CHANGEMAIL);
include 'footer.php';