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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user