Skip to content

Commit

Permalink
Completed be for invitation of patients
Browse files Browse the repository at this point in the history
  • Loading branch information
ms@Nicro authored and ms@Nicro committed Jan 6, 2024
2 parents e18da5f + 1cafeee commit 3dded15
Show file tree
Hide file tree
Showing 177 changed files with 11,898 additions and 246 deletions.
7 changes: 7 additions & 0 deletions META-INF/application.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_9.xsd"
version="9">

</application>
5 changes: 5 additions & 0 deletions META-INF/glassfish-application.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-application PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Java EE Application 6.0//EN"
"http://glassfish.org/dtds/glassfish-application_6_0-1.dtd">
<glassfish-application>
</glassfish-application>
161 changes: 147 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,39 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<junit.version>5.10.0</junit.version>
<sonar.organization>panuozzo77</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>https://repo1.maven.org/maven2/</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>


<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand All @@ -31,13 +58,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand All @@ -56,27 +76,140 @@
<artifactId>jakarta.mail</artifactId>
<version>1.6.5</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.4</version>
</dependency>

<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.4</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>

<dependency>
<groupId>com.mockrunner</groupId>
<artifactId>mockrunner-servlet</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.mockrunner</groupId>
<artifactId>mockrunner-struts</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.3</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.2.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>
-Xmx1024M ${argLine}
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
<append>false</append>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
30 changes: 7 additions & 23 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,16 @@
import model.DAO.DAOUser;
import model.entity.User;
import model.service.login.Authenticator;
//import model.service.message.Conversation;
import model.service.registration.Registration;

public class Main {
public static void main(String[] args) {
Encryption encryption = new Encryption();
DAOUser db = new DAOUser();
String plainTextPassword = "123456";
EmailManager message = new EmailManager();
Authenticator auth = new Authenticator();
Registration r = new Registration();

/*
String hashedPassword = encryption.encryptPassword(plainTextPassword);
// Use hashed password to create new user
db.createUser("[email protected]", hashedPassword, 0);
*/

/*
User user = db.getUserByIdOrEmail("[email protected]");
System.out.println(encryption.verifyPassword(plainTextPassword, user.getPassword()));
*/


//test email
//message.sendEmail("[email protected]", "Email Test", "questo è una email di test");

//test email recupero password
Authenticator authenticator = new Authenticator();
System.out.println(authenticator.authenticate("[email protected]", "123456"));
System.out.println(auth.authenticate("[email protected]", "pwd"));
System.out.println(auth.authenticate("[email protected]", "pwd"));
r.invitePatient(9, "[email protected]", "Raffaele", "Monti");
}
}
38 changes: 38 additions & 0 deletions src/main/java/controller/AddRemovePatientCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package controller;

import model.service.condition.ConditionManager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/AddRemovePatientCondition")
public class AddRemovePatientCondition extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String referer = request.getHeader("Referer");
ConditionManager conditionService= new ConditionManager();

int idPatient = Integer.parseInt(request.getParameter("idPatient"));
int idCondition = Integer.parseInt(request.getParameter("idCondition"));

String operation= request.getParameter("operation");
if (operation.equals("Rimuovi")) //REMOVE
{
conditionService.RemoveConditionPatient(idCondition,idPatient);
}
if (operation.equals("Aggiungi")) //ADD
{
int severity= Integer.parseInt(request.getParameter("severity"));
conditionService.AddConditionPatient(idCondition,idPatient,severity);
}

response.sendRedirect(referer);

}

}
24 changes: 24 additions & 0 deletions src/main/java/controller/ChangePassword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package controller;

import model.service.login.Authenticator;
import model.service.user.UserData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ChangePassword")
public class ChangePassword extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String password = request.getParameter("password");
String password_control = password.replaceAll("\\s", "");
int id = (int) request.getSession().getAttribute("id");
new Authenticator().resetPassword( new UserData().getUser(id).getEmail(), password_control);
response.getWriter().write("true");
}
}
39 changes: 39 additions & 0 deletions src/main/java/controller/ChangeUserInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package controller;

import model.service.user.UserRegistry;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/changeDate")
public class ChangeUserInfo extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
int userId = (int) session.getAttribute("id");
UserRegistry userRegistry = new UserRegistry();
String risultato = "";
if (updatePersonalInfo(request, userId, userRegistry)) {
risultato = "Dati personali aggiornati con successo;";
} else {
risultato = "Dati personali non aggiornati, email gia' utilizzata";
}
response.sendRedirect("/TalkAID_war_exploded/JSP/Cambio_dati.jsp?risultato=" + risultato);
}

private boolean updatePersonalInfo(HttpServletRequest request, int userId, UserRegistry userRegistry) {
String firstName = request.getParameter("firstname");
String lastName = request.getParameter("lastname");
String phoneNumber = request.getParameter("phonenumber");
String email = request.getParameter("email");
String address = request.getParameter("address");
if (!firstName.isEmpty() || !lastName.isEmpty() || !phoneNumber.isEmpty()) {
return userRegistry.updatePersonaInfofromId(userId, firstName, lastName, phoneNumber,email,address);
}
return false;
}
}
24 changes: 24 additions & 0 deletions src/main/java/controller/CheckCurrentPassword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package controller;

import model.service.login.Authenticator;
import model.service.user.UserData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ControllPassword")
public class CheckCurrentPassword extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String password = request.getParameter("password");
Authenticator authenticator = new Authenticator();
int id = (int) request.getSession().getAttribute("id");
String email = new UserData().getUser(id).getEmail();
response.getWriter().write(String.valueOf(authenticator.authenticate(email, password) > 0)); //true se deve abilitare, false altrimenti
}
}
Loading

0 comments on commit 3dded15

Please sign in to comment.