fixes
This commit is contained in:
1 parent
00374da288
commit
27f4885a30
11 files changed
+60
-78
No files matched your search
+4
-3
@@ -6,7 +6,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'site.easy-startup'
|
group = 'site.easy-startup'
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = '0.0.8'
|
||||||
sourceCompatibility = "17"
|
sourceCompatibility = "17"
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
@@ -20,7 +20,8 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springdoc:springdoc-openapi-ui:1.6.9'
|
implementation 'mysql:mysql-connector-java:8.0.30'
|
||||||
|
implementation 'org.springdoc:springdoc-openapi-ui:1.6.11'
|
||||||
implementation 'com.google.code.gson:gson:2.9.0'
|
implementation 'com.google.code.gson:gson:2.9.0'
|
||||||
implementation 'com.auth0:java-jwt:4.0.0'
|
implementation 'com.auth0:java-jwt:4.0.0'
|
||||||
implementation 'org.springframework:spring-websocket:5.3.22'
|
implementation 'org.springframework:spring-websocket:5.3.22'
|
||||||
@@ -53,4 +54,4 @@ tasks.named('compileJava') {
|
|||||||
inputs.files(tasks.named('processResources'))
|
inputs.files(tasks.named('processResources'))
|
||||||
}
|
}
|
||||||
|
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
@@ -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.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
@@ -36,6 +37,7 @@ public class JWTFilter extends OncePerRequestFilter {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
String email = jwtUtil.validateTokenAndRetrieveClaim(jwt);
|
String email = jwtUtil.validateTokenAndRetrieveClaim(jwt);
|
||||||
|
|
||||||
UserDetails userDetails = userDetailService.loadUserByUsername(email);
|
UserDetails userDetails = userDetailService.loadUserByUsername(email);
|
||||||
|
|
||||||
UsernamePasswordAuthenticationToken authenticationToken =
|
UsernamePasswordAuthenticationToken authenticationToken =
|
||||||
|
|||||||
@@ -41,9 +41,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.and()
|
.and()
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers(SecurityConstants.SIGN_UP_URLS).permitAll()
|
.antMatchers(SecurityConstants.SIGN_UP_URLS).permitAll()
|
||||||
.antMatchers("/auth/*").anonymous()
|
.anyRequest().authenticated().and()
|
||||||
.antMatchers("/").permitAll()
|
.antMatcher("/auth/*").anonymous();
|
||||||
.anyRequest().authenticated();
|
|
||||||
http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
|
http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package site.easystartup.web.service;
|
package site.easystartup.web.service;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import site.easystartup.web.domain.exception.UserExistException;
|
import site.easystartup.web.domain.exception.UserExistException;
|
||||||
@@ -20,10 +21,15 @@ public class AuthService {
|
|||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
public User createUser(SignupRequest signupRequest) {
|
public User createUser(SignupRequest signupRequest) {
|
||||||
if (userRepo.findUserByUsername(signupRequest.getUsername()).isPresent()) {
|
boolean exists = false;
|
||||||
throw new UserExistException("An account with this username already exists.");
|
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 user = new User();
|
||||||
user.setEmail(signupRequest.getEmail());
|
user.setEmail(signupRequest.getEmail());
|
||||||
user.setUsername(signupRequest.getUsername());
|
user.setUsername(signupRequest.getUsername());
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package site.easystartup.web.storage.service;
|
package site.easystartup.web.storage.service;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
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.Resource;
|
||||||
import org.springframework.core.io.UrlResource;
|
import org.springframework.core.io.UrlResource;
|
||||||
import org.springframework.util.FileSystemUtils;
|
import org.springframework.util.FileSystemUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -14,7 +17,10 @@ import java.nio.file.Paths;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class FileLocalStorageService implements StorageService {
|
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() {
|
public FileLocalStorageService() {
|
||||||
init();
|
init();
|
||||||
|
|||||||
@@ -4,9 +4,15 @@ spring.jpa.hibernate.ddl-auto=update
|
|||||||
|
|
||||||
spring.sql.init.mode=always
|
spring.sql.init.mode=always
|
||||||
|
|
||||||
spring.sql.init.platform=postgres
|
|
||||||
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
|
#spring.sql.init.platform=postgres
|
||||||
spring.datasource.username=postgres
|
#spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
|
||||||
spring.datasource.password=root
|
#spring.datasource.username=postgres
|
||||||
|
#spring.datasource.password=root
|
||||||
|
|
||||||
|
spring.datasource.url=jdbc:mysql://mysql.joinserver.xyz:3306/s45925_test
|
||||||
|
spring.datasource.username=u45925_MqxGXdRT8T
|
||||||
|
spring.datasource.password=K=9KkskkTa3.IAW!fkJx95JE
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
|
||||||
spring.security.filter.order=10
|
spring.security.filter.order=10
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<p>API</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
const connect = () => {
|
|
||||||
const Stomp = require("stompjs");
|
|
||||||
var SockJS = require("sockjs-client");
|
|
||||||
SockJS = new SockJS("http://localhost:8080/ws");
|
|
||||||
stompClient = Stomp.over(SockJS);
|
|
||||||
stompClient.connect({}, onConnected, onError);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onConnected = () => {
|
|
||||||
console.log("connected");
|
|
||||||
|
|
||||||
stompClient.subscribe(
|
|
||||||
"/user/" + currentUser.id + "/queue/messages",
|
|
||||||
onMessageReceived
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const sendMessage = (msg) => {
|
|
||||||
if (msg.trim() !== "") {
|
|
||||||
const message = {
|
|
||||||
senderId: currentUser.id,
|
|
||||||
recipientId: activeContact.id,
|
|
||||||
senderName: currentUser.name,
|
|
||||||
recipientName: activeContact.name,
|
|
||||||
content: msg,
|
|
||||||
};
|
|
||||||
|
|
||||||
stompClient.send("/app/chat", {}, JSON.stringify(message));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
function connect() {
|
|
||||||
let socket = new SockJs(`api/socket`);
|
|
||||||
|
|
||||||
let stompClient = Stomp.over(socket);
|
|
||||||
|
|
||||||
return stompClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
let stompClient = this.webSocketService.connect();
|
|
||||||
|
|
||||||
stompClient.connect({}, frame => {
|
|
||||||
|
|
||||||
stompClient.subscribe('/user/queue/notification', notification => {
|
|
||||||
console.log('test'+ notification)
|
|
||||||
JSON.parse(notification.body);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
const sendMessage = (msg) => {
|
|
||||||
if (msg.trim() !== "") {
|
|
||||||
const message = {
|
|
||||||
senderId: currentUser.id,
|
|
||||||
recipientId: activeContact.id,
|
|
||||||
senderName: currentUser.name,
|
|
||||||
recipientName: activeContact.name,
|
|
||||||
content: msg,
|
|
||||||
};
|
|
||||||
|
|
||||||
stompClient.send("/app/chat", {}, JSON.stringify(message));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>API</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>API</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in new issue
Block a user