This commit is contained in:
redtea committed 2022-09-15 22:49:10 +03:00
1 parent 00374da288
commit 27f4885a30
11 files changed
+60 -78

No files matched your search

@@ -0,0 +1,12 @@
package site.easystartup.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MainController {
@GetMapping("/")
public String main() {
return "/main";
}
}
@@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
@@ -36,6 +37,7 @@ public class JWTFilter extends OncePerRequestFilter {
} else {
try {
String email = jwtUtil.validateTokenAndRetrieveClaim(jwt);
UserDetails userDetails = userDetailService.loadUserByUsername(email);
UsernamePasswordAuthenticationToken authenticationToken =
@@ -41,9 +41,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.and()
.authorizeRequests()
.antMatchers(SecurityConstants.SIGN_UP_URLS).permitAll()
.antMatchers("/auth/*").anonymous()
.antMatchers("/").permitAll()
.anyRequest().authenticated();
.anyRequest().authenticated().and()
.antMatcher("/auth/*").anonymous();
http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
}
@@ -1,6 +1,7 @@
package site.easystartup.web.service;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import site.easystartup.web.domain.exception.UserExistException;
@@ -20,10 +21,15 @@ public class AuthService {
private final PasswordEncoder passwordEncoder;
public User createUser(SignupRequest signupRequest) {
if (userRepo.findUserByUsername(signupRequest.getUsername()).isPresent()) {
throw new UserExistException("An account with this username already exists.");
}
boolean exists = false;
try {
if (userRepo.findUserByUsername(signupRequest.getUsername()).isPresent()) {
exists = true;
}
} catch (UsernameNotFoundException e) {}
if(exists) throw new UserExistException("An account with this username already exists.");
User user = new User();
user.setEmail(signupRequest.getEmail());
user.setUsername(signupRequest.getUsername());
@@ -1,11 +1,14 @@
package site.easystartup.web.storage.service;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.util.FileSystemUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletContext;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
@@ -14,7 +17,10 @@ import java.nio.file.Paths;
import java.util.stream.Stream;
public class FileLocalStorageService implements StorageService {
private final Path root = Paths.get("uploads");
@Autowired
ServletContext context;
private final Path root = Path.of(new FileSystemResource("").getFile().getAbsolutePath());
public FileLocalStorageService() {
init();