package inc.monsters.mias;

import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;

public class LoginBean {
	private String userName;
	private String password;
	private String captcha;
	private String captchaSessionVar;
	
	/* This map will be filled by the FacesServlet, via a managed property */
	private Map<String, String> logins;

	public void setLogins(Map<String, String> logins) {
		this.logins = logins;
	}

	public synchronized Map<String, String> getLogins() {
		return logins;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getCaptcha() {
		return captcha;
	}

	public void setCaptcha(String captcha) {
		this.captcha = captcha;
	}

	public String getCaptchaSessionVar() {
		return captchaSessionVar;
	}

	public void setCaptchaSessionVar(String captchaSessionVar) {
		this.captchaSessionVar = captchaSessionVar;
	}

	public String login() {
		if (getUserName() != null 
				&& getLogins().get(getUserName()) != null
				&& getLogins().get(getUserName()).equals(getPassword())) {
			return "login";
		} else {
			return "error";
		}
	}
}
