(草稿箱里积压了太多东西,于是整理一下一起丢出来,现在 Discuz X3.0 都已经进入 beta 了。不过按照他们的尿性,自从 X2.5 开始就越来越不稳定了。)
Discuz X2.5 带来的很多更新确实很棒,但是最关键的问题是这货实在不稳定。因此最后的最后还是从 X2.5 降级到了 X2.0。不过 X2.5 有一个通过邮件发送注册链接的功能很实用,可以有效避免注册机的注册,开启之后论坛上注册用户,需要先填写邮箱地址,通过收到的邮件中的链接才能注册。
于是花了点时间把这个功能从 X2.5 port 回了 X2.0,顺便感谢一下 Meld 这个给力的比较/合并工具。
以下是 patch 文件,这里是 Github Gist。
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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | --- dzx20backup/source/admincp/admincp_setting.php +++ dzx20/source/admincp/admincp_setting.php @@ -395,6 +395,7 @@ showsetting('setting_access_register_regclosemessage', 'settingnew[regclosemessage]', $setting['regclosemessage'], 'textarea'); showsetting('setting_access_register_name', 'settingnew[regname]', $setting['regname'], 'text'); + showsetting('setting_access_register_send_register_url', 'settingnew[sendregisterurl]', $setting['sendregisterurl'], 'radio'); showsetting('setting_access_register_link_name', 'settingnew[reglinkname]', $setting['reglinkname'], 'text'); showsetting('setting_access_register_censoruser', 'settingnew[censoruser]', $setting['censoruser'], 'textarea'); showsetting('setting_access_register_verify', array('settingnew[regverify]', array( --- dzx20backup/source/class/class_member.php +++ dzx20/source/class/class_member.php @@ -376,59 +376,93 @@ if(!$invitestatus) { $invite = getinvite(); } + $sendurl = $this->setting['sendregisterurl'] ? true : false; + if($sendurl) { + if(!empty($_GET['hash'])) { + $hash = explode("\t", authcode($_GET['hash'], 'DECODE', $_G['config']['security']['authkey'])); + if(is_array($hash) && isemail($hash[0]) && TIMESTAMP - $hash[1] < 259200) { + $sendurl = false; + } + } + } if(!submitcheck('regsubmit', 0, $seccodecheck, $secqaacheck)) { - if($_G['gp_action'] == 'activation') { - $auth = explode("\t", authcode($auth, 'DECODE')); - if(FORMHASH != $auth[1]) { - showmessage('register_activation_invalid', 'member.php?mod=logging&action=login'); - } - $username = $auth[0]; - $activationauth = authcode("$auth[0]\t".FORMHASH, 'ENCODE'); - } - - if($fromuid) { - $query = DB::query("SELECT username FROM ".DB::table('common_member')." WHERE uid='$fromuid'"); - if(DB::num_rows($query)) { - $fromuser = dhtmlspecialchars(DB::result($query, 0)); - } else { - dsetcookie('promotion'); - } - } - - $bbrulestxt = nl2br("\n$bbrulestxt\n\n"); - if($_G['gp_action'] == 'activation') { - $auth = dhtmlspecialchars($auth); - } - - if($seccodecheck) { - $seccode = random(6, 1); - } - - $username = dhtmlspecialchars($username); - - $htmls = $settings = array(); - foreach($_G['cache']['fields_register'] as $field) { - $fieldid = $field['fieldid']; - $html = profile_setting($fieldid, array(), false, false, true); - if($html) { - $settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid]; - $htmls[$fieldid] = $html; - } - } - - $navtitle = $this->setting['reglinkname']; - - if($this->extrafile && file_exists(libfile('member/'.$this->extrafile, 'module'))) { - require_once libfile('member/'.$this->extrafile, 'module'); - } - + if(!$sendurl) { + if($_GET['gp_action'] == 'activation') { + $auth = explode("\t", authcode($auth, 'DECODE')); + if(FORMHASH != $auth[1]) { + showmessage('register_activation_invalid', 'member.php?mod=logging&action=login'); + } + $username = $auth[0]; + $activationauth = authcode("$auth[0]\t".FORMHASH, 'ENCODE'); + } + + if($fromuid) { + $query = DB::query("SELECT username FROM ".DB::table('common_member')." WHERE uid='$fromuid'"); + if(DB::num_rows($query)) { + $fromuser = dhtmlspecialchars(DB::result($query, 0)); + } else { + dsetcookie('promotion'); + } + } + + $bbrulestxt = nl2br("\n$bbrulestxt\n\n"); + if($_G['gp_action'] == 'activation') { + $auth = dhtmlspecialchars($auth); + } + + if($seccodecheck) { + $seccode = random(6, 1); + } + + $username = dhtmlspecialchars($username); + + $htmls = $settings = array(); + foreach($_G['cache']['fields_register'] as $field) { + $fieldid = $field['fieldid']; + $html = profile_setting($fieldid, array(), false, false, true); + if($html) { + $settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid]; + $htmls[$fieldid] = $html; + } + } + + $navtitle = $this->setting['reglinkname']; + + if($this->extrafile && file_exists(libfile('member/'.$this->extrafile, 'module'))) { + require_once libfile('member/'.$this->extrafile, 'module'); + } + } $dreferer = dreferer(); include template($this->template); } else { + if($sendurl) { + $_G['gp_email'] = $_GET[''.$this->setting['reginput']['email']]; + checkemail($_G['gp_email']); + $hashstr = urlencode(authcode("$_G[gp_email]\t$_G[timestamp]", 'ENCODE', $_G['config']['security']['authkey'])); + $registerurl = "{$_G[siteurl]}member.php?mod=".$this->setting['regname']."&hash={$hashstr}&email={$_G[gp_email]}"; + $email_register_message = lang('email', 'email_register_message', array( + 'bbname' => $this->setting['bbname'], + 'siteurl' => $_G['siteurl'], + 'url' => $registerurl + )); + if(!sendmail("$_G[gp_email] <$_G[gp_email]>", lang('email', 'email_register_subject'), $email_register_message)) { + runlog('sendmail', print_r($_GET, 1) . $this->setting[reginput][email] . "$_G[gp_email] sendmail failed."); + } + showmessage('register_email_send_succeed', dreferer(), array('bbname' => $this->setting['bbname']), array('showdialog' => true, 'msgtype' => 3, 'closetime' => 10)); + } + $emailstatus = 0; + if($this->setting['sendregisterurl'] && !$sendurl) { + $_GET['email'] = strtolower($hash[0]); + $this->setting['regverify'] = $this->setting['regverify'] == 1 ? 0 : $this->setting['regverify']; + if(!$this->setting['regverify']) { + $groupinfo['groupid'] = $this->setting['newusergroupid']; + } + $emailstatus = 1; + } if($this->setting['regstatus'] == 2 && empty($invite) && !$invitestatus) { showmessage('not_open_registration_invite'); --- dzx20backup/source/language/member/lang_template.php +++ dzx20/source/language/member/lang_template.php @@ -42,6 +42,7 @@ 'register_password_tips' => '请填写密码', 'register_repassword_tips' => '请再次输入密码', 'register_username_tips' => '用户名由 3 到 15 个字符组成', + 'register_validate_email_tips' => '注册需要验证邮箱,请务必填写正确的邮箱,提交后请及时查收邮件。<br />您可能需要等待几分钟才能收到邮件,如果收件箱没有,请检查一下垃圾邮件箱。', 'rulemessage' => '网站服务条款', ); --- dzx20backup/source/language/lang_admincp.php +++ dzx20/source/language/lang_admincp.php @@ -632,6 +632,9 @@ 'setting_access_register_open' => '开放普通注册', 'setting_access_register_invite' => '开放邀请注册', 'setting_access_register_connect' => '开放QQ注册', + 'setting_access_register_send_register_url' => '通过邮件发送注册链接', + 'setting_access_register_send_register_url_comment' => '开启后系统会发一条注册的地址到用户的邮箱,从该地址链接过来的允许注册,同时建议UCenter中开启一个邮箱只允许注册一个帐户<br/>注意:只有在<a href="?action=setting&operation=mail">站长 - 邮件设置</a>中完成邮件设置,确保邮件能发送成功下可以开启该功能 ', + 'setting_access_register_invite_buy' => '允许充值购买邀请码', 'setting_access_register_invite_buy_comment' => '允许游客通过在线充值购买注册邀请码。仅限于关闭普通注册时有效。开启前请确认您的<a href="'.ADMINSCRIPT.'?frames=yes&action=setting&operation=ec" target="_blank"><strong>电子商务</strong></a>及<a href="'.ADMINSCRIPT.'?frames=yes&action=setting&operation=mail" target="_blank"><strong>发送邮件</strong></a>功能可正常使用', 'setting_access_register_invite_buyprice' => '邀请码单价(元)', --- dzx20backup/source/language/lang_email.php +++ dzx20/source/language/lang_email.php @@ -71,6 +71,35 @@ 要对您的地址有效性进行验证以避免垃圾邮件或地址被滥用。</p> <p>您只需点击下面的链接即可激活您的帐号:<br /> + +<a href="{url}" target="_blank">{url}</a> +<br /> +(如果上面不是链接形式,请将该地址手工粘贴到浏览器地址栏再访问)</p> + +<p>感谢您的访问,祝您使用愉快!</p> + + +<p> +此致<br /> + +{bbname} 管理团队.<br /> +{siteurl}</p>', + 'email_register_subject' => '论坛注册地址', + 'email_register_message' => '<br /> +<p>这封信是由 {bbname} 发送的。</p> + +<p>您收到这封邮件,是由于在 {bbname} 获取了新用户注册地址使用 +了这个邮箱地址。如果您并没有访问过 {bbname},或没有进行上述操作,请忽 +略这封邮件。您不需要退订或进行其他进一步的操作。</p> +<br /> +----------------------------------------------------------------------<br /> +<strong>新用户注册说明</strong><br /> +----------------------------------------------------------------------<br /> +<br /> +<p>如果您是 {bbname} 的新用户,或在修改您的注册 Email 时使用了本地址,我们需 +要对您的地址有效性进行验证以避免垃圾邮件或地址被滥用。</p> + +<p>您只需点击下面的链接即可进行用户注册,以下链接有效期为3天。过期可以重新请求发送一封新的邮件验证:<br /> <a href="{url}" target="_blank">{url}</a> <br /> --- dzx20backup/source/language/lang_message.php +++ dzx20/source/language/lang_message.php @@ -928,6 +928,7 @@ 'login_invalid' => '登录失败,您还可以尝试 {loginperm} 次', 'register_disable' => '抱歉,目前站点禁止新用户注册', 'register_disable_activation' => '抱歉,目前站点禁止激活', + 'register_email_send_succeed' => '感谢您注册 {bbname},<br />系统给您发送了一封带有注册地址的邮件,快去登录邮箱获取注册链接进行下一步注册吧', 'not_open_registration_invite' => '抱歉,本站目前暂时不允许用户直接注册,需要有效的邀请码才能注册', 'register_rules_agree' => '您必须同意服务条款后才能注册', 'register_activation_message' => '抱歉,您输入的用户名 "{username}" 已存在,请登录站点激活此帐号', --- dzx20backup/template/default/member/register.htm +++ dzx20/template/default/member/register.htm @@ -38,11 +38,41 @@ <input type="hidden" name="regsubmit" value="yes" /> <input type="hidden" name="formhash" value="{FORMHASH}" /> <input type="hidden" name="referer" value="$dreferer" /> - <input type="hidden" name="activationauth" value="{if $_G[gp_action] == 'activation'}$activationauth{/if}" /> + <input type="hidden" name="activationauth" value="{if $_GET[action] == 'activation'}$activationauth{/if}" /> + <!--{if $_G['setting']['sendregisterurl']}--> + <input type="hidden" name="hash" value="$_GET[hash]" /> + <!--{/if}--> <div class="mtw"> <div id="reginfo_a"> <!--{hook/register_top}--> + <!--{if $sendurl}--> + <div class="rfm"> + <table> + <tr> + <th><span class="rq">*</span><label for="{$this->setting['reginput']['email']}">{lang email}:</label></th> + <td> + <input type="text" id="{$this->setting['reginput']['email']}" name="$this->setting['reginput']['email']" autocomplete="off" size="25" tabindex="1" class="px" required /><br /><em id="emailmore"> </em> + <input type="hidden" name="handlekey" value="sendregister"/> + </td> + <td class="tipcol"><i id="tip_{$this->setting['reginput']['email']}" class="p_tip">{lang register_email_tips}</i><kbd id="chk_{$this->setting['reginput']['email']}" class="p_chk"></kbd></td> + </tr> + </table> + <table> + <tr> + <th> </th> + <td class="tipwide"> + {lang register_validate_email_tips} + </td> + </tr> + </table> + <script type="text/javascript"> + function succeedhandle_sendregister(url, msg, values) { + showDialog(msg, 'notice'); + } + </script> + </div> + <!--{else}--> <!--{if $invite}--> <!--{if $invite['uid']}--> <div class="rfm"> @@ -113,8 +143,12 @@ <div class="rfm"> <table> <tr> - <th><span class="rq">*</span><label for="{$this->setting['reginput']['email']}">{lang email}:</label></th> - <td><input type="text" id="{$this->setting['reginput']['email']}" name="" autocomplete="off" size="25" tabindex="1" class="px" required /><br /><em id="emailmore"> </em></td> + <th><span class="rq">*</span><label for="{$this->setting['reginput']['email']}">{lang email}:</label></th> + <!--{if $hash[1]}--> + <td><input type="text" id="{$this->setting['reginput']['email']}" name="" autocomplete="off" size="25" tabindex="1" readonly value="$hash[0]" required /><br /><em id="emailmore"> </em></td> + <!--{else}--> + <td><input type="text" id="{$this->setting['reginput']['email']}" name="" autocomplete="off" size="25" tabindex="1" required /><br /><em id="emailmore"> </em></td> + <!--{/if}--> <td class="tipcol"><i id="tip_{$this->setting['reginput']['email']}" class="p_tip">{lang register_email_tips}</i><kbd id="chk_{$this->setting['reginput']['email']}" class="p_chk"></kbd></td> </tr> </table> @@ -170,6 +204,7 @@ <!--{/if}--> <!--{/loop}--> + <!--{/if}--> <!--{hook/register_input}--> <!--{if $secqaacheck || $seccodecheck}--> |
使用方法是把这代码用 UTF-8 或者 GBK 编码(根据 Discuz 编码自己决定)保存为文本文件名字是 ABC.patch,然后丢到 Discuz 的根目录下(跟 data,archiver,config,source,template,static 等目录放一起就对了),然后用 patch 命令,去命令行(cmd/sh/bash/终端/SSH)下来到这个目录,运行:
1 | patch -p1 ABC.patch |
于是就可以去后台打开这个选项咯。