package com.github.aureliano.verbum_domini.web.mb;

import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.apache.log4j.Logger;

import com.github.aureliano.verbum_domini.helper.WebHelper;
import com.github.aureliano.verbum_domini.web.bc.SignInBC;

@ManagedBean(name = "signInMB")
@RequestScoped
public class SignInMB {
	
	private static final Logger logger = Logger.getLogger(SignInMB.class);

	private String login;
	private String password;
	
	public SignInMB() {
		super();
	}
	
	public void signIn() {
		List<FacesMessage> messages = SignInBC.authenticate(this.login, this.password);
		if (messages.isEmpty()) {
			logger.info("User " + this.login + " has just signed in.");
			WebHelper.setSessionAttribute("user_login", this.login);
			WebHelper.sendRedirect("/verbumdomini/");
			
			return;
		}
		
		WebHelper.addMessagesToContext(messages);
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
}
@@ -488,16 +488,76 @@
 .class);
+%0A%09private static final String USER_LOGIN_KEY = %22user_login%22;
 %0A%0A%09priva
@@ -868,28 +868,30 @@
 tribute(
-%22user_login%22
+USER_LOGIN_KEY
 , this.l
@@ -1006,24 +1006,128 @@
 essages);%0A%09%7D
+%0A%09%0A%09public boolean isUserSignedIn() %7B%0A%09%09return WebHelper.getSessionAttribute(USER_LOGIN_KEY) != null;%0A%09%7D
 %0A%0A%09public St

Validate if current user is signed in.