<!--#INCLUDE FILE="setup.asp" -->
<!--#INCLUDE FILE="checkuser.asp" -->
<!--#INCLUDE FILE="theme.asp" -->
<!--#INCLUDE FILE="include/char.asp" -->
<!-- #include file="inc/UPIConfig.asp" -->
<!--#include file="inc/md5.asp"-->
<%
'完整调用形式：
'<script src="Interface.asp?action=操作类型&name=用户名&Md5Info=验证串&pass=密码&lock=是否锁定&question=提示问题&answer=答案&email=电子邮件&sex=性别&save=Cookies保存选项"
'action、name、Md5Info是必填参数
'删除用户时不需要其它参数
'更新资料时，提供所要更新的信息即可
'注意：这里传递的用户密码为32位MD5加密
Dim Action,useremail,username,userpassword,question,answer,babynam,babybirth


Dim PEMd5Info

UpiMd5Info = UCase(Trim(Request("Md5Info")))
Action = Trim(Request("action"))
username = Trim(Request("name"))
userpassword = Trim(Request("pass"))
If Len(userpassword) = 32 Then userpassword = Mid(userpassword,9,16)
question = Trim(Request("question"))
answer = Trim(Request("answer"))
If Len(answer) = 32 Then answer = Mid(answer,9,16)
UpiUserSex = Trim(Request("sex"))
userid=username
email=Trim(Request("email"))
if(UpiUserSex="1") Then
sex="false"
else
sex="true"
end if
useremail = Trim(Request("email"))

If Not (Action = "" or username = "" or UpiMd5Info = "") Then
	PEMd5Info = MD5(username&SecurityKey,32)
	'If UpiMd5Info = UCase(PEMd5Info) Then
		Select Case Action
		Case "AddUser"
		'response.write username&userpassword
			Call AddUser()
		Case "LoginUser"
			Call LoginUser()
		Case "LogoutUser"
			Call LogoutUser()
		Case "ModifyInfo"
			Call ModifyUserInfo()
		Case "DelUser"
			Call DelUser()
		End Select
'End If
End If


Sub AddUser()
Set rs = Server.CreateObject("ADODB.Recordset")
sql2="select * from student where userid='"&username&"'"
    rs.Open sql2,Conn,1,3
    if not  rs.eof then
	response.write "该用户已经存在！"
	aa=1
	end if
	rs.close
	
if aa<1 then
Set rs1 = Server.CreateObject("ADODB.Recordset")
sql2="select * from student"
    rs1.Open sql2,Conn,1,3
	rs1.addnew
	rs1("userid") = username
	rs1("userpwd") =userpassword
	if question<>"" then
		rs1("question")=question
	end if
	if answer<>"" then
		rs1("answer")=answer
	end if
	'rs("realname") = realname
	rs1("email") =useremail
	rs1("sex")=sex
     response.write "OK!"
	rs1.update
	rs1.close
