user-create.jsp 8.38 KB
Newer Older
Bill Lynch's avatar
Bill Lynch committed
1
<%--
Matt Tucker's avatar
Matt Tucker committed
2 3
  -	$Revision$
  -	$Date$
Bill Lynch's avatar
Bill Lynch committed
4
  -
5
  - Copyright (C) 2004-2005 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch committed
6 7 8
  -
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
9
--%>
10

Matt Tucker's avatar
Matt Tucker committed
11
<%@ page import="org.jivesoftware.util.*,
12
                 org.jivesoftware.wildfire.user.*,
13 14 15
                 java.net.URLEncoder,
                 org.jivesoftware.stringprep.Stringprep,
                 org.jivesoftware.stringprep.StringprepException"
Bill Lynch's avatar
Bill Lynch committed
16
    errorPage="error.jsp"
Matt Tucker's avatar
Matt Tucker committed
17
%>
18
<%@ page import="java.util.Map"%>
19
<%@ page import="java.util.HashMap"%><%@ page import="org.xmpp.packet.JID"%>
20 21

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
22
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
23

24 25 26 27
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<% webManager.init(request, response, session, application, out ); %>

<%  // Get parameters //
28 29
    boolean another = request.getParameter("another") != null;
    boolean create = another || request.getParameter("create") != null;
Matt Tucker's avatar
Matt Tucker committed
30 31 32 33 34 35 36
    boolean cancel = request.getParameter("cancel") != null;
    String username = ParamUtils.getParameter(request,"username");
    String name = ParamUtils.getParameter(request,"name");
    String email = ParamUtils.getParameter(request,"email");
    String password = ParamUtils.getParameter(request,"password");
    String passwordConfirm = ParamUtils.getParameter(request,"passwordConfirm");

37
    Map<String, String> errors = new HashMap<String, String>();
Matt Tucker's avatar
Matt Tucker committed
38 39 40 41 42 43 44 45 46 47 48 49
    // Handle a cancel
    if (cancel) {
        response.sendRedirect("user-summary.jsp");
        return;
    }

    // Handle a request to create a user:
    if (create) {
        // Validate
        if (username == null) {
            errors.put("username","");
        }
50 51 52
        else {
            try {
                username = username.trim().toLowerCase();
53
                username = JID.escapeNode(username);
54 55 56 57 58 59
                username = Stringprep.nodeprep(username);
            }
            catch (StringprepException se) {
                errors.put("username", "");
            }
        }
60 61 62 63 64
        // Trim the password. This means we don't accept spaces as passwords. We don't
        // trim the passwordConfirm as well since not trimming will ensure the user doesn't
        // think space is an ok password character.
        password = password.trim();
        if (password == null || password.equals("")) {
Matt Tucker's avatar
Matt Tucker committed
65 66 67 68 69 70 71 72 73 74 75 76
            errors.put("password","");
        }
        if (passwordConfirm == null) {
            errors.put("passwordConfirm","");
        }
        if (password != null && passwordConfirm != null && !password.equals(passwordConfirm)) {
            errors.put("passwordMatch","");
        }

        // do a create if there were no errors
        if (errors.size() == 0) {
            try {
Matt Tucker's avatar
Matt Tucker committed
77 78
                User newUser = webManager.getUserManager().createUser(username, password, name, email);

Matt Tucker's avatar
Matt Tucker committed
79
                // Successful, so redirect
80 81 82 83
                if (another) {
                    response.sendRedirect("user-create.jsp?success=true");
                }
                else {
84 85
                    response.sendRedirect("user-properties.jsp?success=true&username=" +
                            URLEncoder.encode(newUser.getUsername(), "UTF-8"));
86
                }
Matt Tucker's avatar
Matt Tucker committed
87 88 89 90 91 92 93 94 95 96 97 98
                return;
            }
            catch (UserAlreadyExistsException e) {
                errors.put("usernameAlreadyExists","");
            }
            catch (Exception e) {
                errors.put("general","");
                Log.error(e);
            }
        }
    }
%>
99

100 101 102 103 104 105 106
<html>
    <head>
        <title><fmt:message key="user.create.title"/></title>
        <meta name="pageID" content="user-create"/>
        <meta name="helpPage" content="add_users_to_the_system.html"/>
    </head>
    <body>
107

108 109 110 111 112 113
<% if (UserManager.getUserProvider().isReadOnly()) { %>
<div class="error">
    <fmt:message key="user.read_only"/>
</div>
<% } %>

114
<p><fmt:message key="user.create.info" /></p>
115

Matt Tucker's avatar
Matt Tucker committed
116 117
<%--<c:set var="submit" value="${param.create}"/>--%>
<%--<c:set var="errors" value="${errors}"/>--%>
118

