<!--#include file="qqconnect.asp"-->
<!--#include file="../../Include/Md5.Asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%'=====================================
'软件名称：博科企业网站内容管理系统（BOKECMS）
'软件开发：博科网络科技工作室
'网    址：http://www.bokew.net
'服务  QQ：530051328
'服务邮箱：bbfhq@163.com
'微信公众号：bokewlkj
 
'功能：QQ登录 For ASP
'接口标准OAuth2.0
'能通过QQ登录验证，获取用户空间昵称功能,实现
'QQ快速登录网站、发送微博、分享到QQ空间等简单操作
'=====================================
Call SiteInfo()
Dim qc,CheckLogin,XmlObj,UserInfo,nickname,sex,icon
SET qc = New QqConnet
If Session("Access_Token") = "" Then
    CheckLogin=qc.CheckLogin()
	If CheckLogin=False Then
	Call Alert ("连接QQ认证失败,请后台检查API配置中有关QQ的参数！此外，也有可能是网站空间服务器的时间与腾讯QQ服务器的时间差超过5分钟了！叫空间商调准服务器时间OK！",SysRootDir)   
	   Response.End()
	Else
	   Session("Access_Token")=qc.GetAccess_Token()
	End If
End If
Session("Openid")=qc.Getopenid()
UserInfo=qc.GetUserInfo()
	nickname = qc.GetUserName(UserInfo)(0)
	Session("nickname")=nickname
	sex = qc.GetUserName(UserInfo)(1)
	icon = "http://qzapp.qlogo.cn/qzapp/"&qc.APP_ID&"/"&Session("Openid")&"/50"
Set qc=Nothing
   If sex="男" Then
      sex="先生"
   Else
      sex="小姐"
   End If
session("MemLogin")=""'使会员后台添加绑定时进入关联状态
'=======================================自己增加的成功认证后操作过程开始=======================================
Dim action,openid,QQtoken,MemName,Password,tbname,UserFace,Sitekeywords,rsclass,rslogin,k,RePassWord
action=Request.form("Action")
If Action="check" Then'aaaaaaaa=========
    openid=session("openid")
    QQtoken=Session("Access_Token")
    MemName = CheckStr(trim(request.form("MemName")))
    PassWord = md5(trim(request.form("password")))	
	set rs=server.createobject("adodb.recordset")
	rs.open "select top 1 * from BokeCMS_Members where MemName='" & MemName & "' and password='" & password & "'",conn,1,1
	if rs.eof and rs.bof then
	  rs.close:set rs=Nothing               
	  Call Alert ("您输入的账号不存在或密码不正确！","qqbind.asp")
     response.end
	else
		'绑定到已有账号
		Conn.execute("update BokeCMS_Members set qqopenid='" & openid & "',QQtoken='"&QQtoken&"',nickname='"&Session("nickname")&"' where MemName='" & MemName & "'")
		'调用登录
		session("binding")=""
		session("openid")=""
		Session("Access_Token")=""
		Call DoLogin(MemName,password)
	end if
ElseIf Action="doreg" Then'bbbbbbbb===============
		MemName = 		CheckStr(trim(request.form("MemName")))
		PassWord = 		trim(request.form("PassWord"))
		RePassWord = 	trim(request.form("repassword"))
        email = trim(request.form("email"))
		Sex = 			trim(request.form("Sex"))
		If MemName = "" or len(MemName) > 16 Or len(MemName) < 1 Then
			Call Alert("请填写用户名(大于1小于16位)！",-1)
		ElseIf PassWord = "" or len(PassWord) < 5 Then
			Call Alert("密码不得少于5位！",-1)
        Elseif Not nothaveChinese(MemName) Then
            Call Alert ("本站限制不能用汉字注册!",-1)
        Elseif Check_Str(MemName) then  
			Call Alert ("你想要注册的用户中含有本站禁止注册的字符!",-1)
		End If

		If PassWord = "" Then
			Call Alert("请输入登录密码",-1)
		ElseIF RePassWord="" Then
			Call Alert("请输入确认密码",-1)
		ElseIF PassWord<>RePassWord Then
			Call Alert("两次输入的密码不一致",-1)
		End If

		set rs=server.CreateObject("adodb.recordset")
		rs.open "select top 1 * from BokeCMS_Members where MemName='" & MemName & "'",conn,1,3
		if not rs.eof then
			rs.close:set rs=nothing
			Call Alert ("该用户已存在，请选择新的用户名!","-1")
		end If
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select top 1 * from BokeCMS_Members where email='" & email & "'",conn,1,3
		if not rs.eof then
			rs.close:set rs=nothing
			Call Alert ("该邮箱已注册过，请选择其它邮箱!","-1")
		end If


