Incluidas clases para permitir el login de diferentes tipos de usuaario.
* POJO para usuario logeado. * Hash para claves de usuarios * Métodos EJB para login
This commit is contained in:
@@ -9,6 +9,7 @@ import TO.MedicalSpecialtyTO;
|
||||
import TO.PatientTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import TO.SpecialistDoctorTO;
|
||||
import common.HashUtils;
|
||||
import jpa.FamilyDoctorJPA;
|
||||
import jpa.MedicalSpecialtyJPA;
|
||||
import jpa.PatientJPA;
|
||||
@@ -45,7 +46,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
public PatientTO registerPatient(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
PatientTO paTO = null;
|
||||
|
||||
PatientJPA ms = new PatientJPA(id, nif, name, surname, password, email);
|
||||
PatientJPA ms = new PatientJPA(id, nif, name, surname, HashUtils.hashMD5(password), email);
|
||||
entman.persist(ms);
|
||||
paTO = new PatientTO(ms.getId(), ms.getNif(), ms.getName(), ms.getSurname(), ms.getPassword(), ms.getEmail());
|
||||
|
||||
@@ -59,7 +60,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
|
||||
// TODO: Lanzar error si no se encuentra la especialidad.
|
||||
if (ms != null) {
|
||||
SpecialistDoctorJPA sd = new SpecialistDoctorJPA(id, nif, name, surname, password, email);
|
||||
SpecialistDoctorJPA sd = new SpecialistDoctorJPA(id, nif, name, surname, HashUtils.hashMD5(password), email);
|
||||
entman.persist(sd);
|
||||
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail());
|
||||
}
|
||||
@@ -75,7 +76,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
// TODO: Lanzar error si no encontramos el cap!!!!!
|
||||
if (phcC != null) {
|
||||
|
||||
FamilyDoctorJPA fd = new FamilyDoctorJPA(id, nif, name, surname, password, email);
|
||||
FamilyDoctorJPA fd = new FamilyDoctorJPA(id, nif, name, surname, HashUtils.hashMD5(password), email);
|
||||
fd.setPrimaryHealthCareCenter(phcC);
|
||||
|
||||
entman.persist(fd);
|
||||
@@ -94,7 +95,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
fd.setNif(nif);
|
||||
fd.setName(name);
|
||||
fd.setSurname(surname);
|
||||
fd.setPassword(password);
|
||||
fd.setPassword(HashUtils.hashMD5(password));
|
||||
fd.setEmail(email);
|
||||
|
||||
entman.persist(fd);
|
||||
@@ -117,7 +118,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
sd.setNif(nif);
|
||||
sd.setName(name);
|
||||
sd.setSurname(surname);
|
||||
sd.setPassword(password);
|
||||
sd.setPassword(HashUtils.hashMD5(password));
|
||||
sd.setEmail(email);
|
||||
sd.setMedicalSpecialty(ms);
|
||||
|
||||
@@ -137,7 +138,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
fd.setNif(nif);
|
||||
fd.setName(name);
|
||||
fd.setSurname(surname);
|
||||
fd.setPassword(password);
|
||||
fd.setPassword(HashUtils.hashMD5(password));
|
||||
fd.setEmail(email);
|
||||
|
||||
// TODO: Es posible actualizar el cap? ¿No debería utilizar el método
|
||||
|
||||
@@ -8,10 +8,17 @@ import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import TO.LoggedUserTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import common.HashUtils;
|
||||
import jpa.AdministratorJPA;
|
||||
import jpa.FamilyDoctorJPA;
|
||||
import jpa.MedicalSpecialtyJPA;
|
||||
import jpa.PatientJPA;
|
||||
import jpa.PrimaryHealthCareCenterJPA;
|
||||
import jpa.SpecialistDoctorJPA;
|
||||
import managedbean.common.UserType;
|
||||
|
||||
/**
|
||||
* EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los
|
||||
@@ -83,4 +90,44 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
|
||||
return allCAPs;
|
||||
}
|
||||
|
||||
public LoggedUserTO login(String id, String pwd) {
|
||||
LoggedUserTO usr = null;
|
||||
|
||||
// First try to login as Admin
|
||||
AdministratorJPA adm = entman.find(AdministratorJPA.class, id);
|
||||
if (adm != null) {
|
||||
usr = new LoggedUserTO(adm.getEmail(), "", adm.getPassword(), UserType.ADMINISTRADOR);
|
||||
} else {
|
||||
Integer iId = Integer.valueOf(id);
|
||||
// Try to login Patient
|
||||
PatientJPA pat = entman.find(PatientJPA.class, iId);
|
||||
|
||||
if (pat != null) {
|
||||
usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), UserType.PATIENT);
|
||||
} else {
|
||||
FamilyDoctorJPA fdoc = entman.find(FamilyDoctorJPA.class, iId);
|
||||
|
||||
if (fdoc != null) {
|
||||
usr = new LoggedUserTO(fdoc.getId().toString(), fdoc.getName(), fdoc.getPassword(), UserType.FAMILY_DOCTOR);
|
||||
} else {
|
||||
SpecialistDoctorJPA sdoc = entman.find(SpecialistDoctorJPA.class, iId);
|
||||
|
||||
if (sdoc != null) {
|
||||
usr = new LoggedUserTO(sdoc.getId().toString(), sdoc.getName(), sdoc.getPassword(), UserType.SPECIALIST_DOCTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (usr != null) {
|
||||
// Comprobamos el password
|
||||
if (usr.getPassword().equals(HashUtils.hashMD5(pwd)) == false) {
|
||||
// Bad Password, devolvemos null!
|
||||
usr = null;
|
||||
}
|
||||
}
|
||||
|
||||
return usr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javax.ejb.Remote;
|
||||
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import TO.LoggedUserTO;
|
||||
|
||||
/**
|
||||
* Interfaz remota del EJB Definimos los métodos que estarán disponibles para
|
||||
@@ -21,4 +22,5 @@ public interface SystemAdminFacadeRemote {
|
||||
*/
|
||||
public Collection<MedicalSpecialtyTO> listAllMedicalSpecialities();
|
||||
public Collection<PrimaryHealthCareCenterTO> listAllCAPs();
|
||||
public LoggedUserTO login(String id, String pwd);
|
||||
}
|
||||
Reference in New Issue
Block a user