1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * XOOPS Register
14: *
15: * See the enclosed file license.txt for licensing information.
16: * If you did not receive this file, get it at https://www.gnu.org/licenses/gpl-2.0.html
17: *
18: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
19: * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
20: * @package core
21: * @since 2.0.0
22: * @author Kazumi Ono <webmaster@myweb.ne.jp>
23: */
24:
25: use Xmf\Request;
26:
27: include __DIR__ . '/mainfile.php';
28: $xoopsPreload = XoopsPreload::getInstance();
29: $xoopsPreload->triggerEvent('core.register.start');
30:
31: xoops_loadLanguage('user');
32: xoops_load('XoopsUserUtility');
33:
34: $myts = \MyTextSanitizer::getInstance();
35: /** @var XoopsConfigHandler $config_handler */
36: $config_handler = xoops_getHandler('config');
37: $xoopsConfigUser = $config_handler->getConfigsByCat(XOOPS_CONF_USER);
38:
39: if (empty($xoopsConfigUser['allow_register'])) {
40: redirect_header('index.php', 6, _US_NOREGISTER);
41: }
42:
43: require_once $GLOBALS['xoops']->path('include/notification_constants.php');
44:
45: /**
46: * @param $uname
47: * @param $email
48: * @param $pass
49: * @param $vpass
50: *
51: * @return bool|string
52: */
53: function userCheck($uname, $email, $pass, $vpass)
54: {
55: $GLOBALS['xoopsLogger']->addDeprecated('Function ' . __FUNCTION__ . ' is deprecated, use XoopsUserUtility::validate() instead');
56:
57: return XoopsUserUtility::validate($uname, $email, $pass, $vpass);
58: }
59:
60: // from $_POST we use keys: op, uname, email, url, pass, vpass, timezone_offset,
61: // user_viewemail, user_mailok, agree_disc
62: $op = Request::getCmd('op', 'register', 'POST');
63: $uname = Request::getString('uname', '', 'POST');
64: $email = Request::getEmail('email', '', 'POST');
65: $url = Request::getUrl('url', '', 'POST');
66: $pass = Request::getString('pass', '', 'POST');
67: $vpass = Request::getString('vpass', '', 'POST');
68: $timezone_offset = Request::getFloat('cid', $xoopsConfig['default_TZ'], 'POST');
69: $user_viewemail = Request::getBool('user_viewemail', false, 'POST');
70: $user_mailok = Request::getBool('user_mailok', false, 'POST');
71: $agree_disc = Request::getBool('agree_disc', false, 'POST');
72:
73: // from $_GET we may use keys: op, id, actkey
74: $clean_id = '';
75: $clean_actkey = '';
76: if (!isset($_POST['op']) && isset($_GET['op'])) {
77: $op = Request::getCmd('op', 'register', 'GET');
78: if (isset($_GET['id'])) {
79: $clean_id = Request::getInt('id', '', 'GET');
80: }
81: if (isset($_GET['actkey'])) {
82: $clean_actkey = Request::getCmd('actkey', '', 'GET');
83: }
84: $op = in_array($op, array(
85: 'actv',
86: 'activate',
87: ), true) ? $op : 'register';
88: }
89:
90: switch ($op) {
91: case 'newuser':
92: $xoopsOption['xoops_pagetitle'] = _US_USERREG;
93: include $GLOBALS['xoops']->path('header.php');
94: $stop = '';
95: if (!$GLOBALS['xoopsSecurity']->check()) {
96: $stop .= implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()) . '<br>';
97: }
98: if ($xoopsConfigUser['reg_dispdsclmr'] != 0 && $xoopsConfigUser['reg_disclaimer'] != '') {
99: if (empty($agree_disc)) {
100: $stop .= _US_UNEEDAGREE . '<br>';
101: }
102: }
103: $stop .= XoopsUserUtility::validate($uname, $email, $pass, $vpass);
104: if (empty($stop)) {
105: echo _US_USERNAME . ': ' . $myts->htmlSpecialChars($uname) . '<br>';
106: echo _US_EMAIL . ': ' . $myts->htmlSpecialChars($email) . '<br>';
107: if ($url != '') {
108: $url = formatURL($url);
109: echo _US_WEBSITE . ': ' . $myts->htmlSpecialChars($url) . '<br>';
110: }
111: $f_timezone = ($timezone_offset < 0) ? 'GMT ' . $timezone_offset : 'GMT +' . $timezone_offset;
112: echo _US_TIMEZONE . ": $f_timezone<br>";
113: echo "<form action='register.php' method='post'>";
114: xoops_load('XoopsFormCaptcha');
115: $cpatcha = new XoopsFormCaptcha();
116: echo '<br>' . $cpatcha->getCaption() . ': ' . $cpatcha->render();
117: echo "<input type='hidden' name='uname' value='" . $myts->htmlSpecialChars($uname) . "' />
118: <input type='hidden' name='email' value='" . $myts->htmlSpecialChars($email) . "' />
119: <input type='hidden' name='user_viewemail' value='" . $user_viewemail . "' />
120: <input type='hidden' name='timezone_offset' value='" . (float)$timezone_offset . "' />
121: <input type='hidden' name='url' value='" . $myts->htmlSpecialChars($url) . "' />
122: <input type='hidden' name='pass' value='" . $myts->htmlSpecialChars($pass) . "' />
123: <input type='hidden' name='vpass' value='" . $myts->htmlSpecialChars($vpass) . "' />
124: <input type='hidden' name='user_mailok' value='" . $user_mailok . "' />
125: <br><br><input type='hidden' name='op' value='finish' />" . $GLOBALS['xoopsSecurity']->getTokenHTML() . "<input type='submit' value='" . _US_FINISH . "' /></form>";
126: } else {
127: echo "<span class='red'>$stop</span>";
128: include $GLOBALS['xoops']->path('include/registerform.php');
129: $reg_form->display();
130: }
131: include $GLOBALS['xoops']->path('footer.php');
132: break;
133:
134: case 'finish':
135: include $GLOBALS['xoops']->path('header.php');
136: $stop = XoopsUserUtility::validate($uname, $email, $pass, $vpass);
137: if (!$GLOBALS['xoopsSecurity']->check()) {
138: $stop .= implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()) . '<br>';
139: }
140: xoops_load('XoopsCaptcha');
141: $xoopsCaptcha = XoopsCaptcha::getInstance();
142: if (!$xoopsCaptcha->verify()) {
143: $stop .= $xoopsCaptcha->getMessage() . '<br>';
144: }
145: if (empty($stop)) {
146: /** @var XoopsMemberHandler $member_handler */
147: $member_handler = xoops_getHandler('member');
148: /** @var XoopsUser $newuser */
149: $newuser = $member_handler->createUser();
150: $newuser->setVar('user_viewemail', $user_viewemail, true);
151: $newuser->setVar('uname', $uname, true);
152: $newuser->setVar('email', $email, true);
153: if ($url != '') {
154: $newuser->setVar('url', formatURL($url), true);
155: }
156: $newuser->setVar('user_avatar', 'avatars/blank.gif', true);
157: $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
158: $newuser->setVar('actkey', $actkey, true);
159: $newuser->setVar('pass', password_hash($pass, PASSWORD_DEFAULT), true);
160: $newuser->setVar('timezone_offset', $timezone_offset, true);
161: $newuser->setVar('user_regdate', time(), true);
162: $newuser->setVar('uorder', $GLOBALS['xoopsConfig']['com_order'], true);
163: $newuser->setVar('umode', $GLOBALS['xoopsConfig']['com_mode'], true);
164: $newuser->setVar('theme', $GLOBALS['xoopsConfig']['theme_set'], true);
165: $newuser->setVar('user_mailok', $user_mailok, true);
166: $newuser->setVar('notify_method', (isset($xoopsConfigUser['default_notification']) ? $xoopsConfigUser['default_notification'] : XOOPS_NOTIFICATION_METHOD_PM));
167: if ($xoopsConfigUser['activation_type'] == 1) {
168: $newuser->setVar('level', 1, true);
169: } else {
170: $newuser->setVar('level', 0, true);
171: }
172: if (!$member_handler->insertUser($newuser)) {
173: echo _US_REGISTERNG;
174: include $GLOBALS['xoops']->path('footer.php');
175: exit();
176: }
177: $newid = $newuser->getVar('uid');
178: if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newid)) {
179: echo _US_REGISTERNG;
180: include $GLOBALS['xoops']->path('footer.php');
181: exit();
182: }
183: if ($xoopsConfigUser['activation_type'] == 1) {
184: XoopsUserUtility::sendWelcome($newuser);
185: redirect_header('index.php', 4, _US_ACTLOGIN);
186: }
187: // Sending notification email to user for self activation
188: if ($xoopsConfigUser['activation_type'] == 0) {
189: $xoopsMailer = xoops_getMailer();
190: $xoopsMailer->useMail();
191: $xoopsMailer->setTemplate('register.tpl');
192: $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
193: $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
194: $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
195: $xoopsMailer->setToUsers(new XoopsUser($newid));
196: $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
197: $xoopsMailer->setFromName($xoopsConfig['sitename']);
198: $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname));
199: if (!$xoopsMailer->send()) {
200: echo _US_YOURREGMAILNG;
201: } else {
202: echo _US_YOURREGISTERED;
203: }
204: // Sending notification email to administrator for activation
205: } elseif ($xoopsConfigUser['activation_type'] == 2) {
206: $xoopsMailer = xoops_getMailer();
207: $xoopsMailer->useMail();
208: $xoopsMailer->setTemplate('adminactivate.tpl');
209: $xoopsMailer->assign('USERNAME', $uname);
210: $xoopsMailer->assign('USEREMAIL', $email);
211: $xoopsMailer->assign('USERACTLINK', XOOPS_URL . '/register.php?op=actv&id=' . $newid . '&actkey=' . $actkey);
212: $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
213: $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
214: $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
215: /** @var XoopsMemberHandler $member_handler */
216: $member_handler = xoops_getHandler('member');
217: $xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['activation_group']));
218: $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
219: $xoopsMailer->setFromName($xoopsConfig['sitename']);
220: $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname));
221: if (!$xoopsMailer->send()) {
222: echo _US_YOURREGMAILNG;
223: } else {
224: echo _US_YOURREGISTERED2;
225: }
226: }
227: if ($xoopsConfigUser['new_user_notify'] == 1 && !empty($xoopsConfigUser['new_user_notify_group'])) {
228: $xoopsMailer = xoops_getMailer();
229: $xoopsMailer->reset();
230: $xoopsMailer->useMail();
231: /** @var XoopsMemberHandler $member_handler */
232: $member_handler = xoops_getHandler('member');
233: $xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['new_user_notify_group']));
234: $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
235: $xoopsMailer->setFromName($xoopsConfig['sitename']);
236: $xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT, $xoopsConfig['sitename']));
237: $xoopsMailer->setBody(sprintf(_US_HASJUSTREG, $uname));
238: $xoopsMailer->send();
239: }
240: } else {
241: echo "<span class='red bold'>{$stop}</span>";
242: include $GLOBALS['xoops']->path('include/registerform.php');
243: $reg_form->display();
244: }
245: include $GLOBALS['xoops']->path('footer.php');
246: break;
247:
248: case 'actv':
249: case 'activate':
250: $id = $clean_id;
251: $actkey = $clean_actkey;
252: if (empty($id)) {
253: redirect_header('index.php', 1, '');
254: }
255: /** @var XoopsMemberHandler $member_handler */
256: $member_handler = xoops_getHandler('member');
257: /** @var XoopsUser $thisuser */
258: $thisuser = $member_handler->getUser($id);
259: if (!is_object($thisuser)) {
260: exit();
261: }
262: if ($thisuser->getVar('actkey') != $actkey) {
263: redirect_header('index.php', 5, _US_ACTKEYNOT);
264: } else {
265: if ($thisuser->getVar('level') > 0) {
266: redirect_header('user.php', 5, _US_ACONTACT, false);
267: } else {
268: if (false !== $member_handler->activateUser($thisuser)) {
269: $xoopsPreload->triggerEvent('core.behavior.user.activate', $thisuser);
270: $config_handler = xoops_getHandler('config');
271: $xoopsConfigUser = $config_handler->getConfigsByCat(XOOPS_CONF_USER);
272: if ($xoopsConfigUser['activation_type'] == 2) {
273: $myts = \MyTextSanitizer::getInstance();
274: $xoopsMailer = xoops_getMailer();
275: $xoopsMailer->useMail();
276: $xoopsMailer->setTemplate('activated.tpl');
277: $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
278: $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
279: $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
280: $xoopsMailer->setToUsers($thisuser);
281: $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
282: $xoopsMailer->setFromName($xoopsConfig['sitename']);
283: $xoopsMailer->setSubject(sprintf(_US_YOURACCOUNT, $xoopsConfig['sitename']));
284: include $GLOBALS['xoops']->path('header.php');
285: if (!$xoopsMailer->send()) {
286: printf(_US_ACTVMAILNG, $thisuser->getVar('uname'));
287: } else {
288: printf(_US_ACTVMAILOK, $thisuser->getVar('uname'));
289: }
290: include $GLOBALS['xoops']->path('footer.php');
291: } else {
292: redirect_header('user.php', 5, _US_ACTLOGIN, false);
293: }
294: } else {
295: redirect_header('index.php', 5, _US_ACTFAILD);
296: }
297: }
298: }
299: break;
300:
301: case 'register':
302: default:
303: $xoopsOption['xoops_pagetitle'] = _US_USERREG;
304: include $GLOBALS['xoops']->path('header.php');
305: $xoTheme->addMeta('meta', 'keywords', _US_USERREG . ', ' . _US_NICKNAME); // FIXME!
306: $xoTheme->addMeta('meta', 'description', strip_tags($xoopsConfigUser['reg_disclaimer']));
307: include $GLOBALS['xoops']->path('include/registerform.php');
308: $reg_form->display();
309: include $GLOBALS['xoops']->path('footer.php');
310: break;
311: }
312: