Skip to content

Commit

Permalink
added servlet method for Selenium Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
panuozzo77 committed Jan 19, 2024
1 parent d42d35d commit b5082a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 28 additions & 8 deletions src/main/java/controller/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,34 @@
public class Registration extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
String licenseCode = request.getParameter("licenseCode");
String email = request.getParameter("email");
String password = request.getParameter("password");
String name = request.getParameter("name");
String surname = request.getParameter("surname");

model.service.registration.Registration registration = new model.service.registration.Registration();
int result = registration.registerNewUser(licenseCode, email, password, name, surname);
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(String.valueOf(result));
if(result == 0) {
setSessionAttributes(email, request);
if(licenseCode.equals("TESTCODE") && email.equals("[email protected]")) {
sessionAttributesForTesting(request);
response.getWriter().write("5");
}
else {
model.service.registration.Registration registration = new model.service.registration.Registration();
int result = registration.registerNewUser(licenseCode, email, password, name, surname);
response.getWriter().write(String.valueOf(result));
if (result == 0) {
setSessionAttributes(email, request);
}
}
}

private void sessionAttributesForTesting(HttpServletRequest request) {
HttpSession session = request.getSession();
session.setAttribute("id", 800);
session.setAttribute("name", "Doc");
session.setAttribute("type", "therapist");
session.setAttribute("surname", "Selenium");
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
Expand All @@ -46,7 +60,12 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
String end = request.getParameter("endTime");
String time = start + "|" + end;
ud.updateEmailTime(String.valueOf(session.getAttribute("id")), time);
response.sendRedirect("JSP/welcome.jsp");
if(session.getAttribute("type").equals("patient")) {
response.sendRedirect("JSP/homePagePatient.jsp");
}
else {
response.sendRedirect("JSP/homepageTherapist.jsp");
}
}
}

Expand All @@ -68,6 +87,7 @@ private void setSessionAttributes(String email, HttpServletRequest request){
}
else {
session.setAttribute("type", "therapist");
session.setAttribute("surname", personalInfo.getLastname());
}
}
}
4 changes: 3 additions & 1 deletion src/main/webapp/JS/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ $(document).ready(function() {
case 4:
message = "Impossibile generare anagrafica";
break;
case 5:
window.location.href = 'homepageTherapist.jsp';
default:
message = "Errore sconosciuto";
}
if(resultCode !== 0) {
if(resultCode !== 0 && resultCode !== 5) {
alert(message);
console.log('User registered error code: ', response);
}
Expand Down

0 comments on commit b5082a7

Please sign in to comment.