Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #5: various compatibility issues #7

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ <h1>
Just married Plugin Changelog
</h1>

<p><b>1.2.5</b> -- (TBD)</p>
<p><b>1.3.0</b> -- (TBD)</p>
<ul>
<li>Minimum server requirement: 4.6.0</li>
<li>[<a href='https://github.com/igniterealtime/openfire-justmarried-plugin/issues/5'>#5</a>] - Fix Compatibility with Openfire 4.6.0 and later.</li>
</ul>

<p><b>1.2.4</b> -- November 11, 2020</p>
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<description>Allows admins to rename or copy users</description>
<author>Holger Bergunde</author>
<version>${project.version}</version>
<date>2020-11-11</date>
<minServerVersion>4.0.0</minServerVersion>
<date>2024-11-20</date>
<minServerVersion>4.6.0</minServerVersion>

<adminconsole>
<tab id="tab-users">
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<artifactId>plugins</artifactId>
<groupId>org.igniterealtime.openfire</groupId>
<version>4.3.0-beta</version>
<version>4.6.0</version>
</parent>
<groupId>org.igniterealtime.openfire.plugins</groupId>
<artifactId>justmarried</artifactId>
<version>1.2.5-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<name>JustMarried Plugin</name>
<description>Allows admins to rename or copy users</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public void initializePlugin(PluginManager manager, File pluginDirectory) {
}

public static boolean changeName(String currentUserName, String newUserName, boolean deleteOldUser,
String newEmail, String newRealName) {
String newEmail, String newRealName, String password) {
UserManager userManager = UserManager.getInstance();

try {
User currentUser = userManager.getUser(currentUserName);
// Old user found, create new one
String password = AuthFactory.getPassword(currentUserName);
if (password == null || password.isEmpty()) {
password = AuthFactory.getPassword(currentUserName);
}
String newName = (newRealName == null || newRealName.length() == 0) ? currentUser.getName() : newRealName;
String newMail = (newEmail == null || newEmail.length() == 0) ? currentUser.getEmail() : newEmail;
User newUser = userManager.createUser(newUserName, password, currentUser.getName(), newMail);
Expand Down Expand Up @@ -145,7 +147,7 @@ private static void addNewUserToOthersRoster(User newUser, RosterItem otherItem,

// Is this user registered with our OF server?
String username = otherItem.getJid().getNode();
if (username != null && username.length() > 0 && userManager.isRegisteredUser(username)
if (username != null && username.length() > 0 && userManager.isRegisteredUser(otherItem.getJid(), false)
&& XMPPServer.getInstance().isLocal(XMPPServer.getInstance().createJID(currentUser, null))) {
try {
User otherUser = userManager.getUser(username);
Expand Down
49 changes: 40 additions & 9 deletions src/web/married.jsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="org.jivesoftware.openfire.plugin.married.JustMarriedPlugin"%>
<%@ page import="org.jivesoftware.openfire.auth.AuthFactory" %>
<%@ page import="org.jivesoftware.openfire.user.UserManager" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

Expand All @@ -8,9 +10,12 @@
webManager.init(request, response, session, application, out);
String oldName = request.getParameter("oldName");
String newName = request.getParameter("newName");
String newPassword = request.getParameter("newPassword");
String keepCopy = request.getParameter("copy");
String newEmail = request.getParameter("email");
String newRealName = request.getParameter("realName");

final boolean supported = !UserManager.getUserPropertyProvider().isReadOnly();
%>

<html>
Expand All @@ -24,13 +29,29 @@
</head>
<body>

<% if (!supported) { %>
<div class="jive-warning">
<table>
<tbody>
<tr>
<td class="jive-icon"><img src="/images/warning-16x16.gif" alt=""/></td>
<td class="jive-icon-label">
This instance of Openfire does not support this feature, as its user-base is 'read-only' (likely due to being obtained from a remote directory service).
</td>
</tr>
</tbody>
</table>
</div>
<br />
<% } %>

<div class="jive-contentBoxHeader">Just married</div>
<div class="jive-contentBox">
<%
if (oldName != null && newName != null && oldName.trim().length() > 0 && newName.trim().length() > 0) {
boolean success = JustMarriedPlugin.changeName(oldName, newName, keepCopy == null ? true : false, newEmail, newRealName);
boolean success = JustMarriedPlugin.changeName(oldName, newName, keepCopy == null ? true : false, newEmail, newRealName, newPassword);
if (success) {
out.write("<div class=\"success\">Sucessfully renamed user " + oldName + " to " + newName
out.write("<div class=\"success\">Successfully renamed user " + oldName + " to " + newName
+ "!</div>");
} else {
out.write("<div class=\"error\">Something went wrong :-/. Please have a closer look to the error log!</div>");
Expand All @@ -46,7 +67,7 @@
: "class=\"controls\"");%>>
<input type="text" name="oldName" style="height:26px"
class="input-xlarge"
<%out.write(oldName != null && oldName.length() == 0 ? "id=\"inputError\"" : "id=\"input01\"");%>>
<%out.write(oldName != null && oldName.length() == 0 ? "id=\"inputError\"" : "id=\"input01\"");%> <%=supported?"":"disabled"%> required>
<p class="help-block">The current username e.g user.name
(without server)</p>
</div>
Expand All @@ -56,30 +77,40 @@
: "class=\"controls\"");%>>
<input type="text" name="newName" style="height:26px"
class="input-xlarge"
<%out.write(newName != null && newName.length() == 0 ? "id=\"inputError\"" : "id=\"input01\"");%>>
<p class="help-block">The new username e.g user.newname
<%out.write(newName != null && newName.length() == 0 ? "id=\"inputError\"" : "id=\"input01\"");%> <%=supported?"":"disabled"%> required>
<p class="help-block">The new username e.g. user.newname
(without server)</p>
</div>
<label class="control-label" for="input01">New Password<%=AuthFactory.supportsPasswordRetrieval()?"":"*"%></label>
<div
<%out.write(newName != null && newName.length() == 0 ? "class=\"control-group error\""
: "class=\"controls\"");%>>
<input type="password" name="newPassword" style="height:26px"
class="input-xlarge"
<%out.write(newName != null && newName.length() == 0 ? "id=\"inputError\"" : "id=\"input01\"");%> <%=supported?"":"disabled"%> <%=AuthFactory.supportsPasswordRetrieval()?"":"required"%>>
<p class="help-block">The new password for this user. <%=AuthFactory.supportsPasswordRetrieval()?"Leave empty to keep the old password.":""%></p>
</div>

<label class="control-label" for="input01">New E-Mail address</label>
<div class="controls">
<input type="text" name="email" style="height:26px"
class="input-xlarge" id="input01">
class="input-xlarge" id="input01" <%=supported?"":"disabled"%>>
<p class="help-block">New email address. Will copy address from old user if field is empty.</p>
</div>
<label class="control-label" for="input01">New Name</label>
<div class="controls">
<input type="text" name="realName" style="height:26px"
class="input-xlarge" id="input01">
class="input-xlarge" id="input01" <%=supported?"":"disabled"%>>
<p class="help-block">Will copy name from old user if field is empty.</p>
</div>
<div class="control-group">
<label class="checkbox"> <input type="checkbox"
id="optionsCheckbox2" name="copy" value="keepCopy"> Keep a
id="optionsCheckbox2" name="copy" value="keepCopy" <%=supported?"":"disabled"%>> Keep a
copy of the old username
</label>
</div>
<div class="control-group">
<button type="submit" class="btn btn-primary">Rename user</button>
<button type="submit" class="btn btn-primary" <%=supported?"":"disabled"%>>Rename user</button>
</div>
<p class="help-block">* Mandatory item</p>
</fieldset>
Expand Down