Skip to content

Commit

Permalink
Changes by ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewaaa committed Jan 6, 2024
1 parent 47f697a commit 00c97b5
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/main/java/controller/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -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();
Expand All @@ -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<UserInfo> 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);
}
}

}

0 comments on commit 00c97b5

Please sign in to comment.