package com.javahonk.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;

@Results({
		@Result(name = "success", location = "/WEB-INF/jsp/welcome.jsp"),
		@Result(name = "error", location = "/index.jsp"),
		@Result(name = "input", location = "/index.jsp") })
public class LoginAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String loginid;
	private String password;
	
	@Override
	@Action(value="/loginAction")
	public String execute() throws Exception {
		
		if (null == loginid || loginid.length() == 0){
			addActionError(getText("error.login.required"));
			return ActionSupport.ERROR;
		}
		if (null == password || password.length() == 0){
			addActionError(getText("error.password.required"));
			return ActionSupport.ERROR;
		}
		if (!(loginid.equalsIgnoreCase("Java") 
				&& password.equalsIgnoreCase("Honk"))){
			addActionError(getText("error.loginid_OR_password.incorrect"));
			return ActionSupport.ERROR;
		}
		
		return ActionSupport.SUCCESS;		
		
	}	

	public String getLoginid() {
		return loginid;
	}
	
	@RequiredStringValidator(message = "Please enter your Login Id!")
	public void setLoginid(String loginid) {
		this.loginid = loginid;
	}

	public String getPassword() {
		return password;
	}

	@RequiredStringValidator(message = "Please enter your password!")
	public void setPassword(String password) {
		this.password = password;
	}


}
