package test.struts;

import javax.servlet.http.*;
import org.apache.struts.action.*;

public class LoginBean {

	String userType, userId ,passWord;

	public LoginBean() {}

	public void setParameters(HttpServletRequest request) {
		userId = request.getParameter("userId");
		passWord = request.getParameter("passWord");
	}

	public ActionErrors validate() {

		if (!userId.equals(passWord)) {
			ActionErrors ae = new ActionErrors();
			ae.add("userId", new ActionError("error.invalid.login"));
			return ae;
		}

		if (userId.equals("admin")) {
			userType = "Adminstrator";
		} else
		if (userId.equals("user")) {
			userType = "User";
		} else {
			ActionErrors ae = new ActionErrors();
			ae.add("userId", new ActionError("error.invalid.login"));
			return ae;
		}

		return null;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}
}