%@ page contentType="text/html; charset=UTF-8" %>
<%--
-
- Copyright (C) 2005-2008 Jive Software, 2017-2026 Ignite Realtime Foundation. All rights reserved.
-
- 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.
--%>
<%@ page
import=" org.jivesoftware.openfire.group.Group,
org.jivesoftware.openfire.group.GroupNotFoundException,
org.jivesoftware.openfire.user.User,
org.jivesoftware.openfire.user.UserNotFoundException"%>
<%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.util.StringUtils"%>
<%@ page import="org.jivesoftware.util.CookieUtils"%>
<%@ page import="org.xmpp.packet.JID"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.util.*"%>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="admin" uri="admin" %>
<%
webManager.init(pageContext);
%>
<%
// Get parameters
String add = ParamUtils.getParameter(request, "add");
String delete = ParamUtils.getParameter(request, "delete");
String username = ParamUtils.getParameter(request, "username");
JID jid = webManager.getXMPPServer().createJID(username, null);
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
Map errors = new HashMap<>();
pageContext.setAttribute("errors", errors);
if (add != null || delete != null) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
add = null;
delete = null;
errors.put("csrf", "CSRF security check failed! Please reload page and try again.");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if(add != null) {
try {
Group group = webManager.getGroupManager().getGroup(add);
group.getMembers().add(jid);
response.sendRedirect("user-groups.jsp?username=" + URLEncoder.encode(username, StandardCharsets.UTF_8) + "&updatesuccess=true");
} catch (GroupNotFoundException exp) {
return;
}
}
if(delete != null) {
try {
Group group = webManager.getGroupManager().getGroup(delete);
group.getMembers().remove(jid);
group.getAdmins().remove(jid);
response.sendRedirect("user-groups.jsp?username=" + URLEncoder.encode(username, StandardCharsets.UTF_8) + "&updatesuccess=true");
} catch (GroupNotFoundException exp) {
return;
}
}
// Load the user object
User user = null;
try {
user = webManager.getUserManager().getUser(username);
}
catch (UserNotFoundException unfe) {
}
Collection userGroups = webManager.getGroupManager().getGroups(user);
int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",15);
if (range <= 0) {
range = 15;
}
if (request.getParameter("range") != null) {
webManager.setRowsPerPage("group-summary", range);
}
ArrayList groups = new ArrayList<>(webManager.getGroupManager().getGroups());
// Remove already joined groups
groups.removeAll(userGroups);
String search = null;
if (webManager.getGroupManager().isSearchSupported() && request.getParameter("search") != null
&& !request.getParameter("search").trim().isEmpty()) {
search = request.getParameter("search");
// Use the search terms to get the list of groups.
groups = new ArrayList<>(webManager.getGroupManager().search(search));
groups.removeAll(userGroups);
}
int groupCount = groups.size();
if (start < 0) {
start = 0;
}
if (start >= groupCount) {
start = Math.max(0, ((groupCount - 1) / range) * range);
}
int end = Math.min(start + range, groupCount);
List pagedGroups = groups.subList(start, end);
// paginator vars
int numPages = groupCount == 0 ? 1 : (int)Math.ceil((double)groupCount / range);
int curPage = groupCount == 0 ? 1 : (start / range) + 1;
pageContext.setAttribute("username", username);
pageContext.setAttribute("userGroups", userGroups);
pageContext.setAttribute("groupCount", groupCount);
pageContext.setAttribute("pagedGroups", pagedGroups);
pageContext.setAttribute("numPages", numPages);
pageContext.setAttribute("start", start);
pageContext.setAttribute("curPage", curPage);
pageContext.setAttribute("range", range);
pageContext.setAttribute("search", search);
%>
:
()
.
| |
|
|
|
|
|
"> "> |
.
,
-
[
]
| |
|
|
|
|
|
"> "> |
[
]