Si se actualiza el nombre del perfil, se refresca la sesión y el menú

para reflejar los cambios.
This commit is contained in:
Marcos Garcia Nuñez
2019-12-22 21:08:18 +01:00
parent ed1938f44a
commit 3555348f71
4 changed files with 26 additions and 15 deletions

View File

@@ -183,7 +183,7 @@
<div class="ui-g-12 ui-g-nopad">
<div class="ui-g-4 ui-md-4"></div>
<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 class="ui-g-2 ui-md-2">
<p:button value="Volver" outcome="/home" icon="pi pi-home" />

View File

@@ -17,14 +17,18 @@ public class SessionUtils {
public static final String SESSION_VAR_USER = "loggedOnUser";
public static final String SESSION_VAR_MESSAGE = "facesMessage";
public static HttpSession getSession() {
public static HttpSession getSession(boolean create) {
FacesContext ctx = FacesContext.getCurrentInstance();
if (ctx != null)
return (HttpSession) ctx.getExternalContext().getSession(false);
return (HttpSession) ctx.getExternalContext().getSession(create);
else
return null;
}
public static HttpSession getSession() {
return getSession(false);
}
public static HttpServletRequest getRequest() {
return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
}
@@ -33,8 +37,8 @@ public class SessionUtils {
return ((HttpServletRequest) request).getSession(false);
}
public static void CreateSession(LoggedUserTO usr) {
HttpSession ses = getSession();
public static void createOrUpdateSession(LoggedUserTO usr) {
HttpSession ses = getSession(true);
ses.setAttribute(SessionUtils.SESSION_VAR_USERNAME, usr.getName());
ses.setAttribute(SessionUtils.SESSION_VAR_USERID, usr.getId());
ses.setAttribute(SessionUtils.SESSION_VAR_USERTYPE, usr.getUserType());

View File

@@ -26,8 +26,7 @@ import managedbean.common.SessionUtils;
import managedbean.common.ValidationUtils;
/**
* ManagedBEan que gestiona el registro de usuarios: Usuarios de tipo "Paciente"
* Usuarios de tipo "Médico de Familia" usuarios de tipo "Médico especialista"
* ManagedBEan que gestiona el registro de usuarios: Usuarios de tipo "Paciente" Usuarios de tipo "Médico de Familia" usuarios de tipo "Médico especialista"
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
@@ -295,20 +294,25 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
if (error == 0) {
try {
LoggedUserTO usr = null;
switch (this.userType) {
case PATIENT:
PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email);
this.setPatientData(pat);
usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), this.userType);
break;
case FAMILY_DOCTOR:
FamilyDoctorTO fd = this.getRemoteManagerProfile().updateFamilyDoctorData(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
this.setFamilyDoctorData(fd);
usr = new LoggedUserTO(fd.getId().toString(), fd.getName(), fd.getPassword(), this.userType);
break;
case SPECIALIST_DOCTOR:
SpecialistDoctorTO sd = this.getRemoteManagerProfile().updateSpecialistDoctorData(id, nif, name, surname, password, email, this.medicalSpecialty);
this.setSpecialistDoctorData(sd);
usr = new LoggedUserTO(sd.getId().toString(), sd.getName(), sd.getPassword(), this.userType);
break;
case ADMINISTRATOR:
@@ -321,6 +325,9 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
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.");
} catch (Exception e) {
this.manageException(e);

View File

@@ -45,7 +45,7 @@ public class LoginMBean extends ManagedBeanBase {
if (usr != null) {
loggedIn = true;
SessionUtils.CreateSession(usr);
SessionUtils.createOrUpdateSession(usr);
this.addFacesMessageKeep(FacesMessage.SEVERITY_INFO, "Login correcto", "Bienvenido " + usr.getName());
viewRedirect = "/home?faces-redirect=true";