Skip to content

Instantly share code, notes, and snippets.

@orzFly
Created March 15, 2013 19:10
Show Gist options
  • Save orzFly/5172278 to your computer and use it in GitHub Desktop.
Save orzFly/5172278 to your computer and use it in GitHub Desktop.
给 Discuz X2.0 增加先验证邮件地址再注册用户的功能(从 X2.5 移植)
--- 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']."&amp;hash={$hashstr}&amp;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">&nbsp;</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>&nbsp;</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">&nbsp;</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">&nbsp;</em></td>
+ <!--{else}-->
+ <td><input type="text" id="{$this->setting['reginput']['email']}" name="" autocomplete="off" size="25" tabindex="1" required /><br /><em id="emailmore">&nbsp;</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}-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment