user-create.jsp 7.95 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 19
<%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%>
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 53 54 55 56 57 58
        else {
            try {
                username = username.trim().toLowerCase();
                username = Stringprep.nodeprep(username);
            }
            catch (StringprepException se) {
                errors.put("username", "");
            }
        }
59 60 61 62 63
        // 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
64 65 66 67 68 69 70 71 72 73 74 75
            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
76 77
                User newUser = webManager.getUserManager().createUser(username, password, name, email);

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

99 100 101 102 103 104 105
<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>
106

107
<p><fmt:message key="user.create.info" /></p>
108

Derek DeMoro's avatar
Derek DeMoro committed
109 110
<c:set var="submit" value="${param.create}"/>
<c:set var="errors" value="${errors}"/>
111

Matt Tucker's avatar
Matt Tucker committed
112
<%  if (!errors.isEmpty()) { %>
113 114 115

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
Bill Lynch's avatar
Bill Lynch committed
116
    <tbody>
117 118
        <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
119 120 121
            <td class="jive-icon-label">

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

<%  } %>

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

162
<fieldset>
163
    <legend><fmt:message key="user.create.new_user" /></legend>
164 165 166
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
Derek DeMoro's avatar
Derek DeMoro committed
167
    <tr>
168
        <td width="1%" nowrap><label for="usernametf"><fmt:message key="user.create.username" />:</label> *</td>
169 170 171 172
        <td width="99%">
            <input type="text" name="username" size="30" maxlength="75" value="<%= ((username!=null) ? username : "") %>"
             id="usernametf" autocomplete="off">
        </td>
Derek DeMoro's avatar
Derek DeMoro committed
173 174
    </tr>
    <tr>
175
        <td width="1%" nowrap>
176
            <label for="nametf"><fmt:message key="user.create.name" />:</label>
177 178 179 180 181
        </td>
        <td width="99%">
            <input type="text" name="name" size="30" maxlength="75" value="<%= ((name!=null) ? name : "") %>"
             id="nametf">
        </td>
Derek DeMoro's avatar
Derek DeMoro committed
182 183
    </tr>
    <tr>
184
        <td width="1%" nowrap>
185
            <label for="emailtf"><fmt:message key="user.create.email" />:</label></td>
186 187 188 189
        <td width="99%">
            <input type="text" name="email" size="30" maxlength="75" value="<%= ((email!=null) ? email : "") %>"
             id="emailtf">
        </td>
Derek DeMoro's avatar
Derek DeMoro committed
190 191
    </tr>
    <tr>
192
        <td nowrap>
193
            <label for="passtf"><fmt:message key="user.create.pwd" />:</label> *
194 195 196 197 198
        </td>
        <td width="99%">
            <input type="password" name="password" value="" size="20" maxlength="75"
             id="passtf">
        </td>
Derek DeMoro's avatar
Derek DeMoro committed
199 200
    </tr>
    <tr>
201
        <td width="1%" nowrap>
202
            <label for="confpasstf"><fmt:message key="user.create.confirm_pwd" />:</label> *
203 204 205 206 207
        </td>
        <td width="99%">
            <input type="password" name="passwordConfirm" value="" size="20" maxlength="75"
             id="confpasstf">
        </td>
Derek DeMoro's avatar
Derek DeMoro committed
208
    </tr>
209 210 211 212
    </tbody>
    </table>
    <br>
    <span class="jive-description">
213
    * <fmt:message key="user.create.requied" />
214 215 216
    </span>
    </div>
</fieldset>
Matt Tucker's avatar
Matt Tucker committed
217

218
<br><br>
Matt Tucker's avatar
Matt Tucker committed
219

220 221 222
<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" />">
223 224 225 226 227 228

</form>

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

230 231
    </body>
</html>