<!--#include file="../inc/Bll.asp"-->
<!--#include file="../inc/Constant.asp"-->
<!--#include file="../inc/Md5.asp"-->
<%
dim t_UserInfo,t_UserOpenID,t_UserClientID,t_UserName,t_UserNickName,t_UserSex,t_UserPic

LoginAndReg()

Sub LoginAndReg()
	
	if Request.QueryString("OpenID")="" then Rw "alert('OpenID参数非法!');":Rend
	if not IsNumeric(Request.QueryString("OpenID")) then Rw "alert('OpenID参数非法!');":Rend
	t_UserOpenID = Request.QueryString("OpenID")
	
	t_UserName = t_UserOpenID
	
	if Request.QueryString("NickName")="" then Rw "alert('NickName参数非法!');":Rend
	t_UserNickName = Get_SafeStr(Request.QueryString("NickName"))
	
	if Request.QueryString("Sex")="" then Rw "alert('NickName参数非法!');":Rend
	t_UserSex = Get_SafeStr(Request.QueryString("Sex"))
	if t_UserSex = "male" then t_UserSex = 1 else t_UserSex = 0 end if
	
	t_UserPic = ""
	
	RS_End
	'判断是否存在账户
	RS.Open "select top 1 * from [i_User_Info] a join [i_Sys_Room] b on a.[i_User_ID]=b.[i_Sys_Room_AdminUserID] where a.[i_User_OpenID]='"&t_UserOpenID&"' ", DB_CONN , 1 , 3
	if RS.recordcount>0 then'已经存在
		RS("i_User_Online")=1
		RS("i_User_LastLoginTime")=now()
		RS("i_User_LoginIP")=get_IP()
		RS.Update()
		Session(Session_UserID_Arg)=RS("i_User_ID")
		Session(Session_UserName_Arg)=RS("i_User_Name")
		Session(Session_UserNickName_Arg)=RS("i_User_NickName")
		Session(Session_UserSex_Arg)=RS("i_User_Sex")
		Session(Session_UserClass_Arg)=RS("i_User_Class")
		Session(Session_UserFace_Arg)=RS("i_User_Face")
		Session(Session_RoomID_Arg)=RS("i_Sys_Room_ID")
		Session(Session_LogIP_Arg)=get_IP()
		Session(Session_LogTime_Arg)=now()
		Response.Cookies("ishow")("iAutoLogin")="true":Response.Cookies("ishow")("iUserOpenID")=t_UserOpenID::Response.Cookies("ishow").Expires= (now()+365)
		'整合应用登录
		'i_Syn_Notifyt_Login()
		Rw "location.href='/'":Rend
	else'不存在
	
		RS_End
		RS.Open "select top 1 * from [i_User_Info]", DB_CONN , 1 , 3
		RS.addnew()
		RS("i_User_OpenID")=t_UserOpenID
		RS("i_User_Name")=t_UserName
		RS("i_User_Sex")=t_UserSex
		RS("i_User_NickName")=t_UserNickName
		RS("i_User_Face")=t_UserPic
		RS("i_User_Class")=SysConfig("i_Sys_Config_RegDefaultClass")
		RS("i_User_Score")=SysConfig("i_Sys_Config_RegDefaultScoreNum")
		RS("i_User_Money")=SysConfig("i_Sys_Config_RegDefaultMoneyNum")
		RS("i_User_Online")=1
		RS("i_User_LastLoginTime")=now()
		RS("i_User_LoginIP")=get_IP()
		RS.update()
		RS_End
		'读取注册用户ID
		Set RS=DB_CONN.EXECUTE("select top 1 * from [i_User_Info] where [i_User_Name]='"&t_UserName&"'")
		if RS.RecordCount<1 then Rw "alert('网站注册异常,请联系网站管理员');history.back();":Rend
		t_UserID = RS("i_User_ID")
		RS_End
		'注册房间
		RS.OPEN "select top 1 * from [i_Sys_Room]" , DB_CONN , 1 , 3
		RS.addnew()
		RS("i_Sys_Room_Name")=t_UserNickName
		RS("i_Sys_Room_AdminUserID")=t_UserID
		RS("i_Sys_Room_ManagerUsers")="|"&t_UserID&"|"
		RS.update()
		RS_End
		'设置登录session
		RS.Open "select top 1 * from [i_User_Info] a join [i_Sys_Room] b on a.[i_User_ID]=b.[i_Sys_Room_AdminUserID] where a.[i_User_OpenID]='"&t_UserOpenID&"' ", DB_CONN , 1 , 3
		Session("i_User_OpenID")=RS("i_User_OpenID")
		Session(Session_UserID_Arg)=RS("i_User_ID")
		Session(Session_UserName_Arg)=RS("i_User_Name")
		Session(Session_UserNickName_Arg)=RS("i_User_NickName")
		Session(Session_UserSex_Arg)=RS("i_User_Sex")
		Session(Session_UserClass_Arg)=RS("i_User_Class")
		Session(Session_UserFace_Arg)=RS("i_User_Face")
		Session(Session_RoomID_Arg)=RS("i_Sys_Room_ID")
		Session(Session_LogIP_Arg)=get_IP()
		Session(Session_LogTime_Arg)=now()
		Rw "location.href='/i/"&SysConfig("i_Sys_Config_TemplatePath")&"/Bind.html?"&vbsEscape(t_UserNickName)&"'":Rend
	end if
	RS_End
End Sub

%>