user-password.jsp 6.21 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-2008 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch committed
6
  -
7 8 9 10 11 12 13 14 15 16 17
  - Licensed under the Apache License, Version 2.0 (the "License");
  - you may not use this file except in compliance with the License.
  - You may obtain a copy of the License at
  -
  -     http://www.apache.org/licenses/LICENSE-2.0
  -
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS,
  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - See the License for the specific language governing permissions and
  - limitations under the License.
Matt Tucker's avatar
Matt Tucker committed
18 19 20
--%>

<%@ page import="org.jivesoftware.util.*,
21
                 org.jivesoftware.openfire.user.*,
22
                 java.net.URLEncoder"
Bill Lynch's avatar
Bill Lynch committed
23
    errorPage="error.jsp"
24
%><%@ page import="org.xmpp.packet.JID"%>
25
<%@ page import="org.jivesoftware.openfire.security.SecurityAuditManager" %>
Matt Tucker's avatar
Matt Tucker committed
26

27 28
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Bill Lynch's avatar
Bill Lynch committed
29
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager" />
30
<% admin.init(request, response, session, application, out ); %>
Matt Tucker's avatar
Matt Tucker committed
31 32 33 34

<%  // Get parameters //
    boolean cancel = request.getParameter("cancel") != null;
    boolean update = request.getParameter("update") != null;
35
    String username = ParamUtils.getParameter(request,"username");
Matt Tucker's avatar
Matt Tucker committed
36 37 38 39 40
    String password = ParamUtils.getParameter(request,"password");
    String passwordConfirm = ParamUtils.getParameter(request,"passwordConfirm");

    // Handle a cancel
    if (cancel) {
41
        response.sendRedirect("user-properties.jsp?username=" + URLEncoder.encode(username, "UTF-8"));
Matt Tucker's avatar
Matt Tucker committed
42 43 44 45
        return;
    }

    // Load the user object
46
    User user = admin.getUserManager().getUser(username);
Matt Tucker's avatar
Matt Tucker committed
47 48 49

    // Handle a password update:
    boolean errors = false;
50
    boolean unsupported = false;
Matt Tucker's avatar
Matt Tucker committed
51 52 53
    if (update) {
        // Validate the passwords:
        if (password != null && passwordConfirm != null && password.equals(passwordConfirm)) {
54 55 56 57 58 59 60 61 62 63 64 65
            try {
                user.setPassword(password);
                if (!SecurityAuditManager.getSecurityAuditProvider().blockUserEvents()) {
                    // Log the event
                    admin.logEvent("set password for user "+username, null);
                }
                // Done, so redirect
                response.sendRedirect("user-password.jsp?success=true&username=" + URLEncoder.encode(username, "UTF-8"));
                return;
            }
            catch (UnsupportedOperationException uoe) {
                unsupported = true;
66
            }
Matt Tucker's avatar
Matt Tucker committed
67 68 69 70 71 72 73
        }
        else {
            errors = true;
        }
    }
%>

74 75 76 77 78 79 80 81
<html>
    <head>
        <title><fmt:message key="user.password.title"/></title>
        <meta name="subPageID" content="user-password"/>
        <meta name="extraParams" content="<%= "username="+URLEncoder.encode(username, "UTF-8") %>"/>
        <meta name="helpPage" content="change_a_user_password.html"/>
    </head>
    <body>
Matt Tucker's avatar
Matt Tucker committed
82

83 84 85 86 87 88
<% if (UserManager.getUserProvider().isReadOnly()) { %>
<div class="error">
    <fmt:message key="user.read_only"/>
</div>
<% } %>

Matt Tucker's avatar
Matt Tucker committed
89 90
<%  if (errors) { %>

Bill Lynch's avatar
Bill Lynch committed
91 92 93
    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
94
        <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
Bill Lynch's avatar
Bill Lynch committed
95
        <td class="jive-icon-label">
96
        <fmt:message key="user.password.error_set_pwd" />
Bill Lynch's avatar
Bill Lynch committed
97 98 99 100 101
        </td></tr>
    </tbody>
    </table>
    </div><br>

102 103 104 105 106 107 108 109 110 111 112 113 114
<%  } else if (unsupported) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
        <td class="jive-icon-label">
        <fmt:message key="user.password.error_set_pwd_unsupp" />
        </td></tr>
    </tbody>
    </table>
    </div><br>

Bill Lynch's avatar
Bill Lynch committed
115 116 117 118 119
<%  } else if (request.getParameter("success") != null) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
120
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
Bill Lynch's avatar
Bill Lynch committed
121
        <td class="jive-icon-label">
122
        <fmt:message key="user.password.update" />
Bill Lynch's avatar
Bill Lynch committed
123 124 125 126
        </td></tr>
    </tbody>
    </table>
    </div><br>
Matt Tucker's avatar
Matt Tucker committed
127 128 129

<%  } %>

Bill Lynch's avatar
Bill Lynch committed
130
<p>
131
<fmt:message key="user.password.info" />
Bill Lynch's avatar
Bill Lynch committed
132
</p>
Matt Tucker's avatar
Matt Tucker committed
133

Bill Lynch's avatar
Bill Lynch committed
134
<form action="user-password.jsp" name="passform" method="post">
Sven Tantau's avatar
Sven Tantau committed
135
<input type="hidden" name="username" value="<%=StringUtils.escapeForXML(username) %>">
Matt Tucker's avatar
Matt Tucker committed
136

Bill Lynch's avatar
Bill Lynch committed
137
<fieldset>
138
    <legend><fmt:message key="user.password.change" /></legend>
Bill Lynch's avatar
Bill Lynch committed
139 140 141 142 143
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
        <tr>
            <td class="c1">
144
                <fmt:message key="user.create.username" />:
Bill Lynch's avatar
Bill Lynch committed
145 146
            </td>
            <td class="c2">
Sven Tantau's avatar
Sven Tantau committed
147
                <%= StringUtils.escapeHTMLTags(JID.unescapeNode(user.getUsername())) %>
Bill Lynch's avatar
Bill Lynch committed
148 149 150 151
            </td>
        </tr>
        <tr>
            <td class="c1">
152
                <fmt:message key="user.password.new_pwd" />:
Bill Lynch's avatar
Bill Lynch committed
153
            </td>
154
            <td class="c2">
Bill Lynch's avatar
Bill Lynch committed
155 156 157 158 159
                <input type="password" name="password" value="" size="20" maxlength="50">
            </td>
        </tr>
        <tr>
            <td class="c1">
160
                <fmt:message key="user.password.confirm_new_pwd" />:
Bill Lynch's avatar
Bill Lynch committed
161 162 163 164 165 166 167 168 169 170 171
            </td>
            <td class="c2">
                <input type="password" name="passwordConfirm" value="" size="20" maxlength="50">
            </td>
        </tr>
    </tbody>
    </table>
    </div>
</fieldset>

<br><br>
Matt Tucker's avatar
Matt Tucker committed
172

173 174
<input type="submit" value="<fmt:message key="user.password.update_pwd" />" name="update">
<input type="submit" value="<fmt:message key="global.cancel" />" name="cancel">
Matt Tucker's avatar
Matt Tucker committed
175 176
</form>

177
<script language="JavaScript" type="text/javascript">
Matt Tucker's avatar
Matt Tucker committed
178 179 180
document.passform.password.focus();
</script>

181 182 183 184 185 186 187 188 189 190 191 192 193 194
    <%  // 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>
    <% } %>

195 196
    </body>
</html>