createUser.jsp
资源名称:NetOffice.rar [点击查看]
上传用户:guhaomin
上传日期:2007-06-10
资源大小:23203k
文件大小:8k
源码类别:
电子政务应用
开发平台:
Java
- <%
- /**
- * $RCSfile: createUser.jsp,v $
- * $Revision: 1.3 $
- * $Date: 2000/12/18 02:06:21 $
- */
- %>
- <%@ page import="java.util.*,
- java.net.URLEncoder,
- com.coolservlets.forum.*,
- com.coolservlets.forum.util.*,
- com.coolservlets.forum.util.admin.*"%>
- <jsp:useBean id="adminBean" scope="session"
- class="com.coolservlets.forum.util.admin.AdminBean"/>
- <% ////////////////////////////////
- // Jive authorization check
- // check the bean for the existence of an authorization token.
- // Its existence proves the user is valid. If it's not found, redirect
- // to the login page
- Authorization authToken = adminBean.getAuthToken();
- if( authToken == null ) {
- response.sendRedirect( "/mainctrl/bbs/admin" );
- return;
- }
- %>
- <% ////////////////////
- // Security check
- // make sure the user is authorized to administer users:
- ForumFactory forumFactory = ForumFactory.getInstance(authToken);
- ForumPermissions permissions = forumFactory.getPermissions(authToken);
- boolean isSystemAdmin = permissions.get(ForumPermissions.SYSTEM_ADMIN);
- boolean isUserAdmin = permissions.get(ForumPermissions.USER_ADMIN);
- // redirect to error page if we're not a user admin or a system admin
- if( !isUserAdmin && !isSystemAdmin ) {
- response.sendRedirect("error.jsp?msg="
- + URLEncoder.encode("您没有权限管理用户!"));
- return;
- }
- %>
- <% //////////////////////////////////
- // error variables for parameters
- boolean errorEmail = false;
- boolean errorUsername = false;
- boolean errorNoPassword = false;
- boolean errorNoConfirmPassword = false;
- boolean errorPasswordsNotEqual = false;
- // error variables from user creation
- boolean errorUserAlreadyExists = false;
- boolean errorNoPermissionToCreate = false;
- // overall error variable
- boolean errors = false;
- // creation success variable:
- boolean success = false;
- %>
- <% ////////////////////
- // get parameters
- String name = ParamUtils.getParameter(request,"name");
- String email = ParamUtils.getParameter(request,"email");
- String username = ParamUtils.getParameter(request,"username");
- String password = ParamUtils.getParameter(request,"password");
- String confirmPassword = ParamUtils.getParameter(request,"confirmPassword");
- boolean usernameIsEmail = ParamUtils.getCheckboxParameter(request,"usernameIsEmail");
- boolean nameVisible = !ParamUtils.getCheckboxParameter(request,"hideName");
- boolean emailVisible = !ParamUtils.getCheckboxParameter(request,"hideEmail");
- boolean doCreate = ParamUtils.getBooleanParameter(request,"doCreate");
- %>
- <% ///////////////////////////////////////////////////////////////////
- // trim up the passwords so no one can enter a password of spaces
- if( password != null ) {
- password = password.trim();
- if( password.equals("") ) { password = null; }
- }
- if( confirmPassword != null ) {
- confirmPassword = confirmPassword.trim();
- if( confirmPassword.equals("") ) { confirmPassword = null; }
- }
- %>
- <% //////////////////////
- // check for errors
- if( doCreate ) {
- if( email == null ) {
- errorEmail = true;
- }
- if( username == null ) {
- errorUsername = true;
- }
- if( password == null ) {
- errorNoPassword = true;
- }
- if( confirmPassword == null ) {
- errorNoConfirmPassword = true;
- }
- if( password != null && confirmPassword != null
- && !password.equals(confirmPassword) )
- {
- errorPasswordsNotEqual = true;
- }
- errors = errorEmail || errorUsername || errorNoPassword
- || errorNoConfirmPassword || errorPasswordsNotEqual;
- }
- %>
- <% ////////////////////////////////////////////////////////////////
- // if there are no errors at this point, start the process of
- // adding the user
- ProfileManager profileManager = null;
- if( !errors && doCreate ) {
- // get a profile manager to edit user properties
- profileManager = forumFactory.getProfileManager();
- try {
- User newUser = profileManager.createUser(username,password,email);
- newUser.setName( name );
- newUser.setEmailVisible( emailVisible );
- newUser.setNameVisible( nameVisible );
- success = true;
- }
- catch( UserAlreadyExistsException uaee ) {
- errorUserAlreadyExists = true;
- errorUsername = true;
- errors = true;
- }
- catch( UnauthorizedException ue ) {
- errorNoPermissionToCreate = true;
- errors = true;
- }
- }
- %>
- <% //////////////////////////////////////////////////////////////////////
- // if a user was successfully created, say so and return (to stop the
- // jsp from executing
- if( success ) {
- response.sendRedirect("users.jsp?msg="
- + URLEncoder.encode("用户创建成功!"));
- return;
- }
- %>
- <html>
- <head>
- <title></title>
- <link rel="stylesheet" href="style/global.css">
- </head>
- <body background="images/shadowBack.gif" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
- <% ///////////////////////
- // pageTitleInfo variable (used by include/pageTitle.jsp)
- String[] pageTitleInfo = { "用户", "创建用户" };
- %>
- <% ///////////////////
- // pageTitle include
- %><%@ include file="include/pageTitle.jsp" %>
- <p>
- <% // print error messages
- if( !success && errors ) {
- %>
- <p><font color="#ff0000">
- <% if( errorUserAlreadyExists ) { %>
- 用户名 "<%= username %>" 已经存在,请另选一个。
- <% } else if( errorNoPermissionToCreate ) { %>
- 你没有创建用户的权限。
- <% } else { %>
- 产生一般错误,请检查输入字段,然后再试。
- <% } %>
- </font><p>
- <% } %>
- <p>
- <font size="-1">
- 这里创建的用户,只有默认的设置。
- 一旦你创建了这个用户之后,你需要编辑他们的属性。
- </font>
- <p>
- <%-- form --%>
- <form action="createUser.jsp" method="post" name="createForm">
- <input type="hidden" name="doCreate" value="true">
- <b>新建用户信息</b>
- <p>
- <table bgcolor="#999999" cellspacing="0" cellpadding="0" border="0" width="95%" align="right">
- <td>
- <table bgcolor="#999999" cellspacing="1" cellpadding="3" border="0" width="100%">
- <%-- name row --%>
- <tr bgcolor="#ffffff">
- <td><font size="-1">姓名 <i>(可选)</i></font></td>
- <td><input type="text" name="name" size="30"
- value="<%= (name!=null)?name:"" %>">
- </td>
- </tr>
- <%-- user email --%>
- <tr bgcolor="#ffffff">
- <td><font size="-1"<%= (errorEmail)?(" color="#ff0000""):"" %>>Email</font></td>
- <td><input type="text" name="email" size="30"
- value="<%= (email!=null)?email:"" %>">
- </td>
- </tr>
- <%-- username --%>
- <tr bgcolor="#ffffff">
- <td><font size="-1"<%= (!usernameIsEmail&&errorUsername)?" color="#ff0000"":"" %>>
- 用户名
- <br> (<input type="checkbox" name="usernameIsEmail"
- id="cb01"<%= (usernameIsEmail)?" checked":"" %>
- onclick="this.form.username.value=this.form.email.value;">
- <label for="cb01">使用Email</label>)
- </font>
- </td>
- <td><input type="text" name="username" size="30"
- <% if( usernameIsEmail ) { %>
- value="<%= (email!=null)?email:"" %>">
- <% } else { %>
- value="<%= (username!=null)?username:"" %>">
- <% } %>
- </td>
- </tr>
- <%-- password --%>
- <tr bgcolor="#ffffff">
- <td><font size="-1"<%= (errorNoPassword||errorPasswordsNotEqual)?" color="#ff0000"":"" %>
- >口令</font></td>
- <td><input type="password" name="password" value="" size="20" maxlength="30"></td>
- </tr>
- <%-- confirm password --%>
- <tr bgcolor="#ffffff">
- <td><font size="-1"<%= (errorNoConfirmPassword||errorPasswordsNotEqual)?" color="#ff0000"":"" %>
- >确认口令</font></td>
- <td><input type="password" name="confirmPassword" value="" size="20" maxlength="30"></td>
- </tr>
- </table>
- </td>
- </table>
- <br clear="all"><br>
- <input type="submit" value="创建用户">
-
- <input type="submit" value="取消"
- onclick="location.href='users.jsp';return false;">
- </form>
- <script language="JavaScript" type="text/javascript">
- <!--
- document.createForm.name.focus();
- //-->
- </script>
- </body>
- </html>