<!--#include file="conn.asp"-->
<!--#include file="../Inc/md5.asp"-->
<%
dim UserName,userpassword,PwdConfirm,UserQuesion,UserAnswer,user_01,user_02,user_03,user_05,user_06,useremail

passcode=request("vcode")
GetCode=replace(trim(session("GetCode")),"'","")

UserName=trim(request("username"))
userpassword=trim(request("password"))
useremail=trim(request("usermail"))
successUrl=trim(request("successUrl"))

select case request("op")
case "shopregist" 

'验证码错误！/////////////////////////////////////////////////////////////////////////////////
if not passcode=GetCode then
	response.Write("jsonp_callback('{""msg"":""验证码输入错误"",""result"":""2"",""data"":""""}')")
	response.End()
end if	

	dim sqlCheckReg,rsCheckReg
	sqlCheckReg="select * from [com_user] where UserName='" & UserName & "'"
	set rsCheckReg=server.createobject("adodb.recordset")
	rsCheckReg.open sqlCheckReg,conn,1,1
	if not(rsCheckReg.bof and rsCheckReg.eof) then
		response.Write("jsonp_callback('{""msg"":""该用户名不可用，请更换用户名"",""result"":""1"",""data"":""""}')")
		response.end()
	end if
	rsCheckReg.close
	set rsCheckReg=nothing	
	
	dim sqlCheckRegm,rsCheckRegm
	sqlCheckRegm="select * from [com_user] where useremail='" & useremail & "'"
	set rsCheckRegm=server.createobject("adodb.recordset")
	rsCheckRegm.open sqlCheckRegm,conn,1,1
	if not(rsCheckRegm.bof and rsCheckRegm.eof) then
		response.Write("jsonp_callback('{""msg"":""该邮箱不可用或已经存在，请更换邮箱"",""result"":""1"",""data"":""""}')")
		response.end()
	end if
	rsCheckRegm.close
	set rsCheckRegm=nothing	
	

	dim sqlReg,rsReg
	sqlReg="select * from [com_user] where useremail='" & useremail & "'"
	set rsReg=server.createobject("adodb.recordset")
	rsReg.open sqlReg,conn,1,3
		rsReg.addnew
		rsReg("UserName")=UserName
		rsReg("userpassword")=md5(userpassword)
		rsReg("useremail")=useremail
		'rsReg("UserQuesion")=UserQuesion
		'rsReg("UserAnswer")=md5(UserAnswer)
		'rsReg("user_05")=user_05
		rsReg("Usersex")=1
		rsReg("adddate")=Now()

if request.Cookies("shopxp")("dingdanusername")="" then
username_c=now()
username_c=replace(trim(username_c),"-","")
username_c=replace(username_c,":","")
username_c=replace(username_c," ","")
response.Cookies("shopxp")("dingdanusername")=username_c
else
username_c=request.Cookies("shopxp")("dingdanusername")
end if

set rs2=server.CreateObject("adodb.recordset")
rs2.open "select username,niming,userid from shopxp_action where username='"&username_c&"'",conn,1,3
if not rs2.bof or not rs2.eof then
while not rs2.eof or not rs2.eof
rs2("userid")=rsReg("UserID")
rs2("niming")=0
rs2("username")=rsReg("username")
rs2.movenext
wend
end if
rs2.close
set rs2=nothing

		rsReg.update
		
session("user_xxx_name")=UserName
session("UserID")=rsReg("UserID")
session("user_xxx_mail")=useremail
response.Write("jsonp_callback('{""msg"":""恭喜您注册成功!"",""data"":{""user"" : {""userId"":"""&rsReg("UserID")&""",""username"":"""&rsReg("username")&"""}},""result"":""0""}')")		

	rsReg.close
	set rsReg=nothing


case "shoplogin" 

'验证码错误！/////////////////////////////////////////////////////////////////////////////////
if not passcode=GetCode then
	response.Write("jsonp_callback('{""msg"":""验证码输入错误"",""result"":""2"",""data"":""""}')")
	response.End()
end if	

userpassword=md5(userpassword)
set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from [com_user] where (username='"&useremail&"' or  useremail='"&useremail&"') and UserPassword='"&userpassword&"'" ,conn,1,3
if not(rs.bof and rs.eof) then

	session("user_xxx_mail")=useremail
	session("user_xxx_name")=rs("username")
	session("user_xxx_vip")=rs("reglx")
	session("UserID")=rs("UserID")
	session("niming")=rs("niming")
	rs("lastlogin")=now()
	rs("logins")=rs("logins")+1
	
	rs("userlastip")=Request.ServerVariables("REMOTE_ADDR")
	
	
		if request.Cookies("shopxp")("dingdanusername")="" then
		username_c=now()
		username_c=replace(trim(username_c),"-","")
		username_c=replace(username_c,":","")
		username_c=replace(username_c," ","")
		response.Cookies("shopxp")("dingdanusername")=username_c
		else
		username_c=request.Cookies("shopxp")("dingdanusername")
		end if
	
	set rs2=server.CreateObject("adodb.recordset")
	rs2.open "select username,niming,userid from shopxp_action where username='"&username_c&"'",conn,1,3
		if not rs2.bof or not rs2.eof then
		while not rs2.eof or not rs2.eof
		rs2("userid")=rs("UserID")
		rs2("niming")=0
		rs2("username")=rs("username")
		rs2.movenext
		wend
		end if
	rs2.close
	set rs2=nothing
	
	rs.Update
	rs.Close
	set rs=nothing
	username=trim(request("username"))
	
	response.Write("jsonp_callback('{""msg"":""登录成功!"",""data"":{""user"" : {""userId"":"""&session("UserID")&""",""username"":"""&session("user_xxx_name")&"""}},""result"":""0"",""sUrl"":"""&successUrl&"""}')")		
	
	'if request("linkaddress")="" then
	'response.redirect request.servervariables("http_referer")
	'else
	'response.redirect "Member.asp"
	'end if
	
	
else
response.Write("jsonp_callback('{""msg"":""对不起，您的用户名或密码有误，请重新登录！"",""result"":""1"",""data"":""""}')")
end if


case "shoplogout"
session("user_xxx_name")=""
session("UserID")=""
session("niming")=""
response.Cookies("shopxp")("dingdanusername")=""

response.Write("jsonp_callback('{""msg"":""成功退出!"",""result"":""0""}')")	
'response.Redirect("../index.asp")

end select


%> 



