Añadir usuario admin
This commit is contained in:
@@ -109,6 +109,8 @@ public class AuthorizationFilter implements Filter {
|
||||
authorized = true;
|
||||
if (reqURI.indexOf("/systemAdmin/ListDoctorsByCenter") > 0)
|
||||
authorized = true;
|
||||
if (reqURI.indexOf("/systemAdmin/AddAdmin") > 0)
|
||||
authorized = true;
|
||||
if (reqURI.indexOf("/visit/PatientVisitList") > 0)
|
||||
authorized = true;
|
||||
if (reqURI.indexOf("/visit/UpdateVisit") > 0)
|
||||
|
||||
@@ -46,7 +46,7 @@ public class MenuMBean implements Serializable {
|
||||
subMenu.addElement(new DefaultSeparator());
|
||||
subMenu.addElement(createMenuItem("Ver médicos de un CAP", "fa fa-medkit", "/systemAdmin/ListDoctorsByCenter", null));
|
||||
subMenu.addElement(new DefaultSeparator());
|
||||
subMenu.addElement(createMenuItem("Añadir usuario Admin", "fa fa-user-secret", "/systemAdmin/ManageSpecialties", null));
|
||||
subMenu.addElement(createMenuItem("Añadir usuario Admin", "fa fa-user-secret", "/systemAdmin/AddAdmin", null));
|
||||
|
||||
model.addElement(subMenu);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package managedbean.systemAdmin;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.inject.Named;
|
||||
|
||||
import TO.LoggedUserTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import common.HashUtils;
|
||||
import managedbean.common.ManagedBeanBase;
|
||||
import managedbean.common.SessionUtils;
|
||||
|
||||
@Named("AddAdmin")
|
||||
@RequestScoped
|
||||
public class AddAdminMBean extends ManagedBeanBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
public AddAdminMBean() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// Recuperamos el usuario logeado actual
|
||||
LoggedUserTO usr = null;
|
||||
try {
|
||||
usr = SessionUtils.getloggedOnUser();
|
||||
|
||||
if (usr == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida",
|
||||
"Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void insertData() {
|
||||
int error = 0;
|
||||
|
||||
if (this.getRemoteManagerSystemAdmin().findAdminByEmail(email) != null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Administrador ya existente", "El administrador ya se encuentra dado de alta");
|
||||
error++;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
this.getRemoteManagerSystemAdmin().insertAdmin(email, HashUtils.hashMD5(password));
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "El administrador se ha dado de alta", "Los datos del administrador se han guardado correctamente.");
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user