Lab 6 Vue

This commit is contained in:
shadowik 2023-06-18 20:22:55 +04:00
parent 37b1196914
commit 54ec769a9e
14 changed files with 71 additions and 34 deletions

View File

@ -17,6 +17,7 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@EnableMethodSecurity( @EnableMethodSecurity(
@ -48,6 +49,7 @@ public class SecurityConfiguration {
.authorizeHttpRequests() .authorizeHttpRequests()
.requestMatchers(MasterSignupMvcController.SIGNUP_URL).permitAll() .requestMatchers(MasterSignupMvcController.SIGNUP_URL).permitAll()
.requestMatchers(HttpMethod.GET, LOGIN_URL).permitAll() .requestMatchers(HttpMethod.GET, LOGIN_URL).permitAll()
.requestMatchers("/product").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.formLogin() .formLogin()
@ -68,9 +70,20 @@ public class SecurityConfiguration {
@Bean @Bean
public WebSecurityCustomizer webSecurityCustomizer() { public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring() return (web) -> web.ignoring()
.requestMatchers("/css/**") .requestMatchers(HttpMethod.OPTIONS, "/**")
.requestMatchers("/js/**") .requestMatchers("/*.js")
.requestMatchers("/templates/**") .requestMatchers("/*.html")
.requestMatchers("/webjars/**"); .requestMatchers("/*.css")
.requestMatchers("/assets/**")
.requestMatchers("/favicon.ico")
.requestMatchers("/.js", "/.css")
.requestMatchers("/swagger-ui/index.html")
.requestMatchers("/webjars/**")
.requestMatchers("/swagger-resources/**")
.requestMatchers("/v3/api-docs/**")
.requestMatchers("/h2-console");
} }
} }

View File

@ -1,7 +1,8 @@
package com.example.demo.util.error; package com.example.demo.util.error;
import com.example.demo.master.Master;
import com.example.demo.master.MasterNotFoundException; import com.example.demo.master.MasterNotFoundException;
import com.example.demo.order.Order;
import com.example.demo.order.OrderNotFoundException; import com.example.demo.order.OrderNotFoundException;
import com.example.demo.product.ProductNotFoundException; import com.example.demo.product.ProductNotFoundException;
import com.example.demo.util.validation.ValidationException; import com.example.demo.util.validation.ValidationException;
@ -11,17 +12,15 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ControllerAdvice
public class AdviceController { public class AdviceController {
@ExceptionHandler({ @ExceptionHandler({
MasterNotFoundException.class, MasterNotFoundException.class,
ProductNotFoundException.class,
OrderNotFoundException.class, OrderNotFoundException.class,
ValidationException.class, ProductNotFoundException.class,
ValidationException.class
}) })
public ResponseEntity<Object> handleException(Throwable e) { public ResponseEntity<Object> handleException(Throwable e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);

View File

@ -6,4 +6,8 @@ public class ValidationException extends RuntimeException {
public ValidationException(Set<String> errors) { public ValidationException(Set<String> errors) {
super(String.join("\n", errors)); super(String.join("\n", errors));
} }
public <T> ValidationException(String error) {
super(error);
}
} }

View File

@ -21,5 +21,6 @@ form {
} }
.product-div { .product-div {
background: #e874ac; background: #e874ac !important;
} }

View File

@ -22,7 +22,7 @@
<div class="container"> <div class="container">
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<form th:action="@{/order/masters_order}" method="get"> <form th:action="@{/order/masters_order}" method="get">
<select th:name="master_id" class="form-select" aria-label="Default select example"> <select th:name="master_id" class="form-select login-form" aria-label="Default select example">
<option th:each="master : ${masters}" th:id="master_id" th:value="${master.id}" > <option th:each="master : ${masters}" th:id="master_id" th:value="${master.id}" >
<span th:text="${master.firstName + ' ' + master.lastName }"></span> <span th:text="${master.firstName + ' ' + master.lastName }"></span>
</option> </option>

View File

@ -24,10 +24,10 @@
<div th:each="product : ${order.products}" class="row product-div p-2 m-2"> <div th:each="product : ${order.products}" class="row product-div p-2 m-2">
<input type="hidden" name="id_item" th:name="id" th:value="${product.id}"> <input type="hidden" name="id_item" th:name="id" th:value="${product.id}">
<div class="col"> <div class="col">
<h2 th:text="${product.name}"></h2> <h2 th:text="${product.name}" style="color: white !important;"></h2>
</div> </div>
<div class="col"> <div class="col">
<h3 th:text="${product.cost} + '$'"></h3> <h3 th:text="${product.cost} + '$'" style="color: white !important;"></h3>
</div> </div>
<div class="col"> <div class="col">
<button name="action" value="delete" class="btn btn-primary w-100 h-100 text-lg-center">Delete</button> <button name="action" value="delete" class="btn btn-primary w-100 h-100 text-lg-center">Delete</button>
@ -35,7 +35,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h2 th:text="${fullCost} + '$'"></h2> <h2 th:text="${fullCost} + '$'" style="color: white !important;"></h2>
</div> </div>
<div class="col"> <div class="col">
<h3><button name="action" value="buy" class="btn btn-primary w-100">Buy</button> <h3><button name="action" value="buy" class="btn btn-primary w-100">Buy</button>

View File

@ -19,8 +19,8 @@
<div layout:fragment="content"> <div layout:fragment="content">
<div> <div>
<form method="post" th:object="${product}"> <form method="post" th:object="${product}">
<input type="text" th:field="*{name}" th:value="${product.getName()}" name="name" class="form-control" id="name"> <input type="text" th:field="*{name}" th:value="${product.getName()}" name="name" class="form-control login-form" id="name">
<input type="number" th:field="*{cost}" th:value="${product.getCost()}" name="cost" class="form-control" id="cost"> <input type="number" th:field="*{cost}" th:value="${product.getCost()}" name="cost" class="form-control login-form" id="cost">
<button type="submit" class="btn btn-primary" th:text="${buttonText}">Add</button> <button type="submit" class="btn btn-primary" th:text="${buttonText}">Add</button>
</form> </form>
</div> </div>

View File

@ -22,10 +22,10 @@
<form method="post" th:object="${item}" > <form method="post" th:object="${item}" >
<input type="hidden" th:name="id" th:value="${item.getId()}"> <input type="hidden" th:name="id" th:value="${item.getId()}">
<div class="col"> <div class="col">
<h2 th:text="${item.getName()}" th:name="*{name}"></h2> <h2 th:text="${item.getName()}" style="color: white !important;" th:name="*{name}"></h2>
</div> </div>
<div class="col"> <div class="col">
<h3 th:text="${item.getCost()} + '$'" th:name="*{cost}"></h3> <h3 th:text="${item.getCost()} + '$'" style="color: white !important;" th:name="*{cost}"></h3>
</div> </div>
<div class="col"> <div class="col">
<button type="submit" class="btn btn-primary w-100">Buy</button> <button type="submit" class="btn btn-primary w-100">Buy</button>

View File

@ -19,19 +19,19 @@
<form method="post" th:object="${user}"> <form method="post" th:object="${user}">
<div class="container"> <div class="container">
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<input type="text" name="name" class="form-control" <input type="text" name="name" class="form-control login-form"
id="name" placeholder="Name" th:value="${user.firstName}" th:field="*{firstName}"> id="name" placeholder="Name" th:value="${user.firstName}" th:field="*{firstName}">
</div> </div>
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<input type="text" name="surname" class="form-control" <input type="text" name="surname" class="form-control login-form"
id="surname" placeholder="Surname" th:value="${user.lastName}" th:field="*{lastName}"> id="surname" placeholder="Surname" th:value="${user.lastName}" th:field="*{lastName}">
</div> </div>
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<input type="email" name="email" class="form-control" <input type="email" name="email" class="form-control login-form"
id="email" placeholder="Email" th:value="${user.email}" th:field="*{email}"> id="email" placeholder="Email" th:value="${user.email}" th:field="*{email}">
</div> </div>
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<input type="password" name="password" class="form-control" <input type="password" name="password" class="form-control login-form"
id="password" placeholder="Password" th:value="${user.password}" th:field="*{password}"> id="password" placeholder="Password" th:value="${user.password}" th:field="*{password}">
</div> </div>
<div th:if='${user.firstName != null}' class="row align-items-start"> <div th:if='${user.firstName != null}' class="row align-items-start">

View File

@ -23,10 +23,10 @@
</div> </div>
<div th:each="item : ${products}" class="row product-div p-2 m-2"> <div th:each="item : ${products}" class="row product-div p-2 m-2">
<div class="col"> <div class="col">
<h2 th:text="${item.name}"></h2> <h2 th:text="${item.name}" style="color: white !important;"></h2>
</div> </div>
<div class="col"> <div class="col">
<h3 th:text="${item.cost} + '$'"></h3> <h3 th:text="${item.cost} + '$'" style="color: white !important;"></h3>
</div> </div>
<div class="col"> <div class="col">
<a th:href="'/product/update_product/' + ${{item.id}}" class="btn btn-primary w-100 h-100 text-lg-center">Edit</a> <a th:href="'/product/update_product/' + ${{item.id}}" class="btn btn-primary w-100 h-100 text-lg-center">Edit</a>

View File

@ -7,6 +7,13 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
<style>
.login-form {
color: black !important;
background-color: white !important;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ"
crossorigin="anonymous"> crossorigin="anonymous">
@ -17,10 +24,10 @@
integrity="sha384-Y4oOpwW3duJdCWv5ly8SCFYWqFDsfob/3GkgExXKV4idmbt98QcxXYs9UoXAB7BZ" integrity="sha384-Y4oOpwW3duJdCWv5ly8SCFYWqFDsfob/3GkgExXKV4idmbt98QcxXYs9UoXAB7BZ"
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
</head> </head>
<body> <body style="background: #f54d9a">
<div id="body-shell"> <div id="body-shell">
<header class="logo d-flex flex-wrap align-items-center justify-content-center <header class="logo d-flex flex-wrap align-items-center justify-content-center
justify-content-md-between py-3 mb-4 border-bottom" th:fragment="header"> justify-content-md-between py-3 mb-4 border-bottom" th:fragment="header" style="background: #FF9CCE !important;">
<a href="/" class="d-flex align-items-center col-md-3 mb-2 mb-md-0 text-dark text-decoration-none"> <a href="/" class="d-flex align-items-center col-md-3 mb-2 mb-md-0 text-dark text-decoration-none">
<svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap"><use xlink:href="#bootstrap"></use></svg> <svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap"><use xlink:href="#bootstrap"></use></svg>
</a> </a>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content" style="background: #f54d9a">
<div><span th:text="${error}"></span></div>
<a href="/">Go to main page</a>
</div>
</body>
</html>

View File

@ -19,12 +19,12 @@
<form th:action="@{/login}" method="post"> <form th:action="@{/login}" method="post">
<div class="mb-3"> <div class="mb-3">
<p class="mb-1">Login</p> <p class="mb-1">Login</p>
<input name="username" id="username" class="form-control" <input name="username" id="username" class="form-control login-form"
type="text" required autofocus /> type="text" required autofocus />
</div> </div>
<div class="mb-3"> <div class="mb-3">
<p class="mb-1">Password</p> <p class="mb-1">Password</p>
<input name="password" id="password" class="form-control" <input name="password" id="password" class="form-control login-form"
type="password" required /> type="password" required />
</div> </div>
<div class="mb-3"> <div class="mb-3">

View File

@ -22,19 +22,19 @@
<form method="post" th:object="${userDto}" th:action="@{/signup}"> <form method="post" th:object="${userDto}" th:action="@{/signup}">
<div class="container"> <div class="container">
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<input type="text" name="name" class="form-control" <input type="text" name="name" class="form-control login-form"
id="name" placeholder="Name" th:field="${userDto.firstName}"> id="name" placeholder="Name" th:field="${userDto.firstName}">
</div> </div>
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<input type="text" name="surname" class="form-control" <input type="text" name="surname" class="form-control login-form"
id="surname" placeholder="Surname" th:field="${userDto.lastName}"> id="surname" placeholder="Surname" th:field="${userDto.lastName}">
</div> </div>
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<input type="email" name="email" class="form-control" <input type="email" name="email" class="form-control login-form"
id="email" placeholder="Email" th:field="${userDto.email}"> id="email" placeholder="Email" th:field="${userDto.email}">
</div> </div>
<div class="row gy-5 p-2"> <div class="row gy-5 p-2">
<input type="password" name="password" class="form-control" <input type="password" name="password" class="form-control login-form"
id="password" placeholder="Password" th:field="${userDto.password}"> id="password" placeholder="Password" th:field="${userDto.password}">
</div> </div>
<div class="row gy-5"> <div class="row gy-5">