Advertisement
ballchaichana

loginAdmin

Oct 3rd, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. package th.in.oneauthen.admin;
  2.  
  3. import java.io.IOException;
  4. import java.util.Date;
  5.  
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12.  
  13.  
  14.  
  15. import th.in.oneauthen.object.UserUidDB;
  16. import th.in.oneauthen.object.DAO.UserUidDAO;
  17.  
  18. /**
  19.  * Servlet implementation class LoginServlet
  20.  */
  21. @WebServlet("/loginAdmin")
  22.  
  23. public class LoginAdmin extends HttpServlet {
  24.  
  25.  
  26.     /**
  27.      *
  28.      */
  29.     private static final long serialVersionUID = 1L;
  30.     public static final String SESSION_PARAM_ADMIN = "adminSession";
  31.  
  32.     public static final String REQUEST_PARAM_USERNAME = "username";
  33.     public static final String REQUEST_PARAM_PASSWORD = "password";
  34.  
  35.     public static final String DASHBOARD_URL = "dashboard.jsp";
  36.     public static final String DASHBOARD_SINGING = "dashboard.jsp?reqp=signing";
  37.  
  38.     /**
  39.      * @see HttpServlet#HttpServlet()
  40.      */
  41.     public LoginAdmin() {
  42.         super();
  43.         // TODO Auto-generated constructor stub
  44.     }
  45.  
  46.  
  47.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  48.             throws ServletException, IOException {
  49.         // TODO Auto-generated method stub
  50.  
  51.  
  52.         String username = request.getParameter(REQUEST_PARAM_USERNAME);
  53.         String password = request.getParameter(REQUEST_PARAM_PASSWORD);
  54.        
  55.        
  56.  
  57.  
  58.  
  59.             //////////////////////////////////////////////////////////////////////
  60.             UserUidDAO userDao = new UserUidDAO();
  61.  
  62.             UserUidDB user = null;
  63.  
  64.             if (userDao.findUsername(username) != null) {
  65.                 user = userDao.findUsername(username);
  66.             }
  67.             System.out.println("DAO: " + user);
  68.  
  69.             if (user == null) {
  70.                 LogoutAdmin.doLogout(request, response, "Login Failed!! Incorrect Username");          
  71.             }
  72.             else if(password != user.getPassword()){
  73.                 LogoutAdmin.doLogout(request, response, "Login Failed!!  Incorrect Password");
  74.             }else {
  75.                 System.out.println("Login success!!");
  76.                 UserUidDAO ball = new UserUidDAO();
  77.                 user.setLastLogin(new Date());
  78.  
  79.                 ball.updateTimeLogin(user);
  80.  
  81.                 request.getSession().setAttribute(SESSION_PARAM_ADMIN, user);
  82.                 request.getRequestDispatcher(DASHBOARD_URL).forward(request, response);
  83.                
  84.             }
  85.  
  86.  
  87.  
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement