user-create.jsp 7.66 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", "");
            }
        }
Matt Tucker's avatar
Matt Tucker committed
59 60 61 62 63 64 65 66 67 68 69 70 71
        if (password == null) {
            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
72 73
                User newUser = webManager.getUserManager().createUser(username, password, name, email);

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

95 96 97 98 99 100 101
<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>
102

103
<p><fmt:message key="user.create.info" /></p>
104

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

Matt Tucker's avatar
Matt Tucker committed
108
<%  if (!errors.isEmpty()) { %>
109 110 111

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
Bill Lynch's avatar
Bill Lynch committed
112
    <tbody>
113 114
        <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
115 116 117
            <td class="jive-icon-label">

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

<%  } %>

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

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

214
<br><br>
Matt Tucker's avatar
Matt Tucker committed
215

216 217 218
<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" />">
219 220 221 222 223 224

</form>

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

226 227
    </body>
</html>