刚刚有个学生在做实验,说这个论坛要我写个邀请码注册,花了一节课的时间,给他们演示了一下,怎么添加邀请码注册。
1、要保证原功能正常,所以在数据库里新加了一个表user_id,由id,user_id和yqm_time组成,前二个是INT,后一个是text
2、在admin/main.asp中新加一个添加邀请码连接admin_setting_yqm.asp(为了时间,是根据连接管理页面更改的。(邀请码,只能由管理员添加)
具体代码我不写了,直接放上来。。
<!-- #include file="../inc/conn-bbs.asp" --> <!-- #include file="../inc/check_admin_session.asp" --> <!-- #include file="../inc/fun-admin.asp" --> <!-- #include file="../inc/newfun_db.asp" --> <html> <head> <title>邀请码管理</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <link href="../inc/wdiii/common.css" rel="stylesheet"> <link href="../inc/wdiii/table.css" rel="stylesheet"> <script src="../inc/wdiii/index.js" type="text/javascript"></script> </head><body> <% page_no=chk_num(trim_fun(request("page_no"))) mydo=trim_fun(request("mydo")) modid=chk_num(trim_fun(request("modid"))) %> <div class="table-topmenu" > <div class="table-topmenu-left"> <a class="btn <%if len(mydo)=0 then %>btn-gray<%else%>btn-gray2<%end if%>" href="?">邀请码列表</a> <a class="btn <%if len(mydo)>0 then %>btn-gray<%else%>btn-gray2<%end if%>" href="?mydo=add" title="增加邀请码">增加邀请码</a> </div> <div class="table-topmenu-right"> </div> </div> <% select case mydo case "add" %> <form name="form" method="post" action="?mydo=addok"> <table class="table table-bordered table-responsive"> <thead> <tr> <th align="left" width="30%"> 增加新邀请码</th> <th align="left" width="70%"></th> </tr> </thead> <tbody> <td align="right">邀请码</td> <td align="left"><input type="text" name="user_id" class="form-control" placeholder="邀请码" onKeyUp="value=value.replace(/[^\d]/g,'')"></td> </tr> <tr> <td align="right"></td> <td align="left"><input type="submit" class="btn btn-submit" value="确定"></td> </tr> </tbody> </table> </form> <% response.End() case "addok" user_id=trim_fun(request("user_id")) call dperror_admin(len(user_id)=0 or isnull(user_id),"邀请码不能为空","") '读取最高排序 sql="select top 1 * from user_id order by id desc" set rs=bbsconn.execute(sql) sql="select * from user_id where user_id="& user_id set rs=server.CreateObject("adodb.recordset") rs.open sql,bbsconn,1,3 call dperror_admin(not rs.eof,"重复的邀请码","") rs.addnew rs("user_id")=user_id rs("yqm_time")=thistime rs.update call dperror_admin(true,"添加成功","?") response.End() case "del" call dperror_admin(modid<=0,"ID出错","?") sql="delete * from user_id where id="& modid &"" set rs=bbsconn.execute(sql) call dperror_admin(true,"删除成功","?") response.End() end select %> <table class="table table-bordered table-hover table-responsive table-striped"> <thead> <tr> <th>邀请码</th> <th>添加时间</th> <th>操作</th> </tr> </thead> <% sql="select * from user_id order by id desc" set rs=server.CreateObject("adodb.recordset") rs.open sql,bbsconn,1,1 i=1 page_size=12 if not rs.eof then rs.PageSize=page_size pagecount=rs.PageCount '获取总页码 if page_no<=0 then page_no=1 '判断 if page_no>pagecount then page_no=pagecount rs.AbsolutePage=page_no '设置本页页码 allRecordCount=rs.RecordCount else %><thead> <tr> <td colspan="8" style="height:500px; background-color:#fff; text-align:center;"> 暂无链接! </td> </tr> </thead> <% end if %> <tbody> <% allRecordCount=chk_num(allRecordCount) do while not rs.eof id=rs("id") user_id=rs("user_id") yqm_time=rs("yqm_time") %> <tr> <td><%=user_id%></td> <td><%=yqm_time%></td> <td> <a href="?mydo=del&modid=<%=id%>" class="btn btn-danger " onClick="return makesure('是否删除?无法恢复');">删除</a> </td> </tr> <% if i>page_size then exit do i=i+1 rs.movenext loop call display_blanktr(i,page_size,8) %> </tbody> <thead> <tr> <td colspan="6" class="text-center"> <ul class="pagination"> <%=admin_page_no(page_no,pagecount,"key_word="& key_word &"&dtfrom="& dtfrom &"&dtto="& dtto &"&see_type="& see_type &"")%> </ul> </td> </tr> </thead> </table> </body> </html>
判断了邀请码只能写数据,可能要用USER_ID
3、在setting_other.asp中,添加开关邀请码。字段是bbsset_reg_yq。记得把这个字段放到数据库的BBS_Setting表中。取值参考开关注册那个。注意,只加了这个是取不到数据的,得在INC/CONFIG_BBS.ASP中加一条:
4、bbsset_reg_yq=chk_nodes(objNodes(0).selectSingleNode("bbsset_reg_yq"))
5、好了,后台基本OK了,改前台注册页面main/reg.asp。其实就是判断一下,有没有打开邀请码注册。
因为是邀请码,所以我就把用户ID这个改掉了。具体代码是:
原:
<b><%=user_id%></b><input name="user_id" type="hidden" class="input_style" value="<%=user_id%>" readonly>
改:
<%if bbsset_reg_yq=2 then %>
<b><%=user_id%></b><input name="user_id" type="hidden" class="input_style" value="<%=user_id%>" readonly>
<%else%>
<input type="text" name="user_id" class="input_style" placeholder="邀请码" msg="邀请码必须填写!" min="1" dataType="Limit" onkeyup="value=value.replace(/[^\d]/g,'')">
<%end if%>
就是判断一下,有没有打开要邀请码注册,bbsset_reg_yq=2表示否,当然,前提是要论坛开放注册,说了不改变原功能。
6、为了使用过的邀请码不能再用,我们要判断这个邀请码有没有用过,其实这个我们不用写代码,因为已经有过。
sql="select id from BBS_User where user_id="& user_id &""
set rs=bbsconn.execute(sql)
call dperror("",from_mobile,not rs.eof,"邀请码已过期,请联系管理员",index_url&"r.html")
就是这个,我只是改了几个汉字而已。
这里就是判断你写的邀请码有没有在用户表出现过。出现过了,说明被人用了。
7、我们还需要判断一下,邀请码和管理员添加的是不是一样。如果不一样,就是邀请码无效。所以在chk_reg.asp中,我们要加一个代码,判断如果开启了邀请码注册的,要去比对下刚新建的user_id这个表中的数据是否存在,存在的,说明邀请码有效,反之无效。
if bbsset_reg_yq=1 then
sql="select user_id from user_id where user_id <>"& user_id &""
set rs=bbsconn.execute(sql)
call dperror("",from_mobile,not rs.eof,"邀请码无效,请联系管理员",index_url&"r.html")
end if
第一句要判断邀请码注册这功能是打开的,不然就不用比对了。
好了,完成了。