<!--#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")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" /> 
<title>asp和ucenter通信实例- ASP整合UC实例 </title> 
<meta name="keywords" content="ASP整合UC接口案例,
ASP ucenter整合代码,asp2ucenter,ASP整合UC代码实例,asp ucenter 1.6,ASP整合Discuz X2" /> 
<meta name="description" content="ASP整合UC接口案例,ASP整合UC代码实例下载，ASP整合UCenter无错版本" /> 
<script>
function $(id) {
	return document.getElementById(id);
}

function pmwin(action, param) {
	var objs = document.getElementsByTagName("OBJECT");
	if(action == 'open') {
		for(i = 0;i < objs.length; i ++) {
			if(objs[i].style.visibility != 'hidden') {
				objs[i].setAttribute("oldvisibility", objs[i].style.visibility);
				objs[i].style.visibility = 'hidden';
			}
		}
		var clientWidth = document.body.clientWidth;
		var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
		var pmwidth = 800;
		var pmheight = clientHeight * 0.9;
		if(!$('pmlayer_bg')) {
			div = document.createElement('div');div.id = 'pmlayer_bg';
			div.style.position = 'absolute';
			div.style.left = div.style.top = '0px';
			div.style.width = '100%';
			div.style.height = (clientHeight > document.body.scrollHeight ? clientHeight : document.body.scrollHeight) + 'px';
			div.style.backgroundColor = '#000';
			div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=80,finishOpacity=100,style=0)';
			div.style.opacity = 0.8;
			div.style.zIndex = '998';
			$('append_parent').appendChild(div);
			div = document.createElement('div');div.id = 'pmlayer';
			div.style.width = pmwidth + 'px';
			div.style.height = pmheight + 'px';
			div.style.left = ((clientWidth - pmwidth) / 2) + 'px';
			div.style.position = 'absolute';
			div.style.zIndex = '999';
			$('append_parent').appendChild(div);
			$('pmlayer').innerHTML = '<div style="width: 800px; background: #666666; margin: 5px auto; text-align: left;">' +
				'<div style="width: 800px; height: ' + pmheight + 'px; padding: 1px; background: #FFFFFF; border: 1px solid #7597B8; position: relative; left: -6px; top: -3px;">' +
				'<a href="###" onclick="pmwin(\'close\')"><img style="position: absolute;right: 20px;top: 15px" border="0" src="close.gif" title="关闭" /></a>' +
				'<iframe id="pmframe" name="pmframe" style="width:' + pmwidth + 'px;height:100%" allowTransparency="true" frameborder="0"></iframe></div></div>';
		}
		$('pmlayer_bg').style.display = '';
		$('pmlayer').style.display = '';
		$('pmlayer').style.top = ((clientHeight - pmheight) / 2 + scrollTop) + 'px';
		if(!param) {
			pmframe.location = '<%=Urlself%>?act=pmwin';
		} else {
			pmframe.location = '<%=Urlself%>?act=pmwin&' + param;
		}
		document.body.style.overflow = "hidden";
		document.body.scroll = "no";
	} else if(action == 'close') {
		for(i = 0;i < objs.length; i ++) {
			if(objs[i].attributes['oldvisibility']) {
				objs[i].style.visibility = objs[i].attributes['oldvisibility'].nodeValue;
				objs[i].removeAttribute('oldvisibility');
			}
		}
		$('pmlayer').style.display = 'none';
		$('pmlayer_bg').style.display = 'none';
		document.body.style.overflow = "auto";
		document.body.scroll = "auto";
	}
}

