Skip to content

Commit

Permalink
Added the methods for invitation in the Registration Service
Browse files Browse the repository at this point in the history
Removed testing componets;
Added "invitePatient" method in Registration
Modified RegistrationInterface, added needed method
  • Loading branch information
ms@Nicro authored and ms@Nicro committed Dec 26, 2023
1 parent 95403c1 commit e18da5f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 78 deletions.
41 changes: 0 additions & 41 deletions src/main/java/controller/LicenseController.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/model/DAO/DAOLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public String generateLicense(){
connection = DAOConnection.getConnection();
preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.setString(1, l.getSequence());
preparedStatement.setInt(2, -1); //TODO Rimovere questo, rimasuglio di testing
preparedStatement.setInt(2, 0);
preparedStatement.setDate(3, null);
preparedStatement.executeUpdate();
return l.getSequence();
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/model/service/license/LicenseActivation.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ public void activate(License license, int userId) {
daoLicense.activate(license, userId);
}

public void generatePin(int therapistId) {
//TODO
// Implement the logic to generate a new license with a 4-character pin
// and associate it with the provided therapistId
}
public String generatePin(int therapistId) {return daoLicense.generateInvitation(therapistId); }

public void generateLicense() {
//TODO
// Implement the logic to generate a new license with 8 characters and therapistId 0
}
public String generateLicense() {return daoLicense.generateLicense(); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public interface LicenseActivationInterface {
* genera una nuova licenza da 4 caratteri e con l'ID del terapeuta
*
* @param therapistId è l'identificativo del terapeuta
* @return il pin generato ed inserito nel database, null altrimenti
*/
void generatePin(int therapistId);
String generatePin(int therapistId);

/**
* genera una nuova licenza da 8 caratteri e con ID terapeuta 0
* @return la licenza generata ed inserita nel database, null altrimenti
*/
void generateLicense();
String generateLicense();

}
6 changes: 3 additions & 3 deletions src/main/java/model/service/login/Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Authenticator implements LoginInterface {
DAOUser db = new DAOUser();
@Override
public String resetPassword(String email) {
if(email.equals("[email protected]")) {
if(email.equals("[email protected]")) { //TODO: Rimuovere rimasuglio di Testing
return "12345678";
}
else {
Expand All @@ -27,10 +27,10 @@ public String resetPassword(String email) {

public boolean resetPassword(String email, String plainTextPassword){
Encryption encryption = new Encryption();
System.out.println("password in chiaro: " + plainTextPassword);
System.out.println("password in chiaro: " + plainTextPassword); //TODO: Rimuovere rimasuglio di Testing
String hashed = encryption.encryptPassword(plainTextPassword);
boolean Result = db.resetPassword(email,hashed);
System.out.println("cambiato password, esito:" + Result);
System.out.println("cambiato password, esito:" + Result); //TODO: Rimuovere rimasuglio di Testing
return Result;
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/model/service/registration/Registration.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package model.service.registration;
import model.service.email.EmailManager;
import model.service.encryption.Encryption;
import model.service.license.LicenseActivation;
import model.entity.License;
Expand Down Expand Up @@ -47,7 +48,24 @@ public int register(String licenseCode, String email, String password, String na
return 2; //email non valida
}
return 1; //licenza non valida
}

public boolean invitePatient(int therapistId, String patientEmail, String patientName, String patientSurname){
UserData ud = new UserData();

if(!ud.checkIfEmailExists(patientEmail)) {
EmailManager tool = new EmailManager();
LicenseActivation la = new LicenseActivation();

String pin = la.generatePin(therapistId);
if(pin!=null){
String body = "Salve "+ patientSurname + patientName + ". Ecco il tuo codice per registrarti a TalkAid: "+ pin;

tool.sendEmail(patientEmail, "Sei stato invitato a TalkAID!", body);
return true;
}
}
return false;
}

public boolean resetFromOldPassword(String email, String oldpw, String newpw) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public interface RegistrationInterface {
*/
int register(String licenseCode, String email, String password, String name, String surname);

/**
* invita un nuovo paziente, inviandogli una mail con il pin per la registrazione
* @param therapistId è l'id del terapista che vuole invitare un nuovo paziente
* @param patientEmail è l'email del paziente che il terapista vuole inviare
* @param patientName è il nome del paziente
* @param patientSurname è il cognome del paziente
* @return True se è stato invitato, False altrimenti
*/
boolean invitePatient(int therapistId, String patientEmail, String patientName, String patientSurname);

/**
* cambia la password da una vecchia a quella nuova
* @param email è l'email inserita dell'account
Expand Down
22 changes: 0 additions & 22 deletions src/main/webapp/JS/testingInvitationAndLicense.js

This file was deleted.

0 comments on commit e18da5f

Please sign in to comment.