user-password.jsp 5.78 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
  -
  - This software is published under the terms of the GNU Public License (GPL),
8 9
  - a copy of which is included in this distribution, or a commercial license
  - agreement with Jive.
Matt Tucker's avatar
Matt Tucker committed
10 11 12
--%>

<%@ page import="org.jivesoftware.util.*,
13
                 org.jivesoftware.openfire.user.*,
14
                 java.net.URLEncoder"
Bill Lynch's avatar
Bill Lynch committed
15
    errorPage="error.jsp"
16
%><%@ page import="org.xmpp.packet.JID"%>
17
<%@ page import="org.jivesoftware.openfire.security.SecurityAuditManager" %>
Matt Tucker's avatar
Matt Tucker committed
18

19
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
20
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Bill Lynch's avatar
Bill Lynch committed
21
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager" />
22
<% admin.init(request, response, session, application, out ); %>
Matt Tucker's avatar
Matt Tucker committed
23 24 25 26

<%  // Get parameters //
    boolean cancel = request.getParameter("cancel") != null;
    boolean update = request.getParameter("update") != null;
27
    String username = ParamUtils.getParameter(request,"username");
Matt Tucker's avatar
Matt Tucker committed
28 29 30 31 32
    String password = ParamUtils.getParameter(request,"password");
    String passwordConfirm = ParamUtils.getParameter(request,"passwordConfirm");

    // Handle a cancel
    if (cancel) {
33
        response.sendRedirect("user-properties.jsp?username=" + URLEncoder.encode(username, "UTF-8"));
Matt Tucker's avatar
Matt Tucker committed
34 35 36 37
        return;
    }

    // Load the user object
38
    User user = admin.getUserManager().getUser(username);
Matt Tucker's avatar
Matt Tucker committed
39 40 41

    // Handle a password update:
    boolean errors = false;
42
    boolean unsupported = false;
Matt Tucker's avatar
Matt Tucker committed
43 44 45
    if (update) {
        // Validate the passwords:
        if (password != null && passwordConfirm != null && password.equals(passwordConfirm)) {
46 47 48 49 50 51 52 53 54 55 56 57
            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;
58
            }
Matt Tucker's avatar
Matt Tucker committed
59 60 61 62 63 64 65
        }
        else {
            errors = true;
        }
    }
%>

66 67 68 69 70 71 72 73
<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
74

75 76 77 78 79 80
<% if (UserManager.getUserProvider().isReadOnly()) { %>
<div class="error">
    <fmt:message key="user.read_only"/>
</div>
<% } %>

Matt Tucker's avatar
Matt Tucker committed
81 82
<%  if (errors) { %>

Bill Lynch's avatar
Bill Lynch committed
83 84 85
    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
86
        <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
87
        <td class="jive-icon-label">
88
        <fmt:message key="user.password.error_set_pwd" />
Bill Lynch's avatar
Bill Lynch committed
89 90 91 92 93
        </td></tr>
    </tbody>
    </table>
    </div><br>

94 95 96 97 98 99 100 101 102 103 104 105 106
<%  } 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
107 108 109 110 111
<%  } else if (request.getParameter("success") != null) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
112
        <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
113
        <td class="jive-icon-label">
114
        <fmt:message key="user.password.update" />
Bill Lynch's avatar
Bill Lynch committed
115 116 117 118
        </td></tr>
    </tbody>
    </table>
    </div><br>
Matt Tucker's avatar
Matt Tucker committed
119 120 121

<%  } %>

Bill Lynch's avatar
Bill Lynch committed
122
<p>
123
<fmt:message key="user.password.info" />
Bill Lynch's avatar
Bill Lynch committed
124
</p>
Matt Tucker's avatar
Matt Tucker committed
125

Bill Lynch's avatar
Bill Lynch committed
126 127
<form action="user-password.jsp" name="passform" method="post">
<input type="hidden" name="username" value="<%= username %>">
Matt Tucker's avatar
Matt Tucker committed
128

Bill Lynch's avatar
Bill Lynch committed
129
<fieldset>
130
    <legend><fmt:message key="user.password.change" /></legend>
Bill Lynch's avatar
Bill Lynch committed
131 132 133 134 135
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
        <tr>
            <td class="c1">
136
                <fmt:message key="user.create.username" />:
Bill Lynch's avatar
Bill Lynch committed
137 138
            </td>
            <td class="c2">
139
                <%= JID.unescapeNode(user.getUsername()) %>
Bill Lynch's avatar
Bill Lynch committed
140 141 142 143
            </td>
        </tr>
        <tr>
            <td class="c1">
144
                <fmt:message key="user.password.new_pwd" />:
Bill Lynch's avatar
Bill Lynch committed
145
            </td>
146
            <td class="c2">
Bill Lynch's avatar
Bill Lynch committed
147 148 149 150 151
                <input type="password" name="password" value="" size="20" maxlength="50">
            </td>
        </tr>
        <tr>
            <td class="c1">
152
                <fmt:message key="user.password.confirm_new_pwd" />:
Bill Lynch's avatar
Bill Lynch committed
153 154 155 156 157 158 159 160 161 162 163
            </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
164

165 166
<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
167 168
</form>

169
<script language="JavaScript" type="text/javascript">
Matt Tucker's avatar
Matt Tucker committed
170 171 172
document.passform.password.focus();
</script>

173 174 175 176 177 178 179 180 181 182 183 184 185 186
    <%  // 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>
    <% } %>

187 188
    </body>
</html>