</script>
<style>
*{ word-wrap:break-word; outline:none; }
body, td, input, textarea, select, button{ color:#666; font:12px "Lucida Grande", Verdana, Lucida, Helvetica, Arial, 'Simsun', sans-serif; }
body, ul, dl, dd, p, h1, h2, h3, h4, h5, h6, form, fieldset { margin:0; padding:0; }
h1, h2, h3, h4, h5, h6{ font-size:12px; }
body{ background:#FFF;margin:10px;padding:10px; }

h2{ font-size:14px;margin-bottom:10px; }
a{ color:#3399FF; text-decoration:none; }
	a:hover { text-decoration:underline; }
	a img{ border:none; }
em, cite, th{ font-style:normal; font-weight:normal; }
table{ border-collapse:collapse; }
.box {text-align:left;margin:10px 2px;}
.box p{line-height:1.5;}
.menu dd {width:80px;float:left}
.menu dt {float:left}
.cl {clear:both;}
</style>
</head>
<body>
<%

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 

response.write "<hr />"

 If session("login_user")="" Then 
	'用户未登录
	response.write "<a href='"&Urlself & "?act=login'>登录</a> "
	response.write "<a href='"&Urlself & "?act=register'>注册</a> "
 else 
	'用户已登录
	response.write "<div id='append_parent'></div>"
	response.write "<dl class='menu'><dd><img src='"&UC_API&"/avatar.php?uid="&session("uid")&"&type=virtual&size=small' /><br>"
	response.write session("login_user") &"("&session("uid")&") </dd> <dt><a href='"&Urlself&"'>首页</a> <a href='"&Urlself & "?act=logout'>退出</a>"
	response.write " <a href='"&Urlself & "?act=avatar'>设置头像</a>"
	response.write " <a href='"&Urlself & "?act=pmlist'>短消息列表</a> "
	if IsNull(newpm) Then response.write "<font color='red'>New!("&newpm&")</font> "
	response.write "<a href='###' onclick=""pmwin('open')"">进入短消息中心</a>"
	response.write " <a href='"&Urlself & "?act=friend'>好友</a> "
	response.write " </dt> </dl>"
	response.write " <div class=cl></div><hr>"
	response.write " <form action='"&Urlself & "' method='post'>旧密码 <input type=text name='oldpassword'><br>新密码 <input type=text name='newpassword' value=''><INPUT TYPE='submit' name='submit'><INPUT TYPE='hidden' NAME='act' value='modifypw'></form>"
End If 

%>

<div style="display:none"><script src="http://s11.cnzz.com/stat.php?id=1378864&web_id=1378864" language="JavaScript"></script></div>
</body>
</html>



<%
Sub U_ModifyPW()
	If  isempty(request("submit")) Then 

	else
		If session("login_user")="" Then 
			response.write "请先登录，再修改个人资料"
		Else
			oldpassword = request("oldpassword")
			newpassword = request("newpassword")
			If newpassword="" Or oldpassword="" Then
				response.write "请输入新密码和旧密码!"
			Else			
				uc_result = uc_user_edit( session("login_user"), 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 if
	End if
End Sub 

Sub U_Login()
	if(isempty(request("submit"))) Then 
		'登录表单
		response.write "<form method='post' action='"&Urlself  & "?act=login'>"
		response.write "登录:"
		response.write "<dl><dt>用户名</dt><dd><input name='username'></dd>"
		response.write "<dt>密码</dt><dd><input name='password' type='password'></dd></dl>"
		response.write "<input name='submit' type='submit'> "
		response.write "</form>"
	else 
		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保存登陆信息
			session("login_user") = username
			session("uid") = uid
			'生成同步登录的代码
			ucsynlogin = uc_user_synlogin(uid) '返回javascript分别调用各个应用进行登陆
			response.write "登录成功"& ucsynlogin & "，<a href='"&Urlself  & "'>继续</a>"
		 elseif(uid = "-1") Then 
			response.write "用户不存在,或者被删除"
		 elseif(uid = "-2") Then 
			response.write "密码错"
		 else 
			response.write "未定义"
		End If 
	End If
End Sub 
'----------------------------------------
Sub U_Logout()
	ucsynlogin = uc_user_synlogout() '返回javascript分别调用各个应用进行退出
	response.write ucsynlogin
	session("login_user")=""
	response.write "成功退出！<a href='"&Urlself  & "'>继续</a>"
End Sub 
'----------------------------------------
Sub U_Register_nodb()
	If request("submit")="" then 
		'注册表单
		response.write "<form method=""post"" action="""&Urlself&"?act=register"">"
		response.write "注册:"
		response.write "<dl><dt>用户名</dt><dd><input name=""username""></dd>"
		response.write "<dt>密码</dt><dd><input name=""password""></dd>"
		response.write "<dt>Email</dt><dd><input name=""email""></dd></dl>"
		response.write "<input name=""submit"" type=""submit"">"
		response.write "</form>"
	 else
		'在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 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 

%>