Cambios varios para login de usuario

* Login de diferentes usuarios completado.
* Cambiado esquema de BBDD, campos texto a character varying.
* Cambiada relación entre paciente y medico de cabecera.
* Movida clase UserType a paquete common ya que se utiliza en el EJB.
* Datos de prueba para realizar logins, el password es admin para todos
(hashMD5).
This commit is contained in:
Marcos Garcia Nuñez
2019-12-06 02:17:07 +01:00
parent 32ce0a7eb6
commit 547af98a78
12 changed files with 192 additions and 159 deletions

View File

@@ -33,7 +33,7 @@
</div>
<hr />
<div id="menuDiv">
<p:growl id="messages" sticky="false" showDetail="true" life="3000" />
<p:growl id="messages" sticky="false" showDetail="true" life="15000" />
<p:ajaxStatus style="width:32px; height:32px; position:fixed; right:32px; bottom:32px">
<f:facet name="start">
<i id="loginSpin" class="pi pi-spin pi-spinner" style="font-size: 3em"></i>

View File

@@ -1,13 +1,18 @@
package TO;
import managedbean.common.UserType;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;
import common.UserType;
/**
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
public class LoggedUserTO {
@XmlRootElement(name = "LoggedUser")
public class LoggedUserTO implements Serializable {
private static final long serialVersionUID = 1L;
private String id;

View File

@@ -1,4 +1,4 @@
package managedbean.common;
package common;
public enum UserType {
PATIENT("Paciente"),

View File

@@ -12,20 +12,17 @@ import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import TO.PrimaryHealthCareCenterTO;
import common.HashUtils;
import common.UserType;
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
* métodos de la capa de negocio que implementan la logica de negocio y la
* interacción con la capa de persistencia.
*
* @author mark
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
@Stateless
@@ -97,27 +94,37 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
// 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);
usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRADOR);
} else {
Integer iId = Integer.valueOf(id);
// Try to login Patient
try {
int iId = Integer.parseInt(id);
// Try to login Patient, FamilyDoctor or SpecialistDoctor
// TODO: Si Patient, FamilyDoctor o Specialist Doctor tienen el mismo id, solo
// el paciente se puede logear. ¿Deberíamos cambiar esto permitiendo seleccionar
// el perfil a logearse?
PatientJPA pat = entman.find(PatientJPA.class, iId);
if (pat != null) {
usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), UserType.PATIENT);
usr = new LoggedUserTO(String.valueOf(pat.getId()), 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);
usr = new LoggedUserTO(String.valueOf(fdoc.getId()), 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);
usr = new LoggedUserTO(String.valueOf(sdoc.getId()), sdoc.getName(), sdoc.getPassword(), UserType.SPECIALIST_DOCTOR);
}
}
}
} catch (NumberFormatException nf) {
// id is not an intenger, so, login fails
usr = null;
}
}
if (usr != null) {

View File

@@ -9,10 +9,8 @@ import TO.PrimaryHealthCareCenterTO;
import TO.LoggedUserTO;
/**
* Interfaz remota del EJB Definimos los métodos que estarán disponibles para
* los clientes del EJB
*
* @author mark
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
@Remote
@@ -21,6 +19,8 @@ public interface SystemAdminFacadeRemote {
* Definimos la interfaz remota
*/
public Collection<MedicalSpecialtyTO> listAllMedicalSpecialities();
public Collection<PrimaryHealthCareCenterTO> listAllCAPs();
public LoggedUserTO login(String id, String pwd);
}

View File

