From b3b8e3422c53ea662984962d12702f94abaef0e4 Mon Sep 17 00:00:00 2001 From: Falucho <german.faller@pcunix71.fing.edu.uy> Date: Mon, 24 Jun 2019 12:45:34 -0300 Subject: [PATCH] Se pone los Roles en el registro --- .../uy/edu/fing/tse/jsf/UserLoginBean.java | 23 ++++++++++++++++++- backoffice/src/main/webapp/jsf/register.xhtml | 23 +++++++++++++++---- .../main/java/uy/edu/fing/tse/dto/UserBO.java | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/backoffice/src/main/java/uy/edu/fing/tse/jsf/UserLoginBean.java b/backoffice/src/main/java/uy/edu/fing/tse/jsf/UserLoginBean.java index 8dad390..0e01fa1 100644 --- a/backoffice/src/main/java/uy/edu/fing/tse/jsf/UserLoginBean.java +++ b/backoffice/src/main/java/uy/edu/fing/tse/jsf/UserLoginBean.java @@ -2,15 +2,19 @@ package uy.edu.fing.tse.jsf; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import uy.edu.fing.tse.central.business.BusinessLocal; import uy.edu.fing.tse.central.business.security.SecurityLocal; +import uy.edu.fing.tse.dto.Role; import uy.edu.fing.tse.dto.UserBO; +import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.inject.Named; import java.io.Serializable; +import java.util.List; @RequestScoped @Named("userLoginView") @@ -21,10 +25,28 @@ public class UserLoginBean implements Serializable { private static final Logger LOG = LoggerFactory.getLogger(UserLoginBean.class); @EJB private SecurityLocal securityLocal; + @EJB + private BusinessLocal negocio; + + + private List<Role> roles; + + @PostConstruct + public void init() { + roles = negocio.listarRoles(); + } final UserBO user = new UserBO(); private String repassword; + public List<Role> getRoles() { + return roles; + } + + public void setRoles(List<Role> roles) { + this.roles = roles; + } + public UserBO getUser() { return user; } @@ -45,7 +67,6 @@ public class UserLoginBean implements Serializable { } - public String register() { final var s = securityLocal.register(user); boolean valid = false; // verificar que sean iguales la pasw, en caso contrario diff --git a/backoffice/src/main/webapp/jsf/register.xhtml b/backoffice/src/main/webapp/jsf/register.xhtml index 26d8cbe..0c84897 100644 --- a/backoffice/src/main/webapp/jsf/register.xhtml +++ b/backoffice/src/main/webapp/jsf/register.xhtml @@ -14,21 +14,34 @@ <h:panelGrid columns="2" cellpadding="5" id="form"> <h:outputLabel for="username" value="Username:"/> - <p:inputText id="username" value="#{userLoginView.user.mail}" required="true" requiredMessage="Ingrese su e-mail" label="username"/> + <p:inputText id="username" value="#{userLoginView.user.mail}" required="true" + requiredMessage="Ingrese su e-mail" label="username"/> <h:outputLabel for="password" value="Password:"/> - <p:password id="password" value="#{userLoginView.user.password}" required="true" requiredMessage="Ingrese su password" label="password"/> + <p:password id="password" value="#{userLoginView.user.password}" required="true" + requiredMessage="Ingrese su password" label="password"/> <h:outputLabel for="repassword" value="RePassword:"/> - <p:password id="repassword" value="#{userLoginView.repassword}" required="true" requiredMessage="Reingrese su password" label="repassword"/> + <p:password id="repassword" value="#{userLoginView.repassword}" required="true" + requiredMessage="Reingrese su password" label="repassword"/> + + + <p:outputLabel for="rol" value="Rol:"/> + <p:selectOneRadio id="rol" value="#{userLoginView.user.role}" unselectable="false"> + <f:selectItems value="#{userLoginView.roles}" var="r" itemLabel="#{r.name}" itemValue="#{r}"/> + </p:selectOneRadio> + <f:facet name="footer"> - <h:commandButton styleClass="btn btn-primary" vaction="#{userLoginView.regiszter}" value="Register" style="font-size:20px"/> + <h:commandButton styleClass="btn btn-primary" vaction="#{userLoginView.register}" value="Register" + style="font-size:20px"/> - <h:commandButton styleClass="btn btn-primary" value="Volver" action="login.xhmtl?faces-redirect=true" update="form" async="true" process="@this" style="font-size:20px"/> + <h:commandButton styleClass="btn btn-primary" value="Volver" + action="login.xhmtl?faces-redirect=true" update="form" async="true" process="@this" + style="font-size:20px"/> </f:facet> diff --git a/central-dto/src/main/java/uy/edu/fing/tse/dto/UserBO.java b/central-dto/src/main/java/uy/edu/fing/tse/dto/UserBO.java index 8058ca4..6946e0f 100644 --- a/central-dto/src/main/java/uy/edu/fing/tse/dto/UserBO.java +++ b/central-dto/src/main/java/uy/edu/fing/tse/dto/UserBO.java @@ -7,7 +7,7 @@ public final class UserBO extends User { private String salt; private String password; - private Role role; + private Role role = new Role(); public String getSalt() { return salt; -- GitLab