| 1 | <?php |
|---|
| 2 | // $Id: register.php,v 1.4 2005/08/03 12:39:11 onokazu Exp $ |
|---|
| 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 | |
|---|
| 28 | $xoopsOption['pagetype'] = 'user'; |
|---|
| 29 | |
|---|
| 30 | include 'mainfile.php'; |
|---|
| 31 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 32 | |
|---|
| 33 | $config_handler =& xoops_gethandler('config'); |
|---|
| 34 | $xoopsConfigUser =& $config_handler->getConfigsByCat(XOOPS_CONF_USER); |
|---|
| 35 | |
|---|
| 36 | if (empty($xoopsConfigUser['allow_register'])) { |
|---|
| 37 | redirect_header('index.php', 6, _US_NOREGISTER); |
|---|
| 38 | exit(); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | function userCheck($uname, $email, $pass, $vpass) |
|---|
| 42 | { |
|---|
| 43 | global $xoopsConfigUser; |
|---|
| 44 | $xoopsDB =& Database::getInstance(); |
|---|
| 45 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 46 | $stop = ''; |
|---|
| 47 | if (!checkEmail($email)) { |
|---|
| 48 | $stop .= _US_INVALIDMAIL.'<br />'; |
|---|
| 49 | } |
|---|
| 50 | foreach ($xoopsConfigUser['bad_emails'] as $be) { |
|---|
| 51 | if (!empty($be) && preg_match("/".$be."/i", $email)) { |
|---|
| 52 | $stop .= _US_INVALIDMAIL.'<br />'; |
|---|
| 53 | break; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | if (strrpos($email,' ') > 0) { |
|---|
| 57 | $stop .= _US_EMAILNOSPACES.'<br />'; |
|---|
| 58 | } |
|---|
| 59 | $uname = xoops_trim($uname); |
|---|
| 60 | switch ($xoopsConfigUser['uname_test_level']) { |
|---|
| 61 | case 0: |
|---|
| 62 | // strict |
|---|
| 63 | $restriction = '/[^a-zA-Z0-9\_\-]/'; |
|---|
| 64 | break; |
|---|
| 65 | case 1: |
|---|
| 66 | // medium |
|---|
| 67 | $restriction = '/[^a-zA-Z0-9\_\-\<\>\,\.\$\%\#\@\!\\\'\"]/'; |
|---|
| 68 | break; |
|---|
| 69 | case 2: |
|---|
| 70 | // loose |
|---|
| 71 | $restriction = '/[\000-\040]/'; |
|---|
| 72 | break; |
|---|
| 73 | } |
|---|
| 74 | if (empty($uname) || preg_match($restriction, $uname)) { |
|---|
| 75 | $stop .= _US_INVALIDNICKNAME."<br />"; |
|---|
| 76 | } |
|---|
| 77 | if (strlen($uname) > $xoopsConfigUser['maxuname']) { |
|---|
| 78 | $stop .= sprintf(_US_NICKNAMETOOLONG, $xoopsConfigUser['maxuname'])."<br />"; |
|---|
| 79 | } |
|---|
| 80 | if (strlen($uname) < $xoopsConfigUser['minuname']) { |
|---|
| 81 | $stop .= sprintf(_US_NICKNAMETOOSHORT, $xoopsConfigUser['minuname'])."<br />"; |
|---|
| 82 | } |
|---|
| 83 | foreach ($xoopsConfigUser['bad_unames'] as $bu) { |
|---|
| 84 | if (!empty($bu) && preg_match("/".$bu."/i", $uname)) { |
|---|
| 85 | $stop .= _US_NAMERESERVED."<br />"; |
|---|
| 86 | break; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | if (strrpos($uname, ' ') > 0) { |
|---|
| 90 | $stop .= _US_NICKNAMENOSPACES."<br />"; |
|---|
| 91 | } |
|---|
| 92 | $sql = sprintf('SELECT COUNT(*) FROM %s WHERE uname = %s', $xoopsDB->prefix('users'), $xoopsDB->quoteString(addslashes($uname))); |
|---|
| 93 | $result = $xoopsDB->query($sql); |
|---|
| 94 | list($count) = $xoopsDB->fetchRow($result); |
|---|
| 95 | if ($count > 0) { |
|---|
| 96 | $stop .= _US_NICKNAMETAKEN."<br />"; |
|---|
| 97 | } |
|---|
| 98 | $count = 0; |
|---|
| 99 | if ( $email ) { |
|---|
| 100 | $sql = sprintf('SELECT COUNT(*) FROM %s WHERE email = %s', $xoopsDB->prefix('users'), $xoopsDB->quoteString(addslashes($email))); |
|---|
| 101 | $result = $xoopsDB->query($sql); |
|---|
| 102 | list($count) = $xoopsDB->fetchRow($result); |
|---|
| 103 | if ( $count > 0 ) { |
|---|
| 104 | $stop .= _US_EMAILTAKEN."<br />"; |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | if ( !isset($pass) || $pass == '' || !isset($vpass) || $vpass == '' ) { |
|---|
| 108 | $stop .= _US_ENTERPWD.'<br />'; |
|---|
| 109 | } |
|---|
| 110 | if ( (isset($pass)) && ($pass != $vpass) ) { |
|---|
| 111 | $stop .= _US_PASSNOTSAME.'<br />'; |
|---|
| 112 | } elseif ( ($pass != '') && (strlen($pass) < $xoopsConfigUser['minpass']) ) { |
|---|
| 113 | $stop .= sprintf(_US_PWDTOOSHORT,$xoopsConfigUser['minpass'])."<br />"; |
|---|
| 114 | } |
|---|
| 115 | return $stop; |
|---|
| 116 | } |
|---|
| 117 | $op = !isset($_POST['op']) ? 'register' : $_POST['op']; |
|---|
| 118 | $uname = isset($_POST['uname']) ? $myts->stripSlashesGPC($_POST['uname']) : ''; |
|---|
| 119 | $email = isset($_POST['email']) ? trim($myts->stripSlashesGPC($_POST['email'])) : ''; |
|---|
| 120 | $url = isset($_POST['url']) ? trim($myts->stripSlashesGPC($_POST['url'])) : ''; |
|---|
| 121 | $pass = isset($_POST['pass']) ? $myts->stripSlashesGPC($_POST['pass']) : ''; |
|---|
| 122 | $vpass = isset($_POST['vpass']) ? $myts->stripSlashesGPC($_POST['vpass']) : ''; |
|---|
| 123 | $timezone_offset = $xoopsConfig['default_TZ']; |
|---|
| 124 | $user_viewemail = (isset($_POST['user_viewemail']) && intval($_POST['user_viewemail'])) ? 1 : 0; |
|---|
| 125 | $user_mailok = (isset($_POST['user_mailok']) && intval($_POST['user_mailok'])) ? 1 : 0; |
|---|
| 126 | $agree_disc = 1; |
|---|
| 127 | switch ( $op ) { |
|---|
| 128 | case 'newuser': |
|---|
| 129 | if (!XoopsSingleTokenHandler::quickValidate('register_newuser')) { |
|---|
| 130 | exit(); |
|---|
| 131 | } |
|---|
| 132 | include 'header.php'; |
|---|
| 133 | $stop = ''; |
|---|
| 134 | if ($xoopsConfigUser['reg_dispdsclmr'] != 0 && $xoopsConfigUser['reg_disclaimer'] != '') { |
|---|
| 135 | if (empty($agree_disc)) { |
|---|
| 136 | $stop .= _US_UNEEDAGREE.'<br />'; |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | $stop .= userCheck($uname, $email, $pass, $vpass); |
|---|
| 141 | if (empty($stop)) { |
|---|
| 142 | $token =& XoopsSingleTokenHandler::quickCreate('register_finish'); |
|---|
| 143 | |
|---|
| 144 | /* ¥Õ¥©¡¼¥à¾åµ¥³¥á¥ó¥È */ |
|---|
| 145 | echo "<table id='centerMessage'> |
|---|
| 146 | <tr> |
|---|
| 147 | <td> |
|---|
| 148 | <span class='fs22'><span class='red'>¢¨</span>¡ÖÁ÷¿®¡×¥Ü¥¿¥ó¤ò²¡¤¹¤È¥æ¡¼¥¶ÅÐÏ¿Íѥ᡼¥ë¤òÁ÷¿®¤·¤Þ¤¹¡£<br /> |
|---|
| 149 | ËÜʸ¤ËµºÜ¤µ¤ì¤Æ¤¤¤ë¥ê¥ó¥¯¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¥æ¡¼¥¶ÅÐÏ¿´°Î»¤·¤Æ¤¯¤À¤µ¤¤¡£<br /><br /> |
|---|
| 150 | ¢§---²¼µ¥á¡¼¥ë¥¢¥É¥ì¥¹¤Ø¥á¡¼¥ë¤òÁ÷¿®¤·¤Þ¤¹¡£--- |
|---|
| 151 | </span> |
|---|
| 152 | </td> |
|---|
| 153 | </tr> |
|---|
| 154 | <tr><td heigth='10'></td></tr> |
|---|
| 155 | <tr> |
|---|
| 156 | <td><span class='fs22'>"; |
|---|
| 157 | |
|---|
| 158 | echo _US_USERNAME.": ".$myts->htmlSpecialChars($uname)."<br />"; |
|---|
| 159 | echo _US_EMAIL.": ".$myts->htmlSpecialChars($email)."<br />"; |
|---|
| 160 | if ($url != '') { |
|---|
| 161 | $url = formatURL($url); |
|---|
| 162 | echo _US_WEBSITE.': '.$myts->htmlSpecialChars($url).'<br />'; |
|---|
| 163 | } |
|---|
| 164 | //$f_timezone = ($timezone_offset < 0) ? 'GMT '.$timezone_offset : 'GMT +'.$timezone_offset; |
|---|
| 165 | //echo _US_TIMEZONE.": $f_timezone<br />"; |
|---|
| 166 | echo "<form action='register.php' method='post'>"; |
|---|
| 167 | echo $token->getHtml(); |
|---|
| 168 | echo "<input type='hidden' name='uname' value='".$myts->htmlSpecialChars($uname)."' /> |
|---|
| 169 | <input type='hidden' name='email' value='".$myts->htmlSpecialChars($email)."' />"; |
|---|
| 170 | echo "<input type='hidden' name='user_viewemail' value='".$user_viewemail."' /> |
|---|
| 171 | <input type='hidden' name='url' value='".$myts->htmlSpecialChars($url)."' /> |
|---|
| 172 | <input type='hidden' name='pass' value='".$myts->htmlSpecialChars($pass)."' /> |
|---|
| 173 | <input type='hidden' name='vpass' value='".$myts->htmlSpecialChars($vpass)."' /> |
|---|
| 174 | <input type='hidden' name='timezone_offset' value='".(float)$timezone_offset."' /> |
|---|
| 175 | <input type='hidden' name='user_mailok' value='1' /> |
|---|
| 176 | <br /><br /><input type='hidden' name='op' value='finish' /><center><input type='submit' value='". _US_FINISH ."' /></center></form> |
|---|
| 177 | </span></td> |
|---|
| 178 | </tr> |
|---|
| 179 | </table>"; |
|---|
| 180 | } else { |
|---|
| 181 | echo "<span style='color:#ff0000;'>$stop</span>"; |
|---|
| 182 | include 'include/registerform.php'; |
|---|
| 183 | $reg_form->display(); |
|---|
| 184 | } |
|---|
| 185 | include 'footer.php'; |
|---|
| 186 | break; |
|---|
| 187 | case 'finish': |
|---|
| 188 | if (!XoopsSingleTokenHandler::quickValidate('register_finish')) { |
|---|
| 189 | exit(); |
|---|
| 190 | } |
|---|
| 191 | include 'header.php'; |
|---|
| 192 | include 'include/registerform.php'; |
|---|
| 193 | |
|---|
| 194 | $stop = userCheck($uname, $email, $pass, $vpass); |
|---|
| 195 | if ( empty($stop) ) { |
|---|
| 196 | $member_handler =& xoops_gethandler('member'); |
|---|
| 197 | $newuser =& $member_handler->createUser(); |
|---|
| 198 | $newuser->setVar('user_viewemail',$user_viewemail, true); |
|---|
| 199 | $newuser->setVar('uname', $uname, true); |
|---|
| 200 | $newuser->setVar('email', $email, true); |
|---|
| 201 | if ($url != '') { |
|---|
| 202 | $newuser->setVar('url', formatURL($url), true); |
|---|
| 203 | } |
|---|
| 204 | $newuser->setVar('user_avatar','blank.gif', true); |
|---|
| 205 | $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|---|
| 206 | $newuser->setVar('actkey', $actkey, true); |
|---|
| 207 | $newuser->setVar('pass', md5($pass), true); |
|---|
| 208 | $newuser->setVar('timezone_offset', $timezone_offset, true); |
|---|
| 209 | $newuser->setVar('user_regdate', time(), true); |
|---|
| 210 | $newuser->setVar('uorder',$xoopsConfig['com_order'], true); |
|---|
| 211 | $newuser->setVar('umode',$xoopsConfig['com_mode'], true); |
|---|
| 212 | $newuser->setVar('user_mailok',$user_mailok, true); |
|---|
| 213 | if ($xoopsConfigUser['activation_type'] == 1) { |
|---|
| 214 | $newuser->setVar('level', 1, true); |
|---|
| 215 | } |
|---|
| 216 | if (!$member_handler->insertUser($newuser)) { |
|---|
| 217 | echo _US_REGISTERNG; |
|---|
| 218 | include 'footer.php'; |
|---|
| 219 | exit(); |
|---|
| 220 | } |
|---|
| 221 | $newid = $newuser->getVar('uid'); |
|---|
| 222 | if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newid)) { |
|---|
| 223 | echo _US_REGISTERNG; |
|---|
| 224 | include 'footer.php'; |
|---|
| 225 | exit(); |
|---|
| 226 | } |
|---|
| 227 | if ($xoopsConfigUser['activation_type'] == 1) { |
|---|
| 228 | redirect_header('index.php', 4, _US_ACTLOGIN); |
|---|
| 229 | exit(); |
|---|
| 230 | } |
|---|
| 231 | if ($xoopsConfigUser['activation_type'] == 0) { |
|---|
| 232 | $xoopsMailer =& getMailer(); |
|---|
| 233 | $xoopsMailer->useMail(); |
|---|
| 234 | $xoopsMailer->setTemplate('register.tpl'); |
|---|
| 235 | $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|---|
| 236 | $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|---|
| 237 | $xoopsMailer->assign('SITEURL', XOOPS_URL."/"); |
|---|
| 238 | $xoopsMailer->setToUsers(new XoopsUser($newid)); |
|---|
| 239 | $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|---|
| 240 | $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|---|
| 241 | $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname)); |
|---|
| 242 | if ( !$xoopsMailer->send() ) { |
|---|
| 243 | echo _US_YOURREGMAILNG; |
|---|
| 244 | } else { |
|---|
| 245 | // ¾åÉô¥á¥Ã¥»¡¼¥¸ |
|---|
| 246 | echo "<table id='centerMessage'> |
|---|
| 247 | <tr> |
|---|
| 248 | <td> |
|---|
| 249 | <span class='fs22'><span class='red'>¢¨</span>¤´ÅÐÏ¿ÍÆñ¤¦¤´¤¶¤¤¤Þ¤·¤¿¡£<br /> |
|---|
| 250 | ÅÐÏ¿Íѥ᡼¥ë¤òÁ÷¿®Ãפ·¤Þ¤·¤¿¡£</span> |
|---|
| 251 | </td> |
|---|
| 252 | </tr> |
|---|
| 253 | </table>"; |
|---|
| 254 | //echo _US_YOURREGISTERED; |
|---|
| 255 | } |
|---|
| 256 | } elseif ($xoopsConfigUser['activation_type'] == 2) { |
|---|
| 257 | $xoopsMailer =& getMailer(); |
|---|
| 258 | $xoopsMailer->useMail(); |
|---|
| 259 | $xoopsMailer->setTemplate('adminactivate.tpl'); |
|---|
| 260 | $xoopsMailer->assign('USERNAME', $uname); |
|---|
| 261 | $xoopsMailer->assign('USEREMAIL', $email); |
|---|
| 262 | $xoopsMailer->assign('USERACTLINK', XOOPS_URL.'/user.php?op=actv&id='.$newid.'&actkey='.$actkey); |
|---|
| 263 | $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|---|
| 264 | $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|---|
| 265 | $xoopsMailer->assign('SITEURL', XOOPS_URL."/"); |
|---|
| 266 | $member_handler =& xoops_gethandler('member'); |
|---|
| 267 | $xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['activation_group'])); |
|---|
| 268 | $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|---|
| 269 | $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|---|
| 270 | $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname)); |
|---|
| 271 | if ( !$xoopsMailer->send() ) { |
|---|
| 272 | echo _US_YOURREGMAILNG; |
|---|
| 273 | } else { |
|---|
| 274 | echo _US_YOURREGISTERED2; |
|---|
| 275 | } |
|---|
| 276 | } |
|---|
| 277 | if ($xoopsConfigUser['new_user_notify'] == 1 && !empty($xoopsConfigUser['new_user_notify_group'])) { |
|---|
| 278 | /* ¥æ¡¼¥¶ÅÐÏ¿»þ´ÉÍý¼Ô¤Ø¤Î¥á¡¼¥ëÇÛ¿®¤òÄä»ß */ |
|---|
| 279 | /*$xoopsMailer =& getMailer(); |
|---|
| 280 | $xoopsMailer->useMail(); |
|---|
| 281 | $member_handler =& xoops_gethandler('member'); |
|---|
| 282 | $xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['new_user_notify_group'])); |
|---|
| 283 | $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|---|
| 284 | $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|---|
| 285 | $xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT,$xoopsConfig['sitename'])); |
|---|
| 286 | $xoopsMailer->setBody(sprintf(_US_HASJUSTREG, $uname)); |
|---|
| 287 | $xoopsMailer->send(); |
|---|
| 288 | */ |
|---|
| 289 | } |
|---|
| 290 | } else { |
|---|
| 291 | echo "<span style='color:#ff0000; font-weight:bold;'>$stop</span>"; |
|---|
| 292 | include 'include/registerform.php'; |
|---|
| 293 | $reg_form->display(); |
|---|
| 294 | } |
|---|
| 295 | include 'footer.php'; |
|---|
| 296 | break; |
|---|
| 297 | case 'register': |
|---|
| 298 | default: |
|---|
| 299 | include 'header.php'; |
|---|
| 300 | include 'include/registerform.php'; |
|---|
| 301 | $reg_form->display(); |
|---|
| 302 | include 'footer.php'; |
|---|
| 303 | break; |
|---|
| 304 | } |
|---|
| 305 | ?> |
|---|