Сохранение перед перезагрузкой.

This commit is contained in:
Programmist73 2023-05-13 08:57:19 +04:00
parent 68a0bd7c14
commit 65800b9a6f
7 changed files with 33 additions and 17 deletions

View File

@ -33,7 +33,8 @@ dependencies {
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
//implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.1.RELEASE'
implementation 'org.hibernate.validator:hibernate-validator'
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'

View File

@ -7,6 +7,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@ -36,7 +37,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
final String admin = "admin";
if (clientService.findByLogin(admin) == null) {
log.info("Admin user successfully created");
clientService.addClient(admin, "adminemail@gmail.com", admin, admin, UserRole.ADMIN);
clientService.addClient(admin, "adminemail@gmail.com", admin, 0, admin, UserRole.ADMIN);
}
}
@ -46,15 +47,15 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.cors().and()
.csrf().disable()
.authorizeHttpRequests()
.requestMatchers(UserSignupMvcController.SIGNUP_URL).permitAll()
.requestMatchers(HttpMethod.GET, LOGIN_URL).permitAll()
.antMatchers(UserSignupMvcController.SIGNUP_URL).permitAll()
.antMatchers(HttpMethod.GET, LOGIN_URL).permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage(LOGIN_URL).permitAll()
.and()
.logout().permitAll();
return http.build();
return http.userDetailsService(clientService).build();
}
@Bean
@ -65,12 +66,12 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
return authenticationManagerBuilder.build();
}
@Bean
/*@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring()
.requestMatchers("/css/**")
.requestMatchers("/js/**")
.requestMatchers("/templates/**")
.requestMatchers("/webjars/**");
}
}*/
}

View File

@ -1,7 +1,13 @@
package premium_store.configuration;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

View File

@ -82,7 +82,7 @@ public class ClientMvcController {
if (bindingResult.hasErrors()) {
model.addAttribute("errors", bindingResult.getAllErrors());
return "user";
return "client-edit";
}
try {

View File

@ -28,7 +28,7 @@ public class UserSignupMvcController {
@GetMapping
public String showSignupForm(Model model) {
model.addAttribute("userDto", new UserSignupDto());
model.addAttribute("clientDTO", new UserSignupDto());
return "signup";
}
@ -41,8 +41,8 @@ public class UserSignupMvcController {
return "signup";
}
try {
final GameClient user = clientService.addClient(userSignupDto.getLogin(), userSignupDto.getEmail(), userSignupDto.getPassword(), userSignupDto.getBalance(), userSignupDto.getPasswordConfirm(), UserRole.USER);
return "redirect:/login?created=" + user.getLogin();
final GameClient client = clientService.addClient(userSignupDto.getLogin(), userSignupDto.getEmail(), userSignupDto.getPassword(), userSignupDto.getBalance(), userSignupDto.getPasswordConfirm(), UserRole.USER);
return "redirect:/login?created=" + client.getLogin();
} catch (ValidationException e) {
model.addAttribute("errors", e.getMessage());
return "signup";

View File

@ -13,12 +13,20 @@
</div>
<form action="#" th:action="@{/client/{id}(id=${id})}" th:object="${supportClientDTO}" method="post">
<div class="myModalContent">
<label for="name" class="form-label">Никнейм: </label>
<label for="name" class="form-label">Логин: </label>
<input
type='text'
class="add-nation-input form-control"
id="name"
th:field="${supportClientDTO.nickName}"
th:field="${supportClientDTO.login}"
required="true"
/>
<label for="password" class="form-label">Пароль: </label>
<input
type='text'
class="add-nation-input form-control"
id="password"
th:field="${supportClientDTO.password}"
required="true"
/>
<label for="email" class="form-label">Почта: </label>
@ -54,7 +62,7 @@
<button
class="modalButton"
type="submit"
th:href="@{/client}"
th:href="@{/clients}"
>
Назад
</button>

View File

@ -11,15 +11,15 @@
<div th:if="${errors}" th:text="${errors}" class="margin-bottom alert alert-danger"></div>
<form action="#" th:action="@{/signup}" th:object="${userDto}" method="post">
<div class="mb-3">
<input type="text" class="form-control" th:field="${userDto.login}“
<input type="text" class="form-control" th:field="${clientDTO.login}“
placeholder="Логин" required="true" autofocus="true" maxlength="64"/>
</div>
<div class="mb-3">
<input type="password" class="form-control" th:field="${userDto.password}“
<input type="password" class="form-control" th:field="${clientDTO.password}“
placeholder="Пароль" required="true" minlength="6" maxlength="64"/>
</div>
<div class="mb-3">
<input type="password" class="form-control" th:field="${userDto.passwordConfirm}“
<input type="password" class="form-control" th:field="${clientDTO.passwordConfirm}“
placeholder="Пароль (подтверждение)" required="true" minlength="6" maxlength="64"/>
</div>
<div class="mb-3">