@@ -26,7 +26,7 @@ public class FamilyDoctorJPA implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Integer id;
private int id;
private String nif;
private String name;
private String surname;
@@ -42,7 +42,7 @@ public class FamilyDoctorJPA implements Serializable {
super();
}
public FamilyDoctorJPA(Integer id, String nif, String name, String surname, String password, String email) {
public FamilyDoctorJPA(int id, String nif, String name, String surname, String password, String email) {
this.id = id;
this.nif = nif;
this.name = name;
@@ -53,11 +53,11 @@ public class FamilyDoctorJPA implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer getId() {
public int getId() {
return id;
}
public void setId(Integer value) {
public void setId(int value) {
this.id = value;
}

View File

@@ -23,7 +23,7 @@ public class PatientJPA implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private int id;
private String nif;
private String name;
private String surname;
@@ -40,7 +40,7 @@ public class PatientJPA implements Serializable {
super();
}
public PatientJPA(Integer id, String nif, String name, String surname, String password, String email) {
public PatientJPA(int id, String nif, String name, String surname, String password, String email) {
this.id = id;
this.nif = nif;
this.name = name;
@@ -49,11 +49,11 @@ public class PatientJPA implements Serializable {
this.email = email;
}
public Integer getId() {
public int getId() {
return id;
}
public void setId(Integer value) {
public void setId(int value) {
this.id = value;
}

View File

@@ -22,7 +22,7 @@ public class SpecialistDoctorJPA implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Integer id;
private int id;
private String nif;
private String name;
private String surname;
@@ -48,11 +48,11 @@ public class SpecialistDoctorJPA implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer getId() {
public int getId() {
return id;
}
public void setId(Integer value) {
public void setId(int value) {
this.id = value;
}

View File

@@ -22,8 +22,8 @@ import TO.MedicalSpecialtyTO;
import TO.PatientTO;
import TO.PrimaryHealthCareCenterTO;
import TO.SpecialistDoctorTO;
import common.UserType;
import ejb.systemAdmin.SystemAdminFacadeRemote;
import managedbean.common.UserType;
import managedbean.common.ValidationUtils;
/**

View File

@@ -1,19 +1,24 @@
package managedbean.systemAdmin;
import java.util.Properties;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.http.HttpSession;
import org.primefaces.PrimeFaces;
import TO.LoggedUserTO;
import ejb.systemAdmin.SystemAdminFacadeRemote;
import managedbean.common.SessionUtils;
@Named("loginView")
@RequestScoped
public class LoginMBean {
private String username;
private String password;
@@ -38,26 +43,36 @@ public class LoginMBean {
FacesMessage message = null;
boolean loggedIn = false;
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LoggedUserTO usr = null;
if (username != null && username.equals("admin") && password != null && password.equals("admin")) {
if (username != null && password != null) {
try {
Properties props = System.getProperties();
Context ctx = new InitialContext(props);
SystemAdminFacadeRemote remoteManager = (SystemAdminFacadeRemote) ctx.lookup("java:app/MyHealth.jar/SystemAdminFacadeBean!ejb.systemAdmin.SystemAdminFacadeRemote");
usr = remoteManager.login(username, password);
if (usr != null) {
loggedIn = true;
HttpSession session = SessionUtils.getSession();
session.setAttribute("username", username);
session.setAttribute("username", usr.getName());
session.setAttribute("userid", "1");
message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Bienvenido", username);
session.setAttribute("userid", usr.getUserType());
session.setAttribute("loggedInUser", usr);
message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Bienvenido", usr.getName());
return ("home?faces-redirect=true");
} else {
loggedIn = false;
} else
message = new FacesMessage(FacesMessage.SEVERITY_WARN, "Loggin Error", "El usuario o la contraseña son incorrectos");
} catch (Exception ex) {
message = new FacesMessage(FacesMessage.SEVERITY_FATAL, "Error fatal", ex.getMessage());
}
} else
message = new FacesMessage(FacesMessage.SEVERITY_WARN, "Loggin Error", "El usuario o la contraseña son incorrectos");
FacesContext.getCurrentInstance().addMessage(null, message);
PrimeFaces.current().ajax().addCallbackParam("loggedIn", loggedIn);
@@ -71,6 +86,7 @@ public class LoginMBean {
HttpSession session = SessionUtils.getSession();
session.invalidate();
return "home?faces-redirect=true";
}
}

View File

@@ -11,213 +11,213 @@ DROP TABLE myhealth.SpecialistDoctor;
DROP TABLE myhealth.Visit;
*/
-- Table: MyHealth.Administrator
-- Table: myhealth.administrator
-- DROP TABLE MyHealth.Administrator;
-- DROP TABLE myhealth.administrator;
CREATE TABLE MyHealth.Administrator
CREATE TABLE myhealth.administrator
(
email character varying(50) COLLATE pg_catalog.default NOT NULL,
password character varying(100) COLLATE pg_catalog.default,
CONSTRAINT Administrator_pkey PRIMARY KEY (email)
email character varying(50) COLLATE pg_catalog."default" NOT NULL,
password character varying(100) COLLATE pg_catalog."default",
CONSTRAINT administrator_pkey PRIMARY KEY (email)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.Administrator
ALTER TABLE myhealth.administrator
OWNER to "USER";
-- Table: MyHealth.FamilyDoctor
-- Table: myhealth.familydoctor
-- DROP TABLE MyHealth.FamilyDoctor;
-- DROP TABLE myhealth.familydoctor;
CREATE TABLE MyHealth.FamilyDoctor
CREATE TABLE myhealth.familydoctor
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
password character(50) COLLATE pg_catalog.default,
nif character(50) COLLATE pg_catalog.default,
surname character varying(100) COLLATE pg_catalog.default,
email character varying(120) COLLATE pg_catalog.default,
name character varying(100) COLLATE pg_catalog.default,
PrimaryHealthCareCenterId character varying(50) COLLATE pg_catalog.default,
CONSTRAINT FamilyDoctor_pkey PRIMARY KEY (id)
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
password character(50) COLLATE pg_catalog."default",
nif character(50) COLLATE pg_catalog."default",
surname character varying(100) COLLATE pg_catalog."default",
email character varying(120) COLLATE pg_catalog."default",
name character varying(100) COLLATE pg_catalog."default",
primaryhealthcarecenterid character varying(50) COLLATE pg_catalog."default",
CONSTRAINT familydoctor_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.FamilyDoctor
ALTER TABLE myhealth.familydoctor
OWNER to "USER";
-- Table: MyHealth.MedicalSpecialty
-- Table: myhealth.medicalspecialty
-- DROP TABLE MyHealth.MedicalSpecialty;
-- DROP TABLE myhealth.medicalspecialty;
CREATE TABLE MyHealth.MedicalSpecialty
CREATE TABLE myhealth.medicalspecialty
(
name text COLLATE pg_catalog.default NOT NULL,
description text COLLATE pg_catalog.default,
CONSTRAINT MedicalSpecialty_pkey PRIMARY KEY (name)
name character varying(50) COLLATE pg_catalog."default" NOT NULL,
description character varying(1000) COLLATE pg_catalog."default",
CONSTRAINT medicalspecialty_pkey PRIMARY KEY (name)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.MedicalSpecialty
OWNER to "USER";
ALTER TABLE myhealth.medicalspecialty
OWNER to postgres;
-- Table: MyHealth.MedicalTest
-- Table: myhealth.medicaltest
-- DROP TABLE MyHealth.MedicalTest;
-- DROP TABLE myhealth.medicaltest;
CREATE TABLE MyHealth.MedicalTest
CREATE TABLE myhealth.medicaltest
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
date date,
time abstime,
result text COLLATE pg_catalog.default,
highResImage bytea,
"time" abstime,
result text COLLATE pg_catalog."default",
highresimage bytea,
type integer,
PatientId character varying(50) COLLATE pg_catalog.default NOT NULL,
SpecialistDoctorId character varying(50) COLLATE pg_catalog.default NOT NULL,
CONSTRAINT MedicalTest_pkey PRIMARY KEY (id)
patientid character varying(50) COLLATE pg_catalog."default" NOT NULL,
specialistdoctorid character varying(50) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT medicaltest_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.MedicalTest
ALTER TABLE myhealth.medicaltest
OWNER to "USER";
-- Table: MyHealth.Patient
-- Table: myhealth.patient
-- DROP TABLE MyHealth.Patient;
-- DROP TABLE myhealth.patient;
CREATE TABLE MyHealth.Patient
CREATE TABLE myhealth.patient
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
password character(50) COLLATE pg_catalog.default,
nif character(50) COLLATE pg_catalog.default,
surname character varying(100) COLLATE pg_catalog.default,
email character varying(120) COLLATE pg_catalog.default,
name character varying(100) COLLATE pg_catalog.default,
FamilyDoctorId character varying(50) COLLATE pg_catalog.default,
CONSTRAINT Patient_pkey PRIMARY KEY (id)
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
password character varying COLLATE pg_catalog."default",
nif character varying COLLATE pg_catalog."default",
surname character varying(100) COLLATE pg_catalog."default",
email character varying(120) COLLATE pg_catalog."default",
name character varying(100) COLLATE pg_catalog."default",
familydoctorid integer,
CONSTRAINT patient_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.Patient
ALTER TABLE myhealth.patient
OWNER to "USER";
-- Table: MyHealth.PrimaryHealthCareCenter
-- Table: myhealth.primaryhealthcarecenter
-- DROP TABLE MyHealth.PrimaryHealthCareCenter;
-- DROP TABLE myhealth.primaryhealthcarecenter;
CREATE TABLE MyHealth.PrimaryHealthCareCenter
CREATE TABLE myhealth.primaryhealthcarecenter
(
name character varying(50) COLLATE pg_catalog.default NOT NULL,
location character varying(256) COLLATE pg_catalog.default,
CONSTRAINT PrimaryHealthCareCenter_pkey PRIMARY KEY (name)
name character varying(50) COLLATE pg_catalog."default" NOT NULL,
location character varying(256) COLLATE pg_catalog."default",
CONSTRAINT primaryhealthcarecenter_pkey PRIMARY KEY (name)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.PrimaryHealthCareCenter
ALTER TABLE myhealth.primaryhealthcarecenter
OWNER to "USER";
-- Table: MyHealth.Question
-- Table: myhealth.question
-- DROP TABLE MyHealth.Question;
-- DROP TABLE myhealth.question;
CREATE TABLE MyHealth.Question
CREATE TABLE myhealth.question
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
title character varying(512) COLLATE pg_catalog.default NOT NULL,
message character varying(8000) COLLATE pg_catalog.default NOT NULL,
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
title character varying(512) COLLATE pg_catalog."default" NOT NULL,
message character varying(8000) COLLATE pg_catalog."default" NOT NULL,
status integer,
PatientId character varying(50) COLLATE pg_catalog.default NOT NULL,
CONSTRAINT Question_pkey PRIMARY KEY (id)
patientid character varying(50) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT question_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.Question
ALTER TABLE myhealth.question
OWNER to "USER";
-- Table: MyHealth.Response
-- Table: myhealth.response
-- DROP TABLE MyHealth.Response;
-- DROP TABLE myhealth.response;
CREATE TABLE MyHealth.Response
CREATE TABLE myhealth.response
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
response character varying(8000) COLLATE pg_catalog.default,
QuestionId integer NOT NULL,
CONSTRAINT Response_pkey PRIMARY KEY (id)
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
response character varying(8000) COLLATE pg_catalog."default",
questionid integer NOT NULL,
CONSTRAINT response_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.Response
ALTER TABLE myhealth.response
OWNER to "USER";
-- Table: MyHealth.SpecialistDoctor
-- Table: myhealth.specialistdoctor
-- DROP TABLE MyHealth.SpecialistDoctor;
-- DROP TABLE myhealth.specialistdoctor;
CREATE TABLE MyHealth.SpecialistDoctor
CREATE TABLE myhealth.specialistdoctor
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
password character(50) COLLATE pg_catalog.default,
nif character(50) COLLATE pg_catalog.default,
surname character varying(100) COLLATE pg_catalog.default,
email character varying(120) COLLATE pg_catalog.default,
name character varying(100) COLLATE pg_catalog.default,
MedicalSpecialtyId character varying(50) COLLATE pg_catalog.default,
CONSTRAINT SpecialistDoctor_pkey PRIMARY KEY (id)
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
password character varying COLLATE pg_catalog."default",
nif character varying COLLATE pg_catalog."default",
surname character varying(100) COLLATE pg_catalog."default",
email character varying(120) COLLATE pg_catalog."default",
name character varying(100) COLLATE pg_catalog."default",
medicalspecialtyid character varying(50) COLLATE pg_catalog."default",
CONSTRAINT specialistdoctor_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.SpecialistDoctor
ALTER TABLE myhealth.specialistdoctor
OWNER to "USER";
-- Table: MyHealth.Visit
-- Table: myhealth.visit
-- DROP TABLE MyHealth.Visit;
-- DROP TABLE myhealth.visit;
CREATE TABLE MyHealth.Visit
CREATE TABLE myhealth.visit
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
date date NOT NULL,
time abstime NOT NULL,
observations character varying(4000) COLLATE pg_catalog.default,
result text COLLATE pg_catalog.default,
PatientId character varying(50) COLLATE pg_catalog.default NOT NULL,
FamilyDoctorId character varying(50) COLLATE pg_catalog.default NOT NULL,
CONSTRAINT Visit_pkey PRIMARY KEY (id)
"time" abstime NOT NULL,
observations character varying(4000) COLLATE pg_catalog."default",
result text COLLATE pg_catalog."default",
patientid character varying(50) COLLATE pg_catalog."default" NOT NULL,
familydoctorid character varying(50) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT visit_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE MyHealth.Visit
ALTER TABLE myhealth.visit
OWNER to "USER";

View File

@@ -1,3 +1,7 @@
--Inserta usuarios administradores (contraseña Hash MD5 'admin' para todos)
insert into myhealth.administrator (email, password) values ('admin@example.com', '21232F297A57A5A743894A0E4A801FC3')
insert into myhealth.administrator (email, password) values ('marcos@example.com', '21232F297A57A5A743894A0E4A801FC3')
-- Inserta Especialidades médicas
insert into MyHealth.MedicalSpecialty(name, description)
@@ -30,3 +34,4 @@ insert into MyHealth.MedicalSpecialty(name, description)
values ('Oncología','Especialidad médica de Oncología');
insert into MyHealth.MedicalSpecialty(name, description)
values ('Pediatría','Especialidad médica de Pediatría');