PasswordMailSendAction.java 3.67 KB
Newer Older
Kim Gyeongeun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
package jp.agentec.sinaburocast.action.user;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.mail.MessagingException;

import jp.agentec.sinaburocast.action.AbstractAction;
import jp.agentec.sinaburocast.common.SinaburoConstant;
import jp.agentec.sinaburocast.common.annotation.NoLogin;
import jp.agentec.sinaburocast.common.exception.ExpectedException;
import jp.agentec.sinaburocast.common.exception.SystemException;
import jp.agentec.sinaburocast.common.util.SinaburoViewUtil;
import jp.agentec.sinaburocast.entity.Member;
import jp.agentec.sinaburocast.entity.PasswordMailSend;
import jp.agentec.sinaburocast.form.user.PasswordMailSendForm;
import jp.agentec.sinaburocast.service.MemberService;
import jp.agentec.sinaburocast.service.PasswordMailSendService;

import org.apache.log4j.Logger;
import org.seasar.framework.util.StringUtil;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;

/**
 * ID、パスワード問い合わせ
 *
 * @author choi-c
 *
 */
@NoLogin
public class PasswordMailSendAction extends AbstractAction {
	private final Logger logger = Logger.getLogger(getClass());

	@ActionForm
	public PasswordMailSendForm passwordMailSendForm;

	public MemberService memberService;
	
	public PasswordMailSendService passwordMailSendService;
	
	
	/**
	 * 初期表示
	 */
	@Execute(validator = false)
	public String index() {
		return "/user/passwordMailSend/passwordMailSend.html";
	}
	
	/**
	 * ID、パスワード問い合わせ押下
	 *
	 * @return
	 * @throws IOException
	 * @throws SystemException
	 * @throws ExpectedException
	 */
	@Execute(validator = true, input = "/user/passwordMailSend/passwordMailSend.html")
	public String passwordRemain() throws IOException, SystemException, ExpectedException,MessagingException, UnsupportedEncodingException {		
		//Eメール存在チェック
		List<Member> memberList =memberService.findByEmail(passwordMailSendForm.email);
		
		if(memberList.isEmpty()){
			//該当するデータがありません。
			addError(SinaburoViewUtil.getMessage("errors.E007"));
			return "/user/passwordMailSend/";
		}
		
		//メールを送り、データを登録する。
		try {
			int retValue = passwordMailSendService.insertPasswordMailSendLogic(memberList.get(0),passwordMailSendForm.email);
			if(retValue < 1){			
				addError(SinaburoViewUtil.getMessage("errors.S000"));
				return "/user/passwordMailSend/";			
			}
		} catch (MessagingException e) {
			logger.warn("Mail send failed." + e.toString());
			addError(SinaburoViewUtil.getMessage("errors.E055"));
			return "/user/passwordMailSend/";			
		}
		
		//ID、パスワード問い合わせ完了画面
		return "/user/passwordMailSend/passwordMailSendEnd.html";		        
	}
	
    
	/**
	 * ID、パスワード問い合わせメールのURL押下
	 * 
	 * @return
	 * @throws IOException
	 * @throws SystemException
	 * @throws ExpectedException
	 */
	@Execute(validator = false)
	public String confirm() throws IOException, SystemException, ExpectedException {
		
		if(StringUtil.isBlank(passwordMailSendForm.qUrlId1)){
			passwordMailSendForm.qUrlId1="";
		}
		
		PasswordMailSend passwordMailSend = passwordMailSendService.findByOneTypeTicket(passwordMailSendForm.qUrlId1,SinaburoConstant.MailType.PASSWORD);
		
		//
		if( passwordMailSend == null){
			request.setAttribute("errMsg", SinaburoViewUtil.getMessage("password.error"));
			return "/error/errorMsg.html";
		}
		
		
		passwordMailSendForm.member = memberService.findById(passwordMailSend.memberId);
		
		//テーブル削除
		passwordMailSendService.delete(passwordMailSend);

		return "/user/passwordMailSend/passwordMailSendConfirm.html";
	}

}