set rs=server.createobject("adodb.recordset")
sql="select * from [BokeCMS_Members] where MemName='"&MemName&"'"
rs.open sql,conn,1,3
if rs.eof or rs.bof then'判断用户名是否存在
'如果用户名不存在
rs.addnew
rs("MemName")=trim(request.form("MemName"))
rs("Sex")=trim(request.form("Sex"))
rs("Password")=Md5(trim(request.form("Password")))
rs("Email")=trim(request.form("Email"))
rs("GroupID")="2011721738397168"
rs("GroupName")=GroupName("2011721738397168")
If usersh =False Then
rs("Working")=0
Else
rs("Working")=1
End If
rs("AddTime")=now()
rs("qqopenid")=session("openid")
rs("QQtoken")=Session("Access_Token")
rs("nickname")=Session("nickname")
rs.update
rs.close	
set rs=Nothing


else'如果用户名存在
Dim recommend
 if trim(rs("MemName"))=MemName then
 response.Write "此用户名已存在，请另选择！"'用户名已经注册过
 response.end
 end if
response.Write "未知登陆错误！"'未知登陆错误
 response.end
end If'判断用户名是否存在END


set rs=server.createobject("adodb.recordset")
sql="select * from [BokeCMS_Members] where MemName='"&MemName&"'"
rs.open sql,conn,1,3
if rs.eof or rs.bof then'判断用户名是否存在
response.Write "没有此帐号！"
response.End
Else
If usersh=False And rs("Working")=False Then'判断是否审核通过
session("MemName")=""
session("GroupID")=""
session("MemLogin")=""
response.Write "<script language=javascript>alert('注册成功，您的会员资格等待审核中...');location.replace('../../');</script>"	

rs.close
set rs=Nothing
response.end
End If

   MemName=rs("MemName")
   Password=rs("Password")
   GroupID=rs("GroupID")
   'GroupName=rs("GroupName")

   rs("LastLoginTime")=now()
   rs("LastLoginIP")=Request.ServerVariables("Remote_Addr")
   rs("LoginTimes")=rs("LoginTimes")+1
   rs.update
   rs.close
   set rs=nothing
   session("MemName")=MemName
   session("GroupID")=GroupID
   set rs = server.createobject("adodb.recordset")
   sql="select * from BokeCMS_MemGroup where GroupID='"&GroupID&"'"
   rs.open sql,conn,1,1
   session("GroupLevel")=rs("GroupLevel")
   session("MemLogin")="Succeed"
   session.timeout=60
   rs.close	
   set rs=Nothing
End if
session("login")="yes"
	Response.redirect "../../"

Else'cccccc=====================================================================
    '===================绑定处理=================================
		dim ret,msg,figureurl
		if session("resultxml")<>"" then
			dim obj:set obj = getjson(session("resultxml"))
			if isobject(obj) Then
			  ret=obj.ret
			  msg=obj.msg
			  nickname=obj.nickname
			  figureurl=obj.figureurl
			  If right(figureurl,2)="30" then
			  figureurl=Replace(figureurl,right(figureurl,3),"/100")
			  End if
			End If
			set obj=nothing
		end if
		
		if LaoYRequest(ret)<0 then    '获取失败
			 Call Alert ("登录失败",-1)
		end if
		 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<script language="jscript" runat="server">
