<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import="dao.*, vo.*, utils.*, exceptions.*, exceptions.sql.*"%> <%@page import="java.util.*"%> <% try{ String username = WebUtils.getParameter(request, "username"); String password = WebUtils.getParameter(request, "password"); String submitValue="Login"; String error=""; if(submitValue.equals(WebUtils.getParameter(request, submitValue))){//PROCESS if(username.equals("") || password.equals("")){ error="Invalid Username or Password. Please try again."; }else{ Database db = new Database(); UserDAO userDao = new UserDAO(db); try{ UserVO user = userDao.authenticateUser(username, password); UserSession userSession = new UserSession(request.getSession(true)); userSession.setUsername(user.getUsername()); userSession.setAuthorityLevel(user.getAuthorityLevel()); userSession.setUserId(user.getUserId()); if(user.getAuthorityLevel()==WebUtils.getSifuAuthorityLevel()){ SifuDAO sifuDao = new SifuDAO(db); SifuVO sifu = sifuDao.selectSifu(user.getUserId()); userSession.setSchoolId(sifu.getSchoolId()); } FileManager.writeLog(FileManager.getRealPath(this.getServletContext())+"/logs/userLog.txt", username); WebUtils.redirectHome(response, user.getAuthorityLevel()); }catch(InvalidUserException e){ //not a valid login, try again error = "Login Failed. Please try again."; } db.disconnect(); } } %> <%@include file="/include/header.htm"%> Login <% if(!error.equals("")){ %>

Error: <%=error%>

<% } %>
Login
Username:
Password:
<%@include file="/include/footer.htm"%> <% }catch(Exception e){ throw new WebException("index.jsp", e.getMessage()); } %>