/*
 * $Id$
 * $URL$
 */

package org.subethamail.web.action;

import lombok.Getter;
import lombok.Setter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.subethamail.core.acct.i.AuthSubscribeResult;
import org.subethamail.core.acct.i.BadTokenException;
import org.subethamail.core.acct.i.SubscribeResult;
import org.subethamail.web.Backend;
import org.subethamail.web.action.auth.AuthAction;

/**
 * Subscribes an anonymous (not logged in) user to a mailing list.
 * 
 * @author Jeff Schnitzer
 */
public class SubscribeConfirm extends AuthAction 
{
	/** */
	@SuppressWarnings("unused")
	private final static Logger log = LoggerFactory.getLogger(SubscribeConfirm.class);
	
	/** */
	@Getter @Setter String token = "";
	@Getter @Setter boolean badTokenError;
	@Getter @Setter boolean held;
	@Getter @Setter Long listId;

	/** */
	public void execute() throws Exception
	{
		try
		{
			AuthSubscribeResult authResult = Backend.instance().getAccountMgr().subscribeAnonymous(this.token);
			
			this.listId = authResult.getListId();
			
			if (SubscribeResult.HELD.equals(authResult.getResult()))
			{
				this.held = true;
			}
			
			this.login(authResult.getEmail(), authResult.getPassword());
		}
		catch (BadTokenException ex)
		{
			this.badTokenError = true;
		}
	}
	
}

/*
 * $Id$
 * $URL$
 */

package org.subethamail.web.action;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.java.Log;

import org.subethamail.core.acct.i.AuthSubscribeResult;
import org.subethamail.core.acct.i.BadTokenException;
import org.subethamail.core.acct.i.SubscribeResult;
import org.subethamail.web.Backend;
import org.subethamail.web.action.auth.AuthAction;

/**
 * Subscribes an anonymous (not logged in) user to a mailing list.
 * 
 * @author Jeff Schnitzer
 */
@Log
public class SubscribeConfirm extends AuthAction 
{
	/** */
	@Getter @Setter String token = "";
	@Getter @Setter boolean badTokenError;
	@Getter @Setter boolean held;
	@Getter @Setter Long listId;

	/** */
	public void execute() throws Exception
	{
		try
		{
			AuthSubscribeResult authResult = Backend.instance().getAccountMgr().subscribeAnonymous(this.token);
			
			this.listId = authResult.getListId();
			
			if (SubscribeResult.HELD.equals(authResult.getResult()))
			{
				this.held = true;
			}
			
			this.login(authResult.getEmail(), authResult.getPassword());
		}
		catch (BadTokenException ex)
		{
			this.badTokenError = true;
		}
	}
	
}

switch logging framework