function getjson(str){
        try{
                eval("var jsonStr = (" + str + ")");
        }catch(ex){
                var jsonStr = null;
        }
        return jsonStr;
}
function sf_chg()
{
	var s = document.getElementById("UserPassword").value;
	var o = document.getElementById("sf_tb");
	if (o){
		o = o.rows[0];
		for(var i=0; i<3; i++){
			o.cells[i].className = "sf_b";
		}
		o.cells[sf_lever(s)-1].className = "sf_a";
	}
}
function sf_lever(s)
{
	if (s.length<6){
		return 1;
	}
	var re = new RegExp(/^\d+$/);
	if (re.test(s)){
		return 1;
	}
	re = new RegExp(/^\w+$/);
	if (re.test(s)){
		return 2;
	}
	return 3;
}
</script>
<title>用QQ登录绑定</title>
		 <style type="text/css">
		  *{margin:0;padding:0;word-wrap:break-word;}
		  body{background:url(../img/bodybg.png) repeat-x;font:8px/1.75 "宋体", arial, sans-serif,'DejaVu Sans','Lucida Grande',Tahoma,'Hiragino Sans GB',STHeiti,SimSun,sans-serif;color:#444;line-height:26px}
		 </style>
</head>
<body><% set rslogin=conn.execute("select top 1 * from BokeCMS_Members where qqopenid='" & CheckStr(session("openid")) & "'")
		if rslogin.eof and rslogin.bof  And session("binding")="yes" Then
		%>
<div class="mwall">
<div class="mw">
  <table width="780" align="center" style="margin:20px auto;">
    <tr>
      <td><img src="<%=icon%>"/>&nbsp;&nbsp;&nbsp;&nbsp;<img src="../img/Connect_logo_230.png" alt="通过QQ帐号快速登录本站" width="230" height="48" border="0">&nbsp;&nbsp;&nbsp;&nbsp;<img src="<%=SysRootDir%>images/qq_logo.png"  width="180" height="48" border="0">
        <br/><strong><font size="3">您好，<font color="red"><%=nickname%></font><%=sex%>，<%=SiteTitle%>欢迎您光临！</font></strong></td>
    </tr>
</table>
  <table width="780" align="center" style="margin:50px auto;">

    <tr>
      <td  width="40%" align="left" valign="top"><strong><font size="3" color="#0066CC">1、如果您已有本站账号，可以快速绑定</font></strong>
        <form action="" method="post" name="myform" id="myform">
        <input type="hidden" name="action" value="check"/>
          <table width="100%" height="180" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="40%" height="30" align="left">
                <input type="hidden" name="openid" value="<%=session("openid")%>"/>
                <input type="hidden" name="userface" value="<%=figureurl%>"/>
                原有用户名：</td>
              <td align="left"><input type="text" name="MemName" maxlength="25" class="borderall" style="width:100px;"/> <font color="red">*</font></td>
            </tr>
            <tr>
              <td height="30" align="left">原有登录密码：</td>
              <td align="left"><input type="password" name="password" maxlength="25" class="borderall"  style="width:100px;"/> <font color="red">*</font></td>
            </tr>
            <tr>
              <td height="30" align="left" colspan="2"><input type="submit" class="btn" onClick="return(checkbind())" value=" 快速绑定 " name="submit1"/> <A HREF="http://<%=SiteUrl%>">以后再说，返回首页</A></td>
              <td align="left">&nbsp;</td>
            </tr>
          </table>
        </form></td>
      <td width="1" style="border-left:1px solid #f1f1f1">&nbsp;</td>
      <td align="left" valign="top"><strong><font size="3" color="#0066CC">2、如果还没有本站账号，您可以快速注册</font></strong>
        <%
		  if not conn.execute("select top 1 id from BokeCMS_Members where MemName='" & nickname & "'").eof then
		    nickname=nickname & "_" & year(now)
		  end if
		  %>
<script language="javascript">
<!--
//字节数限制，与下面配合=========
String.prototype.Length=function(){
temp=this.replace(/([^\x00-\xff])/g,"$1$1");
return temp.length
}
//显示输入字符数

//验证邮箱正确性
function checkemail(email){
var str=email;
//在JavaScript中，正则表达式只能使用"/"开头和结束，不能使用双引号
var Expression=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; 
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
} 
// --></script>
        <script type="text/javascript">
		    function checkbind(){
				if (document.myform.MemName.value==''){
			   alert('请输入用户名!');
			   document.myform.MemName.focus();
			   return false;
			  }
			  if (document.myform.password.value==''){
			   alert('请输入密码!');
			   document.myform.password.focus();
			   return false;
			  }
              return true;
			}

function checkreg(){
			  if (document.myform1.MemName.value==''){
			   alert('请输入用户名!');
			   document.myform1.MemName.focus();
			   return false;
			  }
             if ((document.myform.MemName.value.Length()>16) || (document.myform1.MemName.value.Length()<3)) //字节数限制，与上面配合
             {
	         alert("登录帐号长度要求3－16字节，请重新输入！");
	         document.myform1.MemName.focus()
	          return false
             }
			  if (document.myform1.password.value==''){
			   alert('请输入注册密码!');
			   document.myform1.password.focus();
			   return false;
			  }
       	     if ((document.myform1.password.value.Length()>16) || (document.myform1.password.value.Length()<6)) //字节数限制，与上面配合
             {
	         alert("密码长度要求6－16字节，请重新输入！");
	         document.myform1.password.focus()
	         return false
             }
			  if (document.myform1.repassword.value==''){
			   alert('请输入重复密码!');
			   document.myform1.repassword.focus();
			   return false;
			  }
			  if (document.myform1.repassword.value!=document.myform1.password.value){
			   alert('两次输入的密码不一致!');
			   document.myform1.repassword.focus();
			   return false;
			  }
           if(document.myform1.email.value.length<1)
	      {
	      alert("电子邮箱不能为空!");
	      document.myform1.email.focus()
	      return false;
	      }
          if (!checkemail(myform1.email.value))
	      {
          alert("您输入电子邮箱不正确，请重新输入!");
          document.myform1.email.focus();
          return false;
          }
          if(document.myform1.email.value.length>30 )
	      {
	    alert("电子邮箱不能超过30个字符!");
	    document.myform1.email.focus();
	    return false;
	    }

			  return true;
			}
		   </script>
        <form action="" method="post" name="myform1" id="myform1">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>              
              <td height="25"><input name="action" type="hidden" id="action" value="doreg"/>
                <input name="openid" type="hidden" id="openid" value="<%=session("openid")%>"/>
                <input type="hidden" name="userface" value="<%=figureurl%>"/>
                <br/>
                用 户 名：
                <input name="MemName" type="text" class="borderall" id="MemName"  style="width:100px;" value="<%=LCase(getpyUTF8(nickname))%>" maxlength="16"/> <font color="red">*</font> <input name="Check" type="button" id="Check" value="检查是否重名" onClick="checkregid();"></td>
            </tr>
            <tr>
              <td height="25">登录密码：
                <input type="password" class="borderall" name="password" maxlength="16"  style="width:100px;"/> <font color="red">*</font></td>
            </tr>
            <tr>
              <td height="25">确认密码：
                <input type="password" class="borderall" name="repassword" maxlength="16"  style="width:100px;"/> <font color="red">*</font></td>
            </tr>
            <tr>
              <td height="25">电子信箱：
                <input type="email" class="borderall" name="email" maxlength="50"  style="width:190px;"/> <font color="red">*</font></td>
            </tr>
            <tr>
              <td height="25">性&nbsp;&nbsp;&nbsp;&nbsp;别：
               <%If sex="先生" Then%>
               <input type="radio" name="sex" checked="checked" value="1"/>
                男
                <input type="radio" name="sex" value="0"/>
                女
				<%else%>
               <input type="radio" name="sex" value="1"/>
                男
                <input type="radio" name="sex" checked="checked" value="0"/>
                女
				<%End If%></td>
            </tr>
            <tr>
              <td height="25"><input type="submit" value=" 快速注册 " class="btn" name="submit2" onClick="return(checkreg());"/> <A HREF="http://<%=SiteUrl%>">以后再说，返回首页</A></td>
            </tr>
          </table>
        </form></td>
    </tr>
  </table>
<%ElseIf Not rslogin.eof and Not rslogin.bof Then'与数据库，验证通过后登录用户中心
       	session("binding")=""
		session("openid")=""
		Session("Access_Token")=""
        Call DoLogin(rslogin("MemName"),rslogin("password"))
Else'与数据库，未绑定或会员等待审核时进入首页
set rs=server.createobject("adodb.recordset")
sql="select * from [BokeCMS_Members] where qqopenid='" &session("openid")& "'"
rs.open sql,conn,1,1
if rs.eof or rs.bof then
response.Write "<script language=javascript>location.replace('../../');</script>"
Elseif rs("Working")=False Then
response.Write "<script language=javascript>location.replace('../../');</script>"
end If
	
end if'与数据库
		set rslogin=nothing
End If'ddddd================================================================
Set qc=Nothing
Call CloseDB(conn)
'=================================自己增加的成功认证后操作过程结束=========================================%>
 <form name='reg' action='../regid.asp' method='post' target='CheckRegid'>
<input type='hidden' name='MemName' value=''> 
</form>
<script language=javascript>
function checkregid()
{
  if (document.myform1.MemName.value=="")
	{
	alert("请输入用户名！");
	document.myform1.MemName.focus();
	return false;
	}
  else
    {
	document.reg.MemName.value=document.myform1.MemName.value;
	var popupWin = window.open('../regid.asp', 'CheckRegid', 'scrollbars=no,width=300,height=100');
	document.reg.submit();
	}
}
</script> 
 <br/> 
</body>
</html>