Si se actualiza el nombre del perfil, se refresca la sesión y el menú
para reflejar los cambios.
This commit is contained in:
@@ -183,7 +183,7 @@
|
|||||||
<div class="ui-g-12 ui-g-nopad">
|
<div class="ui-g-12 ui-g-nopad">
|
||||||
<div class="ui-g-4 ui-md-4"></div>
|
<div class="ui-g-4 ui-md-4"></div>
|
||||||
<div class="ui-g-2 ui-md-2 ">
|
<div class="ui-g-2 ui-md-2 ">
|
||||||
<p:commandButton validateClient="true" value="Guardar" update="frmUpdateProfile" action="#{UpdateProfile.saveData}" icon="pi pi-check" />
|
<p:commandButton validateClient="true" value="Guardar" update="frmUpdateProfile,frmMenu" action="#{UpdateProfile.saveData}" icon="pi pi-check" />
|
||||||
</div>
|
</div>
|
||||||
<div class="ui-g-2 ui-md-2">
|
<div class="ui-g-2 ui-md-2">
|
||||||
<p:button value="Volver" outcome="/home" icon="pi pi-home" />
|
<p:button value="Volver" outcome="/home" icon="pi pi-home" />
|
||||||
|
|||||||
@@ -17,14 +17,18 @@ public class SessionUtils {
|
|||||||
public static final String SESSION_VAR_USER = "loggedOnUser";
|
public static final String SESSION_VAR_USER = "loggedOnUser";
|
||||||
public static final String SESSION_VAR_MESSAGE = "facesMessage";
|
public static final String SESSION_VAR_MESSAGE = "facesMessage";
|
||||||
|
|
||||||
public static HttpSession getSession() {
|
public static HttpSession getSession(boolean create) {
|
||||||
FacesContext ctx = FacesContext.getCurrentInstance();
|
FacesContext ctx = FacesContext.getCurrentInstance();
|
||||||
if (ctx != null)
|
if (ctx != null)
|
||||||
return (HttpSession) ctx.getExternalContext().getSession(false);
|
return (HttpSession) ctx.getExternalContext().getSession(create);
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HttpSession getSession() {
|
||||||
|
return getSession(false);
|
||||||
|
}
|
||||||
|
|
||||||
public static HttpServletRequest getRequest() {
|
public static HttpServletRequest getRequest() {
|
||||||
return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
|
return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
|
||||||
}
|
}
|
||||||
@@ -33,8 +37,8 @@ public class SessionUtils {
|
|||||||
return ((HttpServletRequest) request).getSession(false);
|
return ((HttpServletRequest) request).getSession(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateSession(LoggedUserTO usr) {
|
public static void createOrUpdateSession(LoggedUserTO usr) {
|
||||||
HttpSession ses = getSession();
|
HttpSession ses = getSession(true);
|
||||||
ses.setAttribute(SessionUtils.SESSION_VAR_USERNAME, usr.getName());
|
ses.setAttribute(SessionUtils.SESSION_VAR_USERNAME, usr.getName());
|
||||||
ses.setAttribute(SessionUtils.SESSION_VAR_USERID, usr.getId());
|
ses.setAttribute(SessionUtils.SESSION_VAR_USERID, usr.getId());
|
||||||
ses.setAttribute(SessionUtils.SESSION_VAR_USERTYPE, usr.getUserType());
|
ses.setAttribute(SessionUtils.SESSION_VAR_USERTYPE, usr.getUserType());
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ import managedbean.common.SessionUtils;
|
|||||||
import managedbean.common.ValidationUtils;
|
import managedbean.common.ValidationUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManagedBEan que gestiona el registro de usuarios: Usuarios de tipo "Paciente"
|
* ManagedBEan que gestiona el registro de usuarios: Usuarios de tipo "Paciente" Usuarios de tipo "Médico de Familia" usuarios de tipo "Médico especialista"
|
||||||
* Usuarios de tipo "Médico de Familia" usuarios de tipo "Médico especialista"
|
|
||||||
*
|
*
|
||||||
* @author Marcos García Núñez (mgarcianun@uoc.edu)
|
* @author Marcos García Núñez (mgarcianun@uoc.edu)
|
||||||
*
|
*
|
||||||
@@ -295,20 +294,25 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
|||||||
|
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
try {
|
try {
|
||||||
|
LoggedUserTO usr = null;
|
||||||
|
|
||||||
switch (this.userType) {
|
switch (this.userType) {
|
||||||
case PATIENT:
|
case PATIENT:
|
||||||
PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email);
|
PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email);
|
||||||
this.setPatientData(pat);
|
this.setPatientData(pat);
|
||||||
|
usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), this.userType);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case FAMILY_DOCTOR:
|
case FAMILY_DOCTOR:
|
||||||
FamilyDoctorTO fd = this.getRemoteManagerProfile().updateFamilyDoctorData(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
|
FamilyDoctorTO fd = this.getRemoteManagerProfile().updateFamilyDoctorData(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
|
||||||
this.setFamilyDoctorData(fd);
|
this.setFamilyDoctorData(fd);
|
||||||
|
usr = new LoggedUserTO(fd.getId().toString(), fd.getName(), fd.getPassword(), this.userType);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SPECIALIST_DOCTOR:
|
case SPECIALIST_DOCTOR:
|
||||||
SpecialistDoctorTO sd = this.getRemoteManagerProfile().updateSpecialistDoctorData(id, nif, name, surname, password, email, this.medicalSpecialty);
|
SpecialistDoctorTO sd = this.getRemoteManagerProfile().updateSpecialistDoctorData(id, nif, name, surname, password, email, this.medicalSpecialty);
|
||||||
this.setSpecialistDoctorData(sd);
|
this.setSpecialistDoctorData(sd);
|
||||||
|
usr = new LoggedUserTO(sd.getId().toString(), sd.getName(), sd.getPassword(), this.userType);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ADMINISTRATOR:
|
case ADMINISTRATOR:
|
||||||
@@ -321,6 +325,9 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
|||||||
this.oldPassword = "";
|
this.oldPassword = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualizamos la sessión del usuario actual por si ha cambiado el nombre de usuario.
|
||||||
|
SessionUtils.createOrUpdateSession(usr);
|
||||||
|
|
||||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de su perfil se han guardado correctamente.");
|
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de su perfil se han guardado correctamente.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.manageException(e);
|
this.manageException(e);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class LoginMBean extends ManagedBeanBase {
|
|||||||
|
|
||||||
if (usr != null) {
|
if (usr != null) {
|
||||||
loggedIn = true;
|
loggedIn = true;
|
||||||
SessionUtils.CreateSession(usr);
|
SessionUtils.createOrUpdateSession(usr);
|
||||||
|
|
||||||
this.addFacesMessageKeep(FacesMessage.SEVERITY_INFO, "Login correcto", "Bienvenido " + usr.getName());
|
this.addFacesMessageKeep(FacesMessage.SEVERITY_INFO, "Login correcto", "Bienvenido " + usr.getName());
|
||||||
viewRedirect = "/home?faces-redirect=true";
|
viewRedirect = "/home?faces-redirect=true";
|
||||||
|
|||||||
Reference in New Issue
Block a user