Matt Tucker's avatar
Matt Tucker committed
119
<%  if (!errors.isEmpty()) { %>
120 121 122

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
Bill Lynch's avatar
Bill Lynch committed
123
    <tbody>
124 125
        <tr>
            <td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0"/></td>
Matt Tucker's avatar
Matt Tucker committed
126 127 128
            <td class="jive-icon-label">

            <% if (errors.get("general") != null) { %>
129
                <fmt:message key="user.create.error_creating_account" />
Matt Tucker's avatar
Matt Tucker committed
130
            <% } else if (errors.get("username") != null) { %>
131
                <fmt:message key="user.create.invalid_username" />
Matt Tucker's avatar
Matt Tucker committed
132
            <% } else if (errors.get("usernameAlreadyExists") != null) { %>
133
                <fmt:message key="user.create.user_exist" />
Matt Tucker's avatar
Matt Tucker committed
134
            <% } else if (errors.get("name") != null) { %>
135
                <fmt:message key="user.create.invalid_name" />
Matt Tucker's avatar
Matt Tucker committed
136
            <% } else if (errors.get("email") != null) { %>
137
                <fmt:message key="user.create.invalid_email" />
Matt Tucker's avatar
Matt Tucker committed
138
            <% } else if (errors.get("password") != null) { %>
139
                <fmt:message key="user.create.invalid_password" />
Matt Tucker's avatar
Matt Tucker committed
140
            <% } else if (errors.get("passwordMatch") != null) { %>
141
                <fmt:message key="user.create.invalid_match_password" />
Matt Tucker's avatar
Matt Tucker committed
142
            <% } else if (errors.get("passwordConfirm") != null) { %>
143
                <fmt:message key="user.create.invalid_password_confirm" />
Matt Tucker's avatar
Matt Tucker committed
144 145
            <% } %>
            </td>
146
        </tr>
Bill Lynch's avatar
Bill Lynch committed
147
    </tbody>
148 149 150 151 152 153 154 155 156 157 158
    </table>
    </div>
    <br>

<%  } else if (request.getParameter("success") != null) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0"></td>
        <td class="jive-icon-label">
159
        <fmt:message key="user.create.created_success" />
160 161 162 163 164 165 166
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

167
<form name="f" action="user-create.jsp" method="get">
Derek DeMoro's avatar
Derek DeMoro committed
168

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	<div class="jive-contentBoxHeader">
		<fmt:message key="user.create.new_user" />
	</div>
	<div class="jive-contentBox">
		<table cellpadding="3" cellspacing="0" border="0">
		<tbody>
		<tr>
			<td width="1%" nowrap><label for="usernametf"><fmt:message key="user.create.username" />:</label> *</td>
			<td width="99%">
				<input type="text" name="username" size="30" maxlength="75" value="<%= ((username!=null) ? username : "") %>"
				 id="usernametf" autocomplete="off">
			</td>
		</tr>
		<tr>
			<td width="1%" nowrap>
				<label for="nametf"><fmt:message key="user.create.name" />:</label>
			</td>
			<td width="99%">
				<input type="text" name="name" size="30" maxlength="75" value="<%= ((name!=null) ? name : "") %>"
				 id="nametf">
			</td>
		</tr>
		<tr>
			<td width="1%" nowrap>
				<label for="emailtf"><fmt:message key="user.create.email" />:</label></td>
			<td width="99%">
				<input type="text" name="email" size="30" maxlength="75" value="<%= ((email!=null) ? email : "") %>"
				 id="emailtf">
			</td>
		</tr>
		<tr>
			<td nowrap>
				<label for="passtf"><fmt:message key="user.create.pwd" />:</label> *
			</td>
			<td width="99%">
				<input type="password" name="password" value="" size="20" maxlength="75"
				 id="passtf">
			</td>
		</tr>
		<tr>
			<td width="1%" nowrap>
				<label for="confpasstf"><fmt:message key="user.create.confirm_pwd" />:</label> *
			</td>
			<td width="99%">
				<input type="password" name="passwordConfirm" value="" size="20" maxlength="75"
				 id="confpasstf">
			</td>
		</tr>
		<tr>

			<td colspan="2" style="padding-top: 10px;">
				<input type="submit" name="create" value="<fmt:message key="user.create.create" />">
				<input type="submit" name="another" value="<fmt:message key="user.create.create_another" />">
				<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />"></td>
		</tr>
		</tbody>
		</table>

	</div>

	<span class="jive-description">
230
    * <fmt:message key="user.create.requied" />
231
    </span>
Matt Tucker's avatar
Matt Tucker committed
232

233 234 235 236 237 238

</form>

<script language="JavaScript" type="text/javascript">
document.f.username.focus();
</script>
Matt Tucker's avatar
Matt Tucker committed
239

240 241 242 243 244 245 246 247 248 249 250 251 252 253
<%  // Disable the form if a read-only user provider.
if (UserManager.getUserProvider().isReadOnly()) { %>

<script language="Javascript" type="text/javascript">
  function disable() {
    var limit = document.forms[0].elements.length;
    for (i=0;i<limit;i++) {
      document.forms[0].elements[i].disabled = true;
    }
  }
  disable();
</script>
    <% } %>

254 255
    </body>
</html>