
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for Servlet: LogIn
 *
 */
public class LogIn extends javax.servlet.http.HttpServlet {

    static final long serialVersionUID = 1L;

    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#HttpServlet()
     */
    public LogIn() {
        super();
    }

    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String s = request.getParameter("T1");
        String s1 = request.getParameter("T2");
        boolean b = DataBase.authenticateUser(s, s1);
       
        if (b) {

          
            if (DataBase.getIsAdmin(s)==1) {
                RequestDispatcher rd = request.getRequestDispatcher("admin.jsp");
                rd.forward(request, response);
            }
            else{
                String firstname=DataBase.getUserName(s);
                response.sendRedirect("welcome.jsp?fname="+firstname+"&id="+s);
             }
         } else {
            request.setAttribute("invalid", "invalid");
            response.sendRedirect("incorrect_username_pass.jsp");
        }
    }

    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }
}