All Downloads are FREE. Search and download functionalities are using the official Maven repository.

base.jee.servlet.SuspendedAccountsServlet Maven / Gradle / Ivy

Go to download

A collection of basic java utility classes that provide basic features for a standalone/simple JEE application. Backed by a Cassandra, MySQL, or SQLite database, it provides, web page templates, user and group management, and a searchable online audit log of all user activity.

There is a newer version: 1.5.4
Show newest version
/*
 This is free and unencumbered software released into the public domain.

 Anyone is free to copy, modify, publish, use, compile, sell, or
 distribute this software, either in source code form or as a compiled
 binary, for any purpose, commercial or non-commercial, and by any
 means.

 In jurisdictions that recognize copyright laws, the author or authors
 of this software dedicate any and all copyright interest in the
 software to the public domain. We make this dedication for the benefit
 of the public at large and to the detriment of our heirs and
 successors. We intend this dedication to be an overt act of
 relinquishment in perpetuity of all present and future rights to this
 software under copyright law.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
package base.jee.servlet;

import base.jee.Breadcrumb;
import base.jee.Constants;
import base.jee.JeeBase;
import base.jee.api.model.Throttle;
import base.jee.api.sql.SearchPeople;
import base.security.PermissionException;
import base.security.User;
import base.text.StringHelper;
import org.stringtemplate.v4.ST;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Display people search form and people search results.
 */
public class SuspendedAccountsServlet extends BaseServlet {

	private static final long serialVersionUID = 1L;

	public SuspendedAccountsServlet(JeeBase jee) throws IOException {
		super(jee);
	}

	@SuppressWarnings("unchecked")
	public void doGet(User u, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String error = null;
		String success = null;

		String a = request.getParameter("a");
		if(a != null && !a.equals(u.getFormAuthToken())) {
			throw new IllegalArgumentException("Invalid authentication token.");
		}

		if(!u.hasRole(Constants.PERSON_MANAGE_ROLE)) {
			throw new PermissionException(SearchPeople.class.getSimpleName(), u, "You do not have permission to manage person details.", Constants.PERSON_MANAGE_ROLE);
		}

		if(a != null && request.getParameter("uuid") != null) {
			Throttle r = jee.getAPI().deleteThrottle(u, request.getParameter("uuid"));
			if(r != null) {
				success = "Removed throttle on " + StringHelper.escapeHtml(r.getUid()) + ".";
			}
		}

		List suspension = null;
		String q = request.getParameter("q");
		if(q == null) { q = ""; }
		q = q.trim();

		suspension = jee.getAPI().getThrottles(u);

		ST page = jee.getPage(u, "suspended_accounts");
		if(q.length() == 0) {
			page.add("q", null);
		} else {
			page.add("q", q);
		}
		page.add("suspension", suspension);
		page.add("error", error);
		page.add("success", success);
		page.add("auth", u.getFormAuthToken());
		page.add("breadcrumbs", new Breadcrumb("People", "/people?q=" + StringHelper.urlEscape(q)));
		page.add("breadcrumbs", new Breadcrumb("Suspended Accounts", null));

		response.getWriter().write(page.render());

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy