mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Añadido funcionalidad de admin activa cliente
This commit is contained in:
parent
4597e3ae85
commit
82ab379934
3 changed files with 53 additions and 2 deletions
|
@ -89,4 +89,20 @@ public class AdministratorController {
|
|||
this.clientService.saveClient(client);
|
||||
return "redirect:/administrators/clients";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/administrators/clients/{username}/activate")
|
||||
public String activateClient(@PathVariable("username") final String username, final ModelMap model) {
|
||||
|
||||
Client client = this.clientService.findByUsername(username);
|
||||
model.put("client", client);
|
||||
return "clients/clientActivate";
|
||||
}
|
||||
@PostMapping(value = "/administrators/clients/{username}/activate")
|
||||
public String activateClientForm(@PathVariable("username") final String username, final ModelMap model, final HttpServletRequest request) {
|
||||
|
||||
Client client = this.clientService.findByUsername(username);
|
||||
client.getUsuar().setEnabled(true);
|
||||
this.clientService.saveClient(client);
|
||||
return "redirect:/administrators/clients";
|
||||
}
|
||||
}
|
||||
|
|
25
src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp
Normal file
25
src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp
Normal file
|
@ -0,0 +1,25 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true"%>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
|
||||
<cheapy:layout pageName="client">
|
||||
|
||||
<jsp:body>
|
||||
<h2 class="text-center" style="font-family: 'Lobster'; font-size: 30px; color: rgb(0, 64, 128); padding:30px"><em>¿Está seguro de que quiere activar esta cuenta?</em></h2>
|
||||
|
||||
<form:form modelAttribute="client" class="form-horizontal">
|
||||
|
||||
<div class="btns-edit2">
|
||||
<button type="submit" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon glyphicon-trash" aria-hidden="true" style="padding: 5px"> </span>
|
||||
Activar</button>
|
||||
</div>
|
||||
</form:form>
|
||||
|
||||
</jsp:body>
|
||||
|
||||
</cheapy:layout>
|
|
@ -69,16 +69,26 @@
|
|||
Borrar cliente</button>
|
||||
</div>
|
||||
</sec:authorize>
|
||||
<sec:authorize access="hasAnyAuthority('admin')">
|
||||
<sec:authorize access="hasAnyAuthority('admin')">
|
||||
<sec:authentication var="principal" property="principal" />
|
||||
<div class="btns-edit">
|
||||
|
||||
<c:if test="${ client.usuar.enabled eq true}">
|
||||
<spring:url value="/administrators/clients/{username}/disable" var="deactivateUrl">
|
||||
<spring:param name="username" value="${client.usuar.username}"/>
|
||||
</spring:url>
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(deactivateUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon glyphicon-trash" aria-hidden="true" style="padding: 5px"> </span>
|
||||
Desactivar cliente</button>
|
||||
</c:if>
|
||||
|
||||
<c:if test="${ client.usuar.enabled eq false}">
|
||||
<spring:url value="/administrators/clients/{username}/activate" var="activateUrl">
|
||||
<spring:param name="username" value="${client.usuar.username}"/>
|
||||
</spring:url>
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(activateUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon glyphicon-trash" aria-hidden="true" style="padding: 5px"> </span>
|
||||
Activar cliente</button>
|
||||
</c:if>
|
||||
</div>
|
||||
</sec:authorize>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue