// Path: src/main/java/com/adintellig/ella/dao/UserDaoImpl.java
// public class UserDaoImpl {
// 	private static Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
// 
// 	public User findByNameAndPassword(String username, String password)
// 			throws SQLException {
// 		String sql = "select * from hbase.user where username=? and password=?";
// 
// 		Connection conn = JdbcUtil.getConnection();
// 		PreparedStatement ps = conn.prepareStatement(sql);
// 		ps.setString(1, username);
// 		ps.setString(2, password);
// 		ResultSet rs = ps.executeQuery();
// 		logger.info("[QUERY]: " + sql);
// 
// 		User u = null;
// 		if (rs.next()) {
// 			u = new User();
// 			u.setUsername(rs.getString("username"));
// 			u.setPassword(rs.getString("password"));
// 		}
// 		JdbcUtil.close(conn,ps,rs);
// 		return u;
// 	}
// }
// 
// Path: src/main/java/com/adintellig/ella/model/user/User.java
// public class User {
// 
// 	private String username;
// 	private String password;
// 	private Timestamp update_time;
// 
// 	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 Timestamp getUpdate_time() {
// 		return update_time;
// 	}
// 
// 	public void setUpdate_time(Timestamp update_time) {
// 		this.update_time = update_time;
// 	}
// 
// }


import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.dao.UserDaoImpl;
import com.adintellig.ella.model.user.User;
package com.adintellig.ella.action;





public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger logger = LoggerFactory.getLogger(LoginServlet.class);

	UserDaoImpl dao = new UserDaoImpl();

	@Override
	public void init() throws ServletException {

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		logger.info("{POST}");
		
		RequestDispatcher dispatcher = null;
		String username = request.getParameter("username").trim();
		String password = request.getParameter("password").trim();

		HttpSession session = request.getSession(true);

		String sessionUsername = (String) session.getAttribute("username");
		
		logger.info("username=" + username + 
				" password=" + password + " sessionuname=" + sessionUsername);

		if (null != sessionUsername && sessionUsername.length() > 0)
			sessionUsername = sessionUsername.trim();

		if (username.equals(sessionUsername)) {
			dispatcher = request.getRequestDispatcher("/index.jsp");
			dispatcher.forward(request, response);
		} else {
			try {
// Path: src/main/java/com/adintellig/ella/dao/UserDaoImpl.java
// public class UserDaoImpl {
// 	private static Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
// 
// 	public User findByNameAndPassword(String username, String password)
// 			throws SQLException {
// 		String sql = "select * from hbase.user where username=? and password=?";
// 
// 		Connection conn = JdbcUtil.getConnection();
// 		PreparedStatement ps = conn.prepareStatement(sql);
// 		ps.setString(1, username);
// 		ps.setString(2, password);
// 		ResultSet rs = ps.executeQuery();
// 		logger.info("[QUERY]: " + sql);
// 
// 		User u = null;
// 		if (rs.next()) {
// 			u = new User();
// 			u.setUsername(rs.getString("username"));
// 			u.setPassword(rs.getString("password"));
// 		}
// 		JdbcUtil.close(conn,ps,rs);
// 		return u;
// 	}
// }
// 
// Path: src/main/java/com/adintellig/ella/model/user/User.java
// public class User {
// 
// 	private String username;
// 	private String password;
// 	private Timestamp update_time;
// 
// 	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 Timestamp getUpdate_time() {
// 		return update_time;
// 	}
// 
// 	public void setUpdate_time(Timestamp update_time) {
// 		this.update_time = update_time;
// 	}
// 
// }


// Path: src/main/java/com/adintellig/ella/action/LoginServlet.java
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.dao.UserDaoImpl;
import com.adintellig.ella.model.user.User;

package com.adintellig.ella.action;





public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger logger = LoggerFactory.getLogger(LoginServlet.class);

	UserDaoImpl dao = new UserDaoImpl();

	@Override
	public void init() throws ServletException {

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		logger.info("{POST}");
		
		RequestDispatcher dispatcher = null;
		String username = request.getParameter("username").trim();
		String password = request.getParameter("password").trim();

		HttpSession session = request.getSession(true);

		String sessionUsername = (String) session.getAttribute("username");
		
		logger.info("username=" + username + 
				" password=" + password + " sessionuname=" + sessionUsername);

		if (null != sessionUsername && sessionUsername.length() > 0)
			sessionUsername = sessionUsername.trim();

		if (username.equals(sessionUsername)) {
			dispatcher = request.getRequestDispatcher("/index.jsp");
			dispatcher.forward(request, response);
		} else {
			try {
				User u = dao.findByNameAndPassword(username, password);