forked from qqcdn/jieqi2.4_utf8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailverify.php
208 lines (207 loc) · 10.3 KB
/
emailverify.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
function jieqi_randcode($len)
{
$str = '1234567890';
$result = '';
$l = strlen($str) - 1;
srand((double) microtime() * 1000000);
for ($i = 0; $i < $len; $i++) {
$num = rand(0, $l);
$result .= $str[$num];
}
return $result;
}
define('JIEQI_MODULE_NAME', 'system');
if (!empty($_REQUEST['sendemail']) && !empty($_REQUEST['type']) && $_REQUEST['type'] == 'randcode') {
define('JIEQI_NEED_SESSION', 1);
define('JIEQI_IS_OPEN', 1);
}
require_once 'global.php';
jieqi_loadlang('users', JIEQI_MODULE_NAME);
include_once JIEQI_ROOT_PATH . '/class/users.php';
$users_handler = JieqiUsersHandler::getInstance('JieqiUsersHandler');
if (!empty($_REQUEST['sendemail'])) {
if ($_REQUEST['type'] == 'randcode') {
if (empty($_REQUEST['email']) || !preg_match('/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+([\\.][a-z0-9-]+)+$/i', trim($_REQUEST['email']))) {
jieqi_printfail($jieqiLang['system']['emailrandcode_email_formaterror']);
} else {
$email = trim($_REQUEST['email']);
}
} else {
jieqi_checklogin();
$user = $users_handler->get($_SESSION['jieqiUserId']);
if (!is_object($user)) {
jieqi_printfail(LANG_NO_USER);
}
$email = $user->getVar('email', 'n');
if (empty($email)) {
jieqi_printfail($jieqiLang['system']['email_not_set']);
}
$isverified = $user->getUserset('verify', 'email');
if (!empty($_REQUEST['cancel'])) {
if (!$isverified) {
jieqi_printfail($jieqiLang['system']['emailverify_is_undo']);
}
} else {
if ($isverified) {
jieqi_printfail($jieqiLang['system']['emailverify_is_finished']);
}
}
}
jieqi_loadlang('users', 'system');
jieqi_getconfigs('system', 'configs');
include_once JIEQI_ROOT_PATH . '/lib/mail/mail.php';
$params = array();
if (isset($jieqiConfigs['system']['mailtype'])) {
$params['mailtype'] = $jieqiConfigs['system']['mailtype'];
}
if (isset($jieqiConfigs['system']['maildelimiter'])) {
$params['maildelimiter'] = $jieqiConfigs['system']['maildelimiter'];
}
if (isset($jieqiConfigs['system']['mailfrom'])) {
$params['mailfrom'] = $jieqiConfigs['system']['mailfrom'];
}
if (isset($jieqiConfigs['system']['mailserver'])) {
$params['mailserver'] = $jieqiConfigs['system']['mailserver'];
}
if (isset($jieqiConfigs['system']['mailport'])) {
$params['mailport'] = $jieqiConfigs['system']['mailport'];
}
if (isset($jieqiConfigs['system']['mailauth'])) {
$params['mailauth'] = $jieqiConfigs['system']['mailauth'];
}
if (isset($jieqiConfigs['system']['mailuser'])) {
$params['mailuser'] = $jieqiConfigs['system']['mailuser'];
}
if (isset($jieqiConfigs['system']['mailpassword'])) {
$params['mailpassword'] = $jieqiConfigs['system']['mailpassword'];
}
if (empty($_REQUEST['type'])) {
if (!empty($_REQUEST['cancel'])) {
$_REQUEST['type'] = 'cancel';
} else {
$_REQUEST['type'] = 'verify';
}
}
switch ($_REQUEST['type']) {
case 'cancel':
$url_emailverify = JIEQI_USER_URL . '/emailverify.php?id=' . $user->getVar('uid', 'n') . '&checkcode=' . md5($user->getVar('email', 'n') . $user->getVar('uid', 'n') . $user->getVar('regdate', 'n') . $user->getVar('salt', 'n')) . '&cancel=1';
$title = sprintf($jieqiLang['system']['emailcancel_email_title'], JIEQI_SITE_NAME);
$htmlformat = false;
$c_template = JIEQI_ROOT_PATH . '/templates/emailcancel.html';
if (is_file($c_template)) {
include_once JIEQI_ROOT_PATH . '/header.php';
$jieqiTpl->assign('uid', $user->getVar('uid'));
$jieqiTpl->assign('email', $user->getVar('email'));
$jieqiTpl->assign('uname', $user->getVar('uname'));
$jieqiTpl->assign('name', $user->getVar('name'));
$jieqiTpl->assign('title', jieqi_htmlstr($title));
$jieqiTpl->assign('url_emailverify', $url_emailverify);
$jieqiTpl->setCaching(0);
$content = $jieqiTpl->fetch($c_template);
$htmlformat = true;
} else {
$content = sprintf($jieqiLang['system']['emailverify_email_content'], JIEQI_SITE_NAME, JIEQI_LOCAL_URL, $url_emailverify);
}
$params['contenttype'] = $htmlformat == true ? 'text/html' : 'text/plain';
$jieqimail = new JieqiMail($email, $title, $content, $params);
$jieqimail->sendmail();
if ($jieqimail->isError(JIEQI_ERROR_RETURN)) {
jieqi_printfail(sprintf($jieqiLang['system']['email_send_failure'], implode('<br />', $jieqimail->getErrors(JIEQI_ERROR_RETURN))));
} else {
jieqi_jumppage(JIEQI_URL . '/userdetail.php?sendemail=1', $jieqiLang['system']['emailcancel_send_title'], $jieqiLang['system']['emailcancel_send_content']);
}
break;
case 'randcode':
if (!isset($_SESSION['jieqiRandCode']) || !is_array($_SESSION['jieqiRandCode'])) {
$_SESSION['jieqiRandCode'] = array();
}
if (isset($_SESSION['jieqiRandCode']['emailtime']) && isset($_SESSION['jieqiRandCode']['emailcode']) && JIEQI_NOW_TIME - intval($_SESSION['jieqiRandCode']['emailtime']) < 300) {
$randcode = $_SESSION['jieqiRandCode']['emailcode'];
} else {
$randcode = jieqi_randcode(6);
$_SESSION['jieqiRandCode']['emailcode'] = $randcode;
$_SESSION['jieqiRandCode']['emailtime'] = JIEQI_NOW_TIME;
}
$title = sprintf($jieqiLang['system']['emailrandcode_email_title'], JIEQI_SITE_NAME);
$htmlformat = false;
$c_template = JIEQI_ROOT_PATH . '/templates/emailrandcode.html';
if (is_file($c_template)) {
include_once JIEQI_ROOT_PATH . '/header.php';
$jieqiTpl->assign('email', $email);
$jieqiTpl->assign('title', jieqi_htmlstr($title));
$jieqiTpl->assign('randcode', $randcode);
$jieqiTpl->setCaching(0);
$content = $jieqiTpl->fetch($c_template);
$htmlformat = true;
} else {
$content = sprintf($jieqiLang['system']['emailrandcode'], JIEQI_SITE_NAME, JIEQI_LOCAL_URL, $randcode);
}
$params['contenttype'] = $htmlformat == true ? 'text/html' : 'text/plain';
$jieqimail = new JieqiMail($email, $title, $content, $params);
$jieqimail->sendmail();
if ($jieqimail->isError(JIEQI_ERROR_RETURN)) {
jieqi_printfail(sprintf($jieqiLang['system']['email_send_failure'], implode('<br />', $jieqimail->getErrors(JIEQI_ERROR_RETURN))));
} else {
jieqi_msgwin(LANG_DO_SUCCESS, $jieqiLang['system']['emailrandcode_email_success']);
}
break;
case 'verify':
default:
$url_emailverify = JIEQI_USER_URL . '/emailverify.php?id=' . $user->getVar('uid', 'n') . '&checkcode=' . md5($user->getVar('email', 'n') . $user->getVar('uid', 'n') . $user->getVar('regdate', 'n') . $user->getVar('salt', 'n'));
$title = sprintf($jieqiLang['system']['emailverify_email_title'], JIEQI_SITE_NAME);
$htmlformat = false;
$c_template = JIEQI_ROOT_PATH . '/templates/emailverify.html';
if (is_file($c_template)) {
include_once JIEQI_ROOT_PATH . '/header.php';
$jieqiTpl->assign('uid', $user->getVar('uid'));
$jieqiTpl->assign('email', $user->getVar('email'));
$jieqiTpl->assign('uname', $user->getVar('uname'));
$jieqiTpl->assign('name', $user->getVar('name'));
$jieqiTpl->assign('title', jieqi_htmlstr($title));
$jieqiTpl->assign('url_emailverify', $url_emailverify);
$jieqiTpl->setCaching(0);
$content = $jieqiTpl->fetch($c_template);
$htmlformat = true;
} else {
$content = sprintf($jieqiLang['system']['emailverify_email_content'], JIEQI_SITE_NAME, JIEQI_LOCAL_URL, $url_emailverify);
}
$params['contenttype'] = $htmlformat == true ? 'text/html' : 'text/plain';
$jieqimail = new JieqiMail($email, $title, $content, $params);
$jieqimail->sendmail();
if ($jieqimail->isError(JIEQI_ERROR_RETURN)) {
jieqi_printfail(sprintf($jieqiLang['system']['email_send_failure'], implode('<br />', $jieqimail->getErrors(JIEQI_ERROR_RETURN))));
} else {
jieqi_jumppage(JIEQI_URL . '/userdetail.php?sendemail=1', $jieqiLang['system']['emailverify_send_title'], $jieqiLang['system']['emailverify_send_content']);
}
break;
}
} else {
if (!empty($_REQUEST['id']) && !empty($_REQUEST['checkcode'])) {
$_REQUEST['id'] = intval($_REQUEST['id']);
$user = $users_handler->get($_REQUEST['id']);
if (!is_object($user)) {
jieqi_printfail(LANG_NO_USER);
}
if (md5($user->getVar('email', 'n') . $user->getVar('uid', 'n') . $user->getVar('regdate', 'n') . $user->getVar('salt', 'n')) != $_REQUEST['checkcode']) {
jieqi_printfail($jieqiLang['system']['emailverify_error_checkcode']);
} else {
$isverified = $user->getUserset('verify', 'email');
if (!empty($_REQUEST['cancel'])) {
if ($isverified) {
$user->setVar('verify', $user->upUserset('verify', 'email', 0));
$users_handler->insert($user);
}
jieqi_jumppage(JIEQI_URL . '/userdetail.php', $jieqiLang['system']['emailcancel_success_title'], $jieqiLang['system']['emailcancel_success_content']);
} else {
if (!$isverified) {
$user->setVar('verify', $user->upUserset('verify', 'email', 1));
$users_handler->insert($user);
}
jieqi_jumppage(JIEQI_URL . '/userdetail.php', $jieqiLang['system']['emailverify_success_title'], $jieqiLang['system']['emailverify_success_content']);
}
}
} else {
jieqi_printfail(LANG_ERROR_PARAMETER);
}
}