diff --git a/src/main/java/controller/Login.java b/src/main/java/controller/Login.java index a32856d..ced5818 100644 --- a/src/main/java/controller/Login.java +++ b/src/main/java/controller/Login.java @@ -2,7 +2,9 @@ import model.entity.PersonalInfo; import model.entity.User; +import model.entity.UserInfo; import model.service.login.Authenticator; +import model.service.personalinfo.PersonalInfoManager; import model.service.user.UserData; import model.service.user.UserRegistry; @@ -12,6 +14,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; +import java.util.ArrayList; @WebServlet("/login") public class Login extends HttpServlet { @@ -36,15 +39,15 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) if (result > 0) { // Login success, defining its Session attributes - setSessionAttributes(result,request); - response.sendRedirect("JSP/welcome.jsp"); + setSessionAttributes(result, request, response); + //response.sendRedirect("JSP/welcome.jsp"); Viene gestita sopra il redirect in base all'utente } else { // Login failed, redirect back to the login page response.sendRedirect("JSP/login.jsp?error=1"); } } - private void setSessionAttributes(int id, HttpServletRequest request){ + private void setSessionAttributes(int id, HttpServletRequest request, HttpServletResponse response){ HttpSession session = request.getSession(); userData = new UserData(); @@ -57,12 +60,39 @@ private void setSessionAttributes(int id, HttpServletRequest request){ session.setAttribute("name", personalInfo.getFirstname()); if(!userData.isTherapist(user)) { + session.setAttribute("type", "patient"); session.setAttribute("therapist", user.getIdTherapist()); + try { + response.sendRedirect("JSP/homepagepatient.jsp"); + } catch (IOException e) { + throw new RuntimeException(e); + } } else { + setPatientsInfo(session); session.setAttribute("type", "therapist"); + try { + response.sendRedirect("JSP/homeTherapist.jsp"); + } catch (IOException e) { + throw new RuntimeException(e); + } } } + private void setPatientsInfo(HttpSession session){ + + UserData userService = new UserData(); + PersonalInfoManager piService = new PersonalInfoManager(); + + ArrayList list_user = new ArrayList<>(); + list_user = userService.getUsersAndPersonalInfoByIdTherapist((Integer) session.getAttribute("id")); //save all patient of X therapist + + session.setAttribute("list_user",list_user); + + PersonalInfo InfoLogged=piService.getPersonalInfoById((Integer) session.getAttribute("id")); + if(InfoLogged!=null) + session.setAttribute("NameSurnameLogged", InfoLogged.getFirstname() + " " + InfoLogged.getLastname()); + else session.setAttribute("NameSurnameLogged",null); + } +} -} \ No newline at end of file