PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/register.php

https://gitlab.com/VoyaTrax/vtCMS
PHP | 277 lines | 241 code | 6 blank | 30 comment | 62 complexity | 2ffae1ece4dadaa1bf85ab7b81c2a64d MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, AGPL-1.0
  1. <?php
  2. // $Id: register.php 1029 2007-09-09 03:49:25Z phppp $
  3. // ------------------------------------------------------------------------ //
  4. // XOOPS - PHP Content Management System //
  5. // Copyright (c) 2000 XOOPS.org //
  6. // <http://www.xoops.org/> //
  7. // ------------------------------------------------------------------------ //
  8. // This program is free software; you can redistribute it and/or modify //
  9. // it under the terms of the GNU General Public License as published by //
  10. // the Free Software Foundation; either version 2 of the License, or //
  11. // (at your option) any later version. //
  12. // //
  13. // You may not change or alter any portion of this comment or credits //
  14. // of supporting developers from this source code or any supporting //
  15. // source code which is considered copyrighted (c) material of the //
  16. // original comment or credit authors. //
  17. // //
  18. // This program is distributed in the hope that it will be useful, //
  19. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  20. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  21. // GNU General Public License for more details. //
  22. // //
  23. // You should have received a copy of the GNU General Public License //
  24. // along with this program; if not, write to the Free Software //
  25. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
  26. // ------------------------------------------------------------------------ //
  27. $xoopsOption['pagetype'] = 'user';
  28. include 'mainfile.php';
  29. $myts =& MyTextSanitizer::getInstance();
  30. $config_handler =& xoops_gethandler('config');
  31. $xoopsConfigUser =& $config_handler->getConfigsByCat(XOOPS_CONF_USER);
  32. if (empty($xoopsConfigUser['allow_register'])) {
  33. redirect_header('index.php', 6, _US_NOREGISTER);
  34. exit();
  35. }
  36. function userCheck($uname, $email, $pass, $vpass)
  37. {
  38. global $xoopsConfigUser;
  39. $xoopsDB =& Database::getInstance();
  40. $myts =& MyTextSanitizer::getInstance();
  41. $stop = '';
  42. if (!checkEmail($email)) {
  43. $stop .= _US_INVALIDMAIL.'<br />';
  44. }
  45. foreach ($xoopsConfigUser['bad_emails'] as $be) {
  46. if (!empty($be) && preg_match("/".$be."/i", $email)) {
  47. $stop .= _US_INVALIDMAIL.'<br />';
  48. break;
  49. }
  50. }
  51. if (strrpos($email,' ') > 0) {
  52. $stop .= _US_EMAILNOSPACES.'<br />';
  53. }
  54. $uname = xoops_trim($uname);
  55. switch ($xoopsConfigUser['uname_test_level']) {
  56. case 0:
  57. // strict
  58. $restriction = '/[^a-zA-Z0-9\_\-]/';
  59. break;
  60. case 1:
  61. // medium
  62. $restriction = '/[^a-zA-Z0-9\_\-\<\>\,\.\$\%\#\@\!\\\'\"]/';
  63. break;
  64. case 2:
  65. // loose
  66. $restriction = '/[\000-\040]/';
  67. break;
  68. }
  69. if (empty($uname) || preg_match($restriction, $uname)) {
  70. $stop .= _US_INVALIDNICKNAME."<br />";
  71. }
  72. if (strlen($uname) > $xoopsConfigUser['maxuname']) {
  73. $stop .= sprintf(_US_NICKNAMETOOLONG, $xoopsConfigUser['maxuname'])."<br />";
  74. }
  75. if (strlen($uname) < $xoopsConfigUser['minuname']) {
  76. $stop .= sprintf(_US_NICKNAMETOOSHORT, $xoopsConfigUser['minuname'])."<br />";
  77. }
  78. foreach ($xoopsConfigUser['bad_unames'] as $bu) {
  79. if (!empty($bu) && preg_match("/".$bu."/i", $uname)) {
  80. $stop .= _US_NAMERESERVED."<br />";
  81. break;
  82. }
  83. }
  84. if (strrpos($uname, ' ') > 0) {
  85. $stop .= _US_NICKNAMENOSPACES."<br />";
  86. }
  87. $sql = sprintf('SELECT COUNT(*) FROM %s WHERE uname = %s', $xoopsDB->prefix('users'), $xoopsDB->quoteString(addslashes($uname)));
  88. $result = $xoopsDB->query($sql);
  89. list($count) = $xoopsDB->fetchRow($result);
  90. if ($count > 0) {
  91. $stop .= _US_NICKNAMETAKEN."<br />";
  92. }
  93. $count = 0;
  94. if ( $email ) {
  95. $sql = sprintf('SELECT COUNT(*) FROM %s WHERE email = %s', $xoopsDB->prefix('users'), $xoopsDB->quoteString(addslashes($email)));
  96. $result = $xoopsDB->query($sql);
  97. list($count) = $xoopsDB->fetchRow($result);
  98. if ( $count > 0 ) {
  99. $stop .= _US_EMAILTAKEN."<br />";
  100. }
  101. }
  102. if ( !isset($pass) || $pass == '' || !isset($vpass) || $vpass == '' ) {
  103. $stop .= _US_ENTERPWD.'<br />';
  104. }
  105. if ( (isset($pass)) && ($pass != $vpass) ) {
  106. $stop .= _US_PASSNOTSAME.'<br />';
  107. } elseif ( ($pass != '') && (strlen($pass) < $xoopsConfigUser['minpass']) ) {
  108. $stop .= sprintf(_US_PWDTOOSHORT,$xoopsConfigUser['minpass'])."<br />";
  109. }
  110. return $stop;
  111. }
  112. $op = !isset($_POST['op']) ? 'register' : $_POST['op'];
  113. $uname = isset($_POST['uname']) ? $myts->stripSlashesGPC($_POST['uname']) : '';
  114. $email = isset($_POST['email']) ? trim($myts->stripSlashesGPC($_POST['email'])) : '';
  115. $url = isset($_POST['url']) ? trim($myts->stripSlashesGPC($_POST['url'])) : '';
  116. $pass = isset($_POST['pass']) ? $myts->stripSlashesGPC($_POST['pass']) : '';
  117. $vpass = isset($_POST['vpass']) ? $myts->stripSlashesGPC($_POST['vpass']) : '';
  118. $timezone_offset = isset($_POST['timezone_offset']) ? intval($_POST['timezone_offset']) : $xoopsConfig['default_TZ'];
  119. $user_viewemail = (isset($_POST['user_viewemail']) && intval($_POST['user_viewemail'])) ? 1 : 0;
  120. $user_mailok = (isset($_POST['user_mailok']) && intval($_POST['user_mailok'])) ? 1 : 0;
  121. $agree_disc = (isset($_POST['agree_disc']) && intval($_POST['agree_disc'])) ? 1 : 0;
  122. switch ( $op ) {
  123. case 'newuser':
  124. include 'header.php';
  125. $stop = '';
  126. if (!$GLOBALS['xoopsSecurity']->check()) {
  127. $stop .= implode('<br />', $GLOBALS['xoopsSecurity']->getErrors())."<br />";
  128. }
  129. // Add CAPTCHA by PinMaster -- added hack- hyperclock \\
  130. include 'include/captcha_validate.php';
  131. include 'header.php';
  132. $stop = '';
  133. // ---------- End CAPTCHA HACK ------------ \\
  134. if ($xoopsConfigUser['reg_dispdsclmr'] != 0 && $xoopsConfigUser['reg_disclaimer'] != '') {
  135. if (empty($agree_disc)) {
  136. $stop .= _US_UNEEDAGREE.'<br />';
  137. }
  138. }
  139. $stop .= userCheck($uname, $email, $pass, $vpass);
  140. if (empty($stop)) {
  141. echo _US_USERNAME.": ".$myts->htmlSpecialChars($uname)."<br />";
  142. echo _US_EMAIL.": ".$myts->htmlSpecialChars($email)."<br />";
  143. if ($url != '') {
  144. $url = formatURL($url);
  145. echo _US_WEBSITE.': '.$myts->htmlSpecialChars($url).'<br />';
  146. }
  147. $f_timezone = ($timezone_offset < 0) ? 'GMT '.$timezone_offset : 'GMT +'.$timezone_offset;
  148. echo _US_TIMEZONE.": $f_timezone<br />";
  149. echo "<form action='register.php' method='post'>
  150. <input type='hidden' name='uname' value='".$myts->htmlSpecialChars($uname)."' />
  151. <input type='hidden' name='email' value='".$myts->htmlSpecialChars($email)."' />";
  152. echo "<input type='hidden' name='user_viewemail' value='".$user_viewemail."' />
  153. <input type='hidden' name='timezone_offset' value='".(float)$timezone_offset."' />
  154. <input type='hidden' name='url' value='".$myts->htmlSpecialChars($url)."' />
  155. <input type='hidden' name='pass' value='".$myts->htmlSpecialChars($pass)."' />
  156. <input type='hidden' name='vpass' value='".$myts->htmlSpecialChars($vpass)."' />
  157. <input type='hidden' name='user_mailok' value='".$user_mailok."' />
  158. <br /><br /><input type='hidden' name='op' value='finish' />".$GLOBALS['xoopsSecurity']->getTokenHTML()."<input type='submit' value='". _US_FINISH ."' /></form>";
  159. } else {
  160. echo "<span style='color:#ff0000;'>$stop</span>";
  161. include 'include/registerform.php';
  162. $reg_form->display();
  163. }
  164. include 'footer.php';
  165. break;
  166. case 'finish':
  167. include 'header.php';
  168. $stop = userCheck($uname, $email, $pass, $vpass);
  169. if (!$GLOBALS['xoopsSecurity']->check()) {
  170. $stop .= implode('<br />', $GLOBALS['xoopsSecurity']->getErrors())."<br />";
  171. }
  172. if ( empty($stop) ) {
  173. $member_handler =& xoops_gethandler('member');
  174. $newuser =& $member_handler->createUser();
  175. $newuser->setVar('user_viewemail',$user_viewemail, true);
  176. $newuser->setVar('uname', $uname, true);
  177. $newuser->setVar('email', $email, true);
  178. if ($url != '') {
  179. $newuser->setVar('url', formatURL($url), true);
  180. }
  181. $newuser->setVar('user_avatar','blank.gif', true);
  182. $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
  183. $newuser->setVar('actkey', $actkey, true);
  184. $newuser->setVar('pass', md5($pass), true);
  185. $newuser->setVar('timezone_offset', $timezone_offset, true);
  186. $newuser->setVar('user_regdate', time(), true);
  187. $newuser->setVar('uorder',$xoopsConfig['com_order'], true);
  188. $newuser->setVar('umode',$xoopsConfig['com_mode'], true);
  189. $newuser->setVar('user_mailok',$user_mailok, true);
  190. if ($xoopsConfigUser['activation_type'] == 1) {
  191. $newuser->setVar('level', 1, true);
  192. }
  193. if (!$member_handler->insertUser($newuser)) {
  194. echo _US_REGISTERNG;
  195. include 'footer.php';
  196. exit();
  197. }
  198. $newid = $newuser->getVar('uid');
  199. if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newid)) {
  200. echo _US_REGISTERNG;
  201. include 'footer.php';
  202. exit();
  203. }
  204. if ($xoopsConfigUser['activation_type'] == 1) {
  205. redirect_header('index.php', 4, _US_ACTLOGIN);
  206. exit();
  207. }
  208. if ($xoopsConfigUser['activation_type'] == 0) {
  209. $xoopsMailer =& getMailer();
  210. $xoopsMailer->useMail();
  211. $xoopsMailer->setTemplate('register.tpl');
  212. $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
  213. $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
  214. $xoopsMailer->assign('SITEURL', XOOPS_URL."/");
  215. $xoopsMailer->setToUsers(new XoopsUser($newid));
  216. $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
  217. $xoopsMailer->setFromName($xoopsConfig['sitename']);
  218. $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname));
  219. if ( !$xoopsMailer->send() ) {
  220. echo _US_YOURREGMAILNG;
  221. } else {
  222. echo _US_YOURREGISTERED;
  223. }
  224. } elseif ($xoopsConfigUser['activation_type'] == 2) {
  225. $xoopsMailer =& getMailer();
  226. $xoopsMailer->useMail();
  227. $xoopsMailer->setTemplate('adminactivate.tpl');
  228. $xoopsMailer->assign('USERNAME', $uname);
  229. $xoopsMailer->assign('USEREMAIL', $email);
  230. $xoopsMailer->assign('USERACTLINK', XOOPS_URL.'/user.php?op=actv&id='.$newid.'&actkey='.$actkey);
  231. $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
  232. $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
  233. $xoopsMailer->assign('SITEURL', XOOPS_URL."/");
  234. $member_handler =& xoops_gethandler('member');
  235. $xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['activation_group']));
  236. $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
  237. $xoopsMailer->setFromName($xoopsConfig['sitename']);
  238. $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname));
  239. if ( !$xoopsMailer->send() ) {
  240. echo _US_YOURREGMAILNG;
  241. } else {
  242. echo _US_YOURREGISTERED2;
  243. }
  244. }
  245. if ($xoopsConfigUser['new_user_notify'] == 1 && !empty($xoopsConfigUser['new_user_notify_group'])) {
  246. $xoopsMailer =& getMailer();
  247. $xoopsMailer->useMail();
  248. $member_handler =& xoops_gethandler('member');
  249. $xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['new_user_notify_group']));
  250. $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
  251. $xoopsMailer->setFromName($xoopsConfig['sitename']);
  252. $xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT,$xoopsConfig['sitename']));
  253. $xoopsMailer->setBody(sprintf(_US_HASJUSTREG, $uname));
  254. $xoopsMailer->send();
  255. }
  256. } else {
  257. echo "<span style='color:#ff0000; font-weight:bold;'>$stop</span>";
  258. include 'include/registerform.php';
  259. $reg_form->display();
  260. }
  261. include 'footer.php';
  262. break;
  263. case 'register':
  264. default:
  265. include 'header.php';
  266. include 'include/registerform.php';
  267. $reg_form->display();
  268. include 'footer.php';
  269. break;
  270. }
  271. ?>