<!--#include file="./uc_client/client.asp"-->
<%
'**************************************************
' ASP-Client to UCenter-Server 通信应用范例
' ************************************************

Dim username,password,email,Urlself
username= request("username")
password= request("password")
email = request("email")
Urlself = Request.ServerVariables("Script_Name")
Dim act 
act= Trim(request("act"))
Select Case act
	case "login"		'UCenter 用户登录的 Example 代码
		Call U_Login()
	case "logout"		'UCenter 用户退出的 Example 代码
		Call U_Logout()
	case "modifypw"		'UCenter 用户修改密码的 Example 代码
		Call U_ModifyPW()
	case "register"		'UCenter 用户注册的 Example 代码
		Call U_Register_nodb()
	case "pmlist"		'UCenter 未读短消息列表的 Example 代码
		Call U_pmlist()
	case "pmwin"		'UCenter 短消息中心的 Example 代码
		Call U_pmwin()
	case "friend"		'UCenter 好友的 Example 代码
		Call U_friend()
	case "avatar"		'UCenter 设置头像的 Example 代码
		Call U_avatar()
	Case Else
		response.write "请选择需要的操作！"
End Select 

Sub U_ModifyPW()
	oldpassword = request("oldpassword")
	newpassword = request("newpassword")
	If newpassword="" Or oldpassword="" Then
		response.write "请输入新密码和旧密码!"
	Else			
		uc_result = uc_user_edit(username, oldpassword, newpassword,"",0,"","")
		uc_result =CInt(uc_result)
		If uc_result =-1 Then 
			response.write "旧密码不正确"
		ElseIf uc_result = -4 Then 
			response.write "Email 格式有误"
		ElseIf uc_result = -5 Then 
			response.write "Email 不允许注册"
		ElseIf uc_result = -6 then
			response.write "该 Email 已经被注册"
		ElseIf uc_result = 0 then
			response.write "没有做任何修改"
		Else
			response.write "修改成功！"&uc_result
		End If 				
	End If 
End Sub 

Sub U_Login()
	Dim uid
	uid = Empty 
	'通过接口判断登录帐号的正确性，返回值为数组
	XML_login = uc_user_login(username,password) ' 需要xml转化提取数组出来
	'response.write XML_login
	arr_login =  xml2array(XML_login)

	uid = arr_login(0)
	username= arr_login(1)
	password= arr_login(2)
	email = arr_login(3)

	If (uid > "0") Then 
		'用户登陆成功，设置登陆成功的标志，您可以采用Cookies保存登陆信息
		'生成同步登录的代码
		ucsynlogin = uc_user_synlogin(uid) '返回javascript分别调用各个应用进行登陆
		response.write "登录成功|||"& ucsynlogin
	 elseif(uid = "-1") Then 
		response.write "用户不存在,或者被删除"
	 elseif(uid = "-2") Then 
		response.write "密码错"
	 else 
		response.write "未定义"
	End If 
End Sub 
'----------------------------------------

'----------------------------------------
Sub U_Register_nodb()
	'在UCenter注册用户信息
	uid = uc_user_register(username,password,email)
	uid =CInt(uid)
	if(uid <= 0) Then 
		if(uid = -1) Then  
			response.write "用户名不合法"
		 elseif(uid = -2) Then
			response.write "包含要允许注册的词语"
		 elseif(uid = -3) Then
			response.write "用户名已经存在"
		 elseif(uid = -4) Then
			response.write "Email 格式有误"
		 elseif(uid = -5) Then
			response.write "Email 不允许注册"
		 elseif(uid = -6) Then
			response.write "该 Email 已经被注册"
		 else 
			response.write "未定义"
		End if
	 else 
		'注册成功，设置 Cookie，加密直接用 uc_authcode 函数，用户使用自己的函数
		session("login_user") = username
		session("uid") = uid
		response.write "注册成功<br><a href="""&Urlself&""">继续</a>"
	End If
End Sub 

'----------------------------------------
Sub U_pmlist()
	response.write "此模块没有编写,请自行完成!<br><br>"
End Sub 
'----------------------------------
Sub U_pmwin()
	response.write "此模块没有编写,请自行完成!<br><br>"
End Sub 
'-----------------------------
Sub U_friend()
	response.write "此模块没有编写,请自行完成!<br><br>"
End Sub 

'-----------------------------
Sub U_avatar()
	str_avatar = uc_avatar(session("uid"),"virtual")
	response.write str_avatar
End Sub 
%>