user-create.jsp 7.5 KB
Newer Older
Bill Lynch's avatar
Bill Lynch committed
1
<%--
Matt Tucker's avatar
Matt Tucker committed
2 3 4
  -	$RCSfile$
  -	$Revision$
  -	$Date$
Bill Lynch's avatar
Bill Lynch committed
5 6 7 8 9
  -
  - Copyright (C) 2004 Jive Software. All rights reserved.
  -
  - 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
10
--%>
11

Matt Tucker's avatar
Matt Tucker committed
12 13 14 15 16 17 18
<%@ page import="org.jivesoftware.util.*,
                 java.util.HashMap,
                 java.util.Map,
                 org.jivesoftware.messenger.user.UserManager,
                 org.jivesoftware.messenger.user.*,
                 java.util.*,
                 org.jivesoftware.messenger.*,
Derek DeMoro's avatar
Derek DeMoro committed
19
                 org.jivesoftware.admin.*,
Matt Tucker's avatar
Matt Tucker committed
20 21 22 23 24 25
                 java.io.StringWriter,
                 java.io.StringWriter,
                 java.io.IOException,
                 org.jivesoftware.messenger.auth.UnauthorizedException,
                 java.io.PrintStream,
                 org.dom4j.xpath.DefaultXPath,
26 27
                 org.dom4j.*,
                 java.net.URLEncoder"
Bill Lynch's avatar
Bill Lynch committed
28
    errorPage="error.jsp"
Matt Tucker's avatar
Matt Tucker committed
29
%>
30 31 32 33 34 35 36 37

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

<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<jsp:useBean id="errors" class="java.util.HashMap" />
<% webManager.init(request, response, session, application, out ); %>

<%  // Get parameters //
38 39
    boolean another = request.getParameter("another") != null;
    boolean create = another || request.getParameter("create") != null;
Matt Tucker's avatar
Matt Tucker committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    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");

    // 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","");
        }
        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

Derek DeMoro's avatar
Derek DeMoro committed
95 96
<jsp:useBean id="pageinfo" scope="request" class="org.jivesoftware.admin.AdminPageBean"/>
<%   // Title of this page and breadcrumbs
Derek DeMoro's avatar
Derek DeMoro committed
97 98
    String title = "Create User";
    pageinfo.setTitle(title);
Bill Lynch's avatar
Bill Lynch committed
99
    pageinfo.getBreadcrumbs().add(new AdminPageBean.Breadcrumb("Main", "index.jsp"));
Derek DeMoro's avatar
Derek DeMoro committed
100 101 102
    pageinfo.getBreadcrumbs().add(new AdminPageBean.Breadcrumb(title, "user-create.jsp"));
    pageinfo.setPageID("user-create");
%>
Derek DeMoro's avatar
Derek DeMoro committed
103 104
<jsp:include page="top.jsp" flush="true"/>
<jsp:include page="title.jsp" flush="true"/>
105 106 107

<p>Use the form below to create a new user.</p>

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

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

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
Bill Lynch's avatar
Bill Lynch committed
115
    <tbody>
116 117
        <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
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
            <td class="jive-icon-label">

            <% if (errors.get("general") != null) { %>
                Error creating the user account. Please check your error logs.
            <% } else if (errors.get("username") != null) { %>
                Invalid username.
            <% } else if (errors.get("usernameAlreadyExists") != null) { %>
                Username already exists - please choose a different one.
            <% } else if (errors.get("name") != null) { %>
                Invalid name.
            <% } else if (errors.get("email") != null) { %>
                Invalid email.
            <% } else if (errors.get("password") != null) { %>
                Invalid password.
            <% } else if (errors.get("passwordMatch") != null) { %>
                Passwords don't match.
            <% } else if (errors.get("passwordConfirm") != null) { %>
                Invalid password confirmation.
            <% } %>
            </td>
138
        </tr>
Bill Lynch's avatar
Bill Lynch committed
139
    </tbody>
140 141 142 143 144 145 146 147 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">
        New user created successfully.
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

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

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

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

219 220 221 222 223 224 225 226 227
<input type="submit" name="create" value="Create User">
<input type="submit" name="another" value="Create &amp; Create Another">
<input type="submit" name="cancel" value="Cancel">

</form>

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

229
<jsp:include page="bottom.jsp" flush="true"/>