mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Vista de login
This commit is contained in:
parent
bb86bbc6ba
commit
fbd5813f86
11 changed files with 32 additions and 26 deletions
3
pom.xml
3
pom.xml
|
@ -135,7 +135,10 @@
|
|||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -36,15 +36,15 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||
.antMatchers(HttpMethod.GET, "/", "/oups").permitAll()
|
||||
.antMatchers("/users/new").permitAll()
|
||||
.antMatchers("/login/**").anonymous()
|
||||
.antMatchers("/logout").permitAll()
|
||||
.antMatchers("/usuarios/new").permitAll()
|
||||
.antMatchers("/admin/**").hasAnyAuthority("admin")
|
||||
.antMatchers("/owners/**").hasAnyAuthority("owner", "admin")
|
||||
.antMatchers("/vets/**").authenticated().anyRequest().anonymous()
|
||||
.and().formLogin()
|
||||
.loginPage("/login")
|
||||
.successForwardUrl("/")
|
||||
.failureUrl("/login?error")
|
||||
.and().logout().logoutUrl("/login?logout");
|
||||
.loginPage("/login").permitAll()
|
||||
.failureUrl("/login?error")
|
||||
.and().logout().logoutSuccessUrl("/login");
|
||||
|
||||
// Configuración para que funcione la consola de administración
|
||||
// de la BD H2 (deshabilitar las cabeceras de protección contra
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.springframework.cheapy.system;
|
||||
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
@ -24,7 +27,11 @@ class LoginController {
|
|||
|
||||
@GetMapping("/login")
|
||||
public String login() {
|
||||
return "login";
|
||||
Authentication authentication= SecurityContextHolder.getContext().getAuthentication();
|
||||
if(authentication==null || authentication instanceof AnonymousAuthenticationToken) {
|
||||
return "login";
|
||||
}
|
||||
return "redirect:/";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
|
||||
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||
|
||||
<!-- %@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %-->
|
||||
|
||||
<style>
|
||||
|
@ -280,13 +280,15 @@
|
|||
<div class="fadeIn first">
|
||||
<img src="/resources/images/Logo Cheapy.png" id="icon" />
|
||||
</div>
|
||||
|
||||
<div th:if="${param.error}">
|
||||
<p class="text-danger"> Invalid username or password</p>
|
||||
</div>
|
||||
<!-- Login Form -->
|
||||
<form class='form-signin' action="/login" method='POST'>
|
||||
<input type="text" id="login" class="fadeIn second" name="login" placeholder="login">
|
||||
<input type="password" id="password" class="fadeIn third" name="login" placeholder="password">
|
||||
<input type="text" id="username" class="fadeIn second" name="username" placeholder="username" required autofocus>
|
||||
<input type="password" id="password" class="fadeIn third" name="password" placeholder="password" required>
|
||||
<sec:csrfInput />
|
||||
<input type="submit" class="fadeIn fourth" value="Log In">
|
||||
<input type="submit" class="fadeIn fourth" value="Login">
|
||||
</form>
|
||||
|
||||
<!-- Remind Passowrd -->
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ 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" %>
|
||||
<cheapy:layout pageName="owners">
|
||||
<h2>
|
||||
<c:if test="${owner['new']}">New </c:if> Owner
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
<%@ taglib prefix="sec"
|
||||
uri="http://www.springframework.org/security/tags"%>
|
||||
<!-- >%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%-->
|
||||
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<cheapy:layout pageName="owners">
|
||||
|
||||
<h2>Find Owners</h2>
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<cheapy:layout pageName="owners">
|
||||
|
||||
<h2>Owner Information</h2>
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<cheapy:layout pageName="owners">
|
||||
<h2>Owners</h2>
|
||||
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ 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" %>
|
||||
<cheapy:layout pageName="owners">
|
||||
<h2>
|
||||
<c:if test="${owner['new']}">New </c:if> Owner
|
||||
|
|
|
@ -69,10 +69,10 @@
|
|||
<p class="text-left">
|
||||
<strong><sec:authentication property="name" /></strong>
|
||||
</p>
|
||||
<p class="text-left">
|
||||
<a href="<c:url value="/logout" />"
|
||||
class="btn btn-primary btn-block btn-sm">Logout</a>
|
||||
</p>
|
||||
<form action="/logout" method=post>
|
||||
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
|
||||
<input type="submit" value="logout">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
|
||||
<%@ attribute name="active" required="true" rtexprvalue="true" %>
|
||||
<%@ attribute name="url" required="true" rtexprvalue="true" %>
|
||||
<%@ attribute name="title" required="false" rtexprvalue="true" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
|
||||
<li class="${active ? 'active' : ''}">
|
||||
<a href="<spring:url value="${url}" htmlEscape="true" />"
|
||||
|
|
Loading…
Reference in a new issue