📄 account.jsp
字号:
<%
/**
* $RCSfile: account.jsp,v $
* $Revision: 1.4 $
* $Date: 2000/12/27 22:39:45 $
*/
%>
<%@ page
import="java.io.*,
java.text.*,
java.util.*,
java.net.*,
com.coolservlets.forum.*,
com.coolservlets.forum.util.*"
errorPage="/mainctrl/bbs/error"
%>
<jsp:useBean id="BusinessName" scope="session" class="com.vnex.intranet.pub.BusinessSession" />
<%! final int CREATE = 1;
final int MANAGE = 2;
final int PASSWORD = 3;
final int LOGIN = 4;
final int VIEW = 5;
final int FROMOA = 6;
%>
<% ////////////////////////
// Authorization check
// check for the existence of an authorization token
Authorization authToken = SkinUtils.getUserAuthorization(request,response);
// if the token was null, they're not authorized. Since this skin will
// allow guests to view forums, we'll set a "guest" authentication
// token
if( authToken == null ) {
authToken = AuthorizationFactory.getAnonymousAuthorization();
}
%>
<% // Get parameters
int mode = ParamUtils.getIntParameter(request, "mode", -1);
int userID = ParamUtils.getIntParameter(request, "user", -1);
int forumID = ParamUtils.getIntParameter(request, "forum", -1);
boolean doCreate = ParamUtils.getBooleanParameter(request, "doCreate");
String username = ParamUtils.getParameter(request, "username"); // required to create account
String password = ParamUtils.getParameter(request, "password"); // required to create account
// ADD BY X.J.ZHANG
if ( mode == FROMOA && BusinessName.getDeptId() != -1 )
{
username = BusinessName.getUserName();
password = BusinessName.getPassword();
}
String password2 = ParamUtils.getParameter(request, "password2"); // required to create account
String email = ParamUtils.getParameter(request, "email"); // required to create account
String URL = ParamUtils.getParameter(request, "URL");
String name = ParamUtils.getParameter(request, "name");
String sig = ParamUtils.getParameter(request, "signature");
boolean emailVisible= ParamUtils.getCheckboxParameter(request, "emailVisible");
boolean nameVisible = ParamUtils.getCheckboxParameter(request, "nameVisible");
boolean autoLogin = ParamUtils.getCheckboxParameter(request, "autoLogin");
String message = ParamUtils.getParameter(request, "message");
if (message == null)
message = "";
boolean emailOK = ( email != null && email.length() != 0 );
boolean usernameOK = ( username != null && username.length() != 0 );
boolean passwordOK = ( password != null && password.length() != 0 );
passwordOK = ((mode == LOGIN && passwordOK) || ( mode == FROMOA && passwordOK) || (mode == CREATE && (passwordOK && password.equals(password2))) ||
(mode == MANAGE && ((password == null && password2 == null) || (passwordOK && password.equals(password2)))) );
boolean requiredParamsOK = ( emailOK && usernameOK && passwordOK );
boolean createSuccess = false;
String redirectPage = "/mainctrl/bbs/account?mode=" + mode;
User user = null;
%>
<% // Create a ForumFactory object
ForumFactory forumFactory = ForumFactory.getInstance(authToken);
ProfileManager manager = forumFactory.getProfileManager();
%>
<% // Login in
if (mode == LOGIN || mode ==FROMOA ) {
// check to make sure the username and password are valid (ie, not null or blank)
if( !usernameOK || !passwordOK ) {
System.out.println("\n not userNameOk or password Ok");
message = "登陆失败。请检查您的用户名和密码!";
response.sendRedirect( "/mainctrl/bbs/account?message=" + URLEncoder.encode(message) );
return;
}
else {
try {
// get the user's authorization token
System.out.println("request:"+request);
System.out.println("response:"+response);
System.out.println("username:"+username);
System.out.println("password:"+password);
System.out.println("autoLogin:"+autoLogin);
authToken = SkinUtils.setUserAuthorizationByEncryptedPWD(request, response, username, password, autoLogin);
// redirect to the main page
response.sendRedirect( "/mainctrl/bbs/index" );
return;
}
catch( UnauthorizedException ue ) {
System.out.println("\n catch exception when login the bbs \n:"+ue);
message = "登陆失败。请检查您的用户名和密码!";
response.sendRedirect( "/mainctrl/bbs/account?message=" + URLEncoder.encode(message) );
return;
}
}
}
// Create a new user, or change your account
// check to make sure username, password and email are valid (ie, not null or blank)
else if (doCreate && requiredParamsOK && (mode == CREATE || mode == MANAGE)) {
try {
if (mode == CREATE) {
user = manager.createUser(username, password, email); // throws a UserAlreadyExistsException
message = "帐户创建成功!";
} else {
user = manager.getUser(authToken.getUserID());
message = "帐户修改成功!";
}
if (name != null && !name.equals(user.getName())) {
user.setName(name);
}
if (password != null && mode == MANAGE) {
user.setPassword(password);
}
if (email != null && !email.equals(user.getEmail())) {
user.setEmail(email);
}
if (nameVisible != user.isNameVisible()) {
user.setNameVisible(nameVisible);
}
if (emailVisible != user.isEmailVisible()) {
user.setEmailVisible(emailVisible);
}
// IP, URL and Signature are extended properties:
if (!request.getRemoteAddr().equals(user.getProperty("IP"))) {
user.setProperty("IP", request.getRemoteAddr());
}
if (URL != null && !URL.equals(user.getProperty("URL"))) {
user.setProperty("URL", URL);
}
if (sig != null && !sig.equals(user.getProperty("sig"))) {
user.setProperty("sig", sig);
}
if (mode == CREATE) {
authToken = SkinUtils.setUserAuthorization(request, response, username, password, autoLogin);
}
response.sendRedirect( redirectPage + "&message=" + URLEncoder.encode(message) );
return;
}
catch( UserAlreadyExistsException uaee ) {
message = "对不起,用户已经存在!";
response.sendRedirect( redirectPage +"&message=" + URLEncoder.encode(message) );
return;
}
catch( UserNotFoundException unfe ) {
message = "对不起,不存在此用户!";
response.sendRedirect( redirectPage +"&message=" + URLEncoder.encode(message) );
return;
}
catch( UnauthorizedException ue ) {
java.io.StringWriter sw = new java.io.StringWriter();
ue.printStackTrace(new PrintWriter(sw,true));
message = "您没有授权。" + sw.toString();
response.sendRedirect( redirectPage +"&message=" + URLEncoder.encode(message) );
return;
}
}
// View or Update a users attributes
// check to make sure username, password and email are valid (ie, not null or blank)
else if (!doCreate && (mode == VIEW || mode == MANAGE)) {
try {
if (mode == VIEW) {
// userID? user = manager.getUser(authToken.getUserID());
message = "帐户创建成功!";
} else {
user = manager.getUser(authToken.getUserID());
}
username = user.getUsername();
name = user.getName();
if (name == null) {
name = (mode == VIEW) ? "不可见" : "";
}
email = user.getEmail();
if (email == null) {
email = (mode == VIEW) ? "不可见" : "";
}
nameVisible = user.isNameVisible();
emailVisible = user.isEmailVisible();
URL = user.getProperty("URL");
sig = user.getProperty("sig");
}
catch( UserNotFoundException unfe ) {
message = "对不起,不存在此用户!";
response.sendRedirect( redirectPage +"&message=" + URLEncoder.encode(message) );
return;
}
}
else if (!doCreate && (mode == CREATE)) {
nameVisible = true;
emailVisible = true;
}
%>
<% // header include
String title = "管理您的帐户";
%>
<%@ include file="/skins/bay/header.jsp" %>
<%-- begin breadcrumbs --%>
<table bgcolor="#666666" cellpadding=0 cellspacing=0 border=0 width="600">
<tr>
<td>
<font class="strongw"><a href="/mainctrl/home/index"><font color="#FFFFFF">首页</font></a>>><a href="/mainctrl/communication/main"><font color="#FFFFFF">通信</font></a>>><a href="/mainctrl/bbs/index" class="normal"><font color="#FFFFFF">论坛主页</font></a>
>>
<% if( mode > 0 ) { %>
<a href="/mainctrl/bbs/account" class="normal"><font color="#FFFFFF">用户帐户</font></a>
>
<% if( mode == CREATE ) { %>
创建帐户
<% } else if( mode == MANAGE ) { %>
管理帐户
<% } else if( mode == PASSWORD ) { %>
密码帮助
<% } else if( mode == LOGIN ) { %>
用户登录
<% } else { %>
<% } %>
<% } else { %>
用户登陆
<% } %>
</font>
</td>
</tr>
</table>
<%-- end breadcrubms --%>
<font color="#ff0000"><%= message %></font>
<% if(mode == CREATE || mode == MANAGE) { %>
<% // if we're trying to create a user and there's an error, print a message:
if( !createSuccess && doCreate ) { %>
用户帐户创建失败。请纠正标记字段。
<% } %>
<form action="/mainctrl/bbs/account" method="post">
<table cellspacing=1 cellpadding=2 border=0 bgcolor=#fafafa width="600">
<tr>
<td>
<input type="hidden" name="mode" value="<%= mode %>">
<input type="hidden" name="doCreate" value="true">
</td>
</tr>
<tr bgcolor="#fafafa">
<td>
<font class="strong">用户名:</font>
<% if( !usernameOK && doCreate ) { %>
<font color="#ff0000" face="arial,helvetica"><font class="strong">*</font></font>
<% } %>
</td>
<td>
<% if (mode == CREATE) { %>
<input type="text" name="username" value="<%= username == null ? "" : username %>" size=20 maxlength=30 class=text> * (带*为必填内容)
<% } else {%>
<input type="hidden" name="username" value="<%= username == null ? "" : username %>" class=text>
<%= username == null ? "[error]" : username %> (带*为必填内容)
<% } %>
</td>
</tr>
<tr bgcolor="#e0e0e0">
<td>
<font class="strong">口令:</font>
<% if( !passwordOK && doCreate ) { %>
<font color="#ff0000" face="arial,helvetica"><font class="strong">*</font></font>
<% } %>
</td>
<td><input class=text type="password" name="password" value=""> *
<% if (mode == CREATE) { %>
<% } %>
</td>
</tr>
<tr bgcolor="#fafafa">
<td >
<font class="strong">口令确认:</font>
<% if( !passwordOK && doCreate ) { %>
<font color="#ff0000" face="arial,helvetica"><font class="strong">*</font></font>
<% } %>
</td>
<td><input class=text type="password" name="password2" value=""> *
<% if (mode == CREATE) { %>
<% } %>
</tr>
<tr bgcolor="#e0e0e0">
<td>
<font class="strong">Email地址:</font>
<% if( !emailOK && doCreate ) { %>
<font color="#ff0000" face="arial,helvetica"><font class="strong">*</font></font>
<% } %>
</td>
<td><input class=text type="text" name="email" value="<%= email == null ? "" : email %>" size=30 maxlength=30> *
<% if (mode == CREATE) { %>
<% } %>
</td>
</tr>
<tr bgcolor="#fafafa">
<td><font class="strong">姓名:</font></td>
<td><input class=text type="text" name="name" value="<%= name == null ? "" : name %>" size=40 maxlength=50></td>
</tr>
<tr bgcolor="#e0e0e0">
<td><font class="strong">URL:</font></td>
<td><input class=text type="text" name="URL" value="<%= URL == null ? "" : URL %>" size=40 maxlength=255></td>
</tr>
<tr bgcolor="#fafafa">
<td><font class="strong">签字档:</font><br>(不得多于224个字符,或112个汉字)</td>
<td><textarea cols=40 rows=4 name="signature" wrap="virtual"><%= sig == null ? "" : sig %></textarea></td>
</tr>
<tr bgcolor="#e0e0e0">
<td><font class="strong">显示姓名:</font></td>
<td><input class=text type="checkbox" name="nameVisible" <%= nameVisible ? "checked" : "" %>></td>
</tr>
<tr bgcolor="#fafafa">
<td><font class="strong">显示Email:</font></td>
<td><input class=text type="checkbox" name="emailVisible" <%= emailVisible ? "checked" : "" %>></td>
</tr>
<% if (mode == CREATE) { %>
<tr bgcolor="#e0e0e0">
<td><font class="strong">自动登录:</font></td>
<td><input class=text type="checkbox" name="autoLogin"></td>
</tr>
<% } %>
<tr>
<td><br></td>
<td><input class=text type="submit" value="<%= mode == CREATE ? "创建帐户" : "修改帐户" %>"></td>
</tr>
</table>
</form>
<% } else if( mode == PASSWORD ) { %>
<font face="verdana" >
<font class="strong">发送密码</font>
<li> 还未实现
</font>
<%-- default mode: check if the authorization token references an anonymous user -- that means
the user is logged in already so we should display her account options
--%>
<% } else { %>
<% user = manager.getUser( authToken.getUserID() );
boolean anonUser = user.isAnonymous();
%>
<% if (anonUser) { %>
<form action="/mainctrl/bbs/account" method="get">
<input type="hidden" name="mode" value="<%= LOGIN %>">
<table cellspacing=1 cellpadding=2 border=0 width="600">
<tr bgcolor="#fafafa">
<td colspan="2">如果没有帐户,请<a href="/mainctrl/bbs/account?mode=<%= CREATE %>" ><font class=strong>创建一个</font></a>。</td>
</tr>
<tr bgcolor="#e0e0e0">
<td colspan="2">我要<a href="/mainctrl/bbs/index" ><font class=strong>匿名访问</font></a></td>
</tr>
<tr bgcolor="#fafafa">
<td align="right"><font face="verdana" class=strong> 用户名:</font></td>
<td><input class=text type="text" name="username" size="20"></td>
</tr>
<tr bgcolor="#e0e0e0">
<td align="right"><font face="verdana" class=strong> 口令:</font></td>
<td><input class=text type="password" name="password" size="20"></td>
</tr>
<tr bgcolor="#fafafa">
<td align="right"><font face="verdana" class=strong> 自动登陆:</font></td>
<td><input class=text type="checkbox" name="autoLogin"></td>
</tr>
<tr bgcolor="#e0e0e0">
<td align="center" colspan="2"><input class=text type="submit" value="登录"></td>
</tr>
</table>
</form>
<% } else { %>
<table class=title cellspacing=1 cellpadding=2 border=0 width="600">
<tr bgcolor="#fafafa">
<td>您-<font class="strong"><%= user.getUsername() %></font>已经登录。</td>
</tr>
<tr bgcolor="#e0e0e0">
<td>我要[<a href="/mainctrl/bbs/index?logout=true" class="normal">退出</a>]</td>
</tr>
</table>
<% } %>
<% } %>
<%@ include file="/skins/bay/footer.jsp" %>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -