view src/nabble/view/web/mailing_list/UnsubscribeFromMailingList.java @ 19:18cf4872fd7f

remove anonymous posting
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 29 May 2020 22:58:25 -0600
parents 7ecd1a4ef557
children
line wrap: on
line source


package nabble.view.web.mailing_list;

import fschmidt.util.servlet.AuthorizingServlet;
import nabble.model.MailingList;
import nabble.model.ModelHome;
import nabble.model.Node;
import nabble.model.User;
import nabble.view.lib.Jtp;
import nabble.view.lib.Shared;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


public final class UnsubscribeFromMailingList extends HttpServlet implements AuthorizingServlet {

	public String getAuthorizationKey(HttpServletRequest request) throws ServletException {
		return Jtp.getReadAuthorizationKey( Jtp.getSiteNotNull(request).getNode(Jtp.getLong(request,"node")) );
	}

	public boolean authorize(String key,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		return Jtp.authorizeForRead(key,request,response);
	}

    protected void service(HttpServletRequest request,HttpServletResponse response)
		throws ServletException, IOException
	{
		User user = Jtp.getUser(request);

		if (user == null) {
			Jtp.login("You must login to unsubscribe from a mailing list.", request, response);
			return;
		}

		Node forum = Jtp.getSiteNotNull(request).getNode(Jtp.getLong(request, "node"));
		boolean allowed = Jtp.canBeEditedBy(forum,user);
		if (!allowed) {
			Jtp.login("Only administrators can proceed in this area.", request, response);
			return;
		}

		String errorMsg = null;
		boolean isSendEmail = "SendEmail".equals(request.getParameter("action"));

		MailingList mailingList = forum.getMailingList();
		String subscriptionAddress = mailingList.getSubscriberAddress().getAddrSpec();
		PrintWriter out = response.getWriter();
		char c = 'A';
		
		out.print( "\r\n<html>\r\n	<head>\r\n		<META NAME=\"robots\" CONTENT=\"noindex,nofollow\">\r\n		" );
 Shared.title(request,response,"How to Unsubscribe this Forum"); 
		out.print( "\r\n		<style type=\"text/css\">\r\n			div.field-title {\r\n				margin-top: 0;\r\n			}\r\n			td.number {\r\n				width: 3em;\r\n				padding-bottom: .2em;\r\n			}\r\n			span.number {\r\n				font-size: 200%;\r\n				padding: 0 .3em .03em;\r\n				border-width:1px;\r\n				border-style:solid;\r\n			}\r\n		</style>\r\n	</head>\r\n	<body>\r\n		" );
 Shared.minHeader(request, response, forum);
		out.print( "\r\n		" );
 Shared.editHeader(forum.getSubjectHtml(), "How to Unsubscribe this Forum", out); 
		out.print( "\r\n		" );
 Shared.errorMessage(request,response,errorMsg, "Please fix the error and try again." ); 
		out.print( "\r\n		" );

				if (isSendEmail && "POST".equals(request.getMethod())) {
					errorMsg = SubscribeToMailingList.sendRequest(forum, request, out);
					Shared.errorMessage(request, response, errorMsg, "Failed to send the request." );
				}
				
		out.print( "\r\n\r\n<div class=\"field-box light-border-color\">\r\n	<div class=\"second-font field-title\">General Instructions</div>\r\n	<div style=\"margin-left:1.5em\">\r\n		If you want to unsubscribe this forum from a mailing list, you have to remove the following email address from the mailing list subscriber's list:\r\n		<div class=\"info-message\" style=\"margin:.2em;padding:.2em;font-weight:bold\">" );
		out.print( (subscriptionAddress) );
		out.print( "</div>\r\n		This can be done in several ways. Below you can find the most common ones.\r\n	</div>\r\n</div>\r\n\r\n<div class=\"second-font field-title\" style=\"margin-top:1em\">Unsubscription Options</div>\r\n<div class=\"weak-color\">Choose the best option for this mailing list.</div>\r\n\r\n<div class=\"field-box light-border-color\">\r\n	<table style=\"margin-left:1.3em\">\r\n		<tr valign=\"top\">\r\n			<td class=\"number\"><span class=\"number shaded-bg-color medium-border-color\">" );
		out.print( (c++) );
		out.print( "</span></td>\r\n			<td>\r\n				<div class=\"second-font field-title\">Remove from subscriber's list</div>\r\n				Mailing list administrators usually can remove email addresses from the subscribers' list directly.\r\n				If you can do this, remove <b>" );
		out.print( (subscriptionAddress) );
		out.print( "</b> from that list.\r\n			</td>\r\n		</tr>\r\n	</table>\r\n</div>\r\n\r\n<div class=\"field-box light-border-color\">\r\n	<table style=\"margin-left:1.3em\">\r\n		<tr valign=\"top\">\r\n			<td class=\"number\"><span class=\"number shaded-bg-color medium-border-color\">" );
		out.print( (c++) );
		out.print( "</span></td>\r\n			<td>\r\n				<div class=\"second-font field-title\">Go to mailing list website</div>\r\n				You can go to the mailing list homepage (<a href=\"" );
		out.print( (mailingList.getUrl()) );
		out.print( "\">" );
		out.print( (mailingList.getUrl()) );
		out.print( "</a>)\r\n				and unsubscribe <b>" );
		out.print( (subscriptionAddress) );
		out.print( "</b> from the list.\r\n				The confirmation email will be forwarded to your email address as soon as it is received by Nabble.com.\r\n				You will have to follow the instructions in that email to confirm this request.\r\n			</td>\r\n		</tr>\r\n	</table>\r\n</div>\r\n" );
 SubscribeToMailingList.emailForm(forum, false, "Unsubscribe by email", "Send Unsubscription Request", c, request, out); 
		out.print( "\r\n" );
 Shared.footer(request,response); 
		out.print( "\r\n" );
 Shared.analytics(request,response); 
		out.print( "\r\n</body>\r\n</html>\r\n" );

	}

}