end if
	Conn.Execute("update config Set UserNum=UserNum+1")

	'recommender=trim(checkstr(Request("recommender")))
	'if recommender<>"" Then 
	'	Conn.Execute("update student Set point=point+"&PointSet(25)&" where userid='"&recommender&"'")
	'End if


	MailFrom=StrVar(2):Mailto=email
	mailtopic="感谢您在"&StrVar(1)&"注册！"
	MailBody="您好："&vbCrLf&vbCrLf&_
	"欢迎您加入"&StrVar(1)&"，我们将提供给您最好的服务！"&vbCrLf&_
	"同学录地址："&SchoolmateURL&vbCrLf&vbCrLf&string(55,"-")&vbCrLf&_
	"您的注册信息如下："&vbCrLf&_
	"用户名："&userid&""&vbCrLf&_
	"密  码："&userpassword&""&vbCrLf&_
	"您随时可以使用用户资料修改您的密码"&vbCrLf&string(55,"-")&vbCrLf&vbCrLf&_
	"再次感谢您注册本系统，让我们一起来建设这个网上家园！"

	Select Case IntVar(5)
	Case 1
		Call jmail_smtp()
	Case 2
		Call Cdonts()
	Case 3
		Call aspemail()
	Case 4
		Call jmail_msg()
	Case Else
		SendMailStatus=""
	End Select


	sender=StrVar(1)
	title=StrVar(1)&"欢迎您的到来"
	body=StrVar(1)&"全体管理人员欢迎您的到来"&vbLf&"如有任何疑问请及时[email="&StrVar(2)&"]联系系统管理员[/email]。"&vbLf&"如有任何使用上的问题请查看同学录帮助。"&vbLf&"感谢您注册本系统，让我们一起来建设这个网上家园！"
	sql="insert into message(incept,sender,title,content,sendtime,flag,issend,delS) values('"&userid&"','"&StrVar(1)&"','"&title&"','"&body&"',Now(),0,1,2)"
	Conn.Execute(sql)

	userip1 = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
	userip2 = Request.ServerVariables("REMOTE_ADDR")
    if userip1 = ""  then lastip=userip2 else lastip=userip1

	LoginSQL="update student Set point=point+"&PointSet(1)&",lastip='"&lastip&"' where userid='"&userid&"'"
	conn.execute(LoginSQL)
	response.cookies("fytxl")("fystud")=username
	response.cookies("fytxl")("fypasswd")=userpassword
	response.cookies("fytxl")("logintime")=Now()
    session("fytxl")=userid
	'RURL="Default.asp"
	'Rtitle="注册同学录成功"
	'if SendMailStatus="0K" then
	'	Rmsg="感谢您注册"&StrVar(1)&"!您的注册信息和密码已经发往您的邮箱。"
	'end if
	'Rmsg=Rmsg&"<br><ul><li><a href=Default.asp>返回同学录首页面</a></li></ul>"
	'Call top(1,1)
	'if BoolVar(1) Then	Response.Write "<bgsound src=""sound/logon.wav"" border=0>"
	'Redirect 4,RURL,Rtitle,Rmsg
end sub

Sub LoginUser()
	lastip = Request.ServerVariables("REMOTE_ADDR")

	LoginSQL="update student Set point=point+"&PointSet(1)&",visitcount=visitcount+1,lastlogin=now(),lastip='"&lastip&"' where userid='"&userid&"'"
	conn.execute(LoginSQL)
	response.cookies("fytxl")("fystud")=userid
	Set rs = Server.CreateObject("ADODB.Recordset")
   sql="select * from student where userid='"&userid&"'"
	rs.Open sql,Conn,1,1
	response.cookies("fytxl")("fypasswd")=rs("userpwd")
	response.cookies("fytxl")("logintime")=now()
	session("fytxl")=userid
	rs.close
	set rs=nothing
End Sub

Sub LogoutUser()
	response.cookies("fytxl")("fystud")=""
	
	response.cookies("fytxl")("fypasswd")=""
	response.cookies("fytxl")("visitedclasses")=""
	response.cookies("fytxl")("logintime")=""
	session("fytxl")=""
	RemoveUser="delete from online where userid='"&membername&"'"
	Conn.Execute RemoveUser
	Server.Transfer "Default.asp"
End Sub

Sub ModifyUserInfo()
	
	Dim Rs,sql
	Dim ErrMsg
	Set Rs = Server.CreateObject("ADODB.Recordset")

	sql = "Select * from student where userid='"&username&"'"
	Rs.open sql,Conn,1,3

	if Rs.eof and Rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>该用户名不存在！"
		response.write ErrMsg
		Exit Sub
	End if

		Rs("question")=question
		Rs("answer")=answer
	    Rs("email")=trim(email)
	Rs.Update
	response.write rs("email")&"------------"
	Rs.close
	response.write "您已经成功的修改了您的个人信息和个人选项。"

End Sub

Sub DelUser()

conn.execute "delete from student where userid in ("&username&") "

conn.close

End Sub

%>