Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #741

Merged
merged 11 commits into from
Sep 25, 2023
32 changes: 26 additions & 6 deletions client/src/components/MyPage/MyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function MyPage() {

const [withdrawModal, setWithdrawModal] = useState(false);

const [accompanyList, setAccompanyList] = useState(["안녕하세요","안녕하세요","안녕하세요","안녕하세요","안녕하세요"]) // 동행 신청 현황
const [accompanyList, setAccompanyList] = useState(["1","2","3","4","5"]) // 동행 신청 현황

var ranklist = "";
var size = posts.length;
Expand Down Expand Up @@ -505,13 +505,33 @@ function MyPage() {
<Card key={idx} style={{
height: '100px'
}} >
{item}
<Button
<h6>여행 일정 :</h6>
<h6>신청자 : </h6>
<h6>신청 내용 : {item.length <= 50 ? item : item.slice(0,50) + '...'}</h6>
<table>
<td><Button
onClick={(e) => {
const updateList = accompanyList.filter((listItem) => listItem !== item)
setAccompanyList(updateList);
}}
style={{
width: '50px',
height: '50px'
marginTop: '-15%',
marginLeft: '170%',
width: '40px',
height: '40px'
}}
>O</Button>
>O</Button></td>
<td>
<Button onClick= {(e) => {
const updateList = accompanyList.filter((listItem) => listItem !== item)
setAccompanyList(updateList);
}}
style={{marginTop: '-15%', marginLeft: '85%',width: '40px', height: '40px'}}>
X
</Button>
</td>
</table>

</Card>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Navbar/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
}

.drawer .btn {
width: 100%;
width: 80%;
text-align: left;
padding: 10px;
color: #fff;
Expand Down
34 changes: 18 additions & 16 deletions client/src/components/Navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,30 @@ function NavBar() {
})

eventSource.addEventListener('SSE',event => {
console.log("event",event);

const newMessage = event.data;

console.log('newMessage : ', event.data);
setMessages(prevMessages => [...prevMessages, newMessage]);
if(newMessage[0] === '{')
{
const jsonData = JSON.parse(newMessage);

const senderName = jsonData.senderName;
const review = jsonData.review;
const postDate = jsonData.postDate;

const notificationString = `${senderName}님이\n ${review.slice(0,4)}..를 입력하였습니다.\n ${postDate}`
setMessages(prevMessages => [...prevMessages, notificationString])
}
else{
setMessages(prevMessages => [...prevMessages, newMessage]);
}
});

eventSource.onopen =() => {
console.log('SSE connection opened.');
console.log('eventSource',eventSource);
}

eventSource.onmessage = (event) => {
try{
console.log('SSE message received: ', event.data);
const newMessage = event.data;
setMessages(prevMessages => [...prevMessages, newMessage]);
}
catch(error){
console.log("Error in onmessage: ", error);
}
}

eventSource.onerror = (error) => {
console.log("SSE connection closed");
}
Expand Down Expand Up @@ -105,8 +105,9 @@ function NavBar() {
}

function logout() {
axios
.get("http://localhost:8080/api/members/logout",{
if(token !== null){
axios
.post("http://localhost:8080/api/members/logout",token,{
headers:{
'Authorization': `Bearer ${token}`
}
Expand All @@ -125,6 +126,7 @@ function NavBar() {
});

window.location.href = "/";
}
}

var offset = localStorage.getItem("vest");
Expand Down
31 changes: 30 additions & 1 deletion client/src/components/StartPage/StartAnimationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ function StartAnimation() {
const [showModal, setShowModal] = useState(false);

const [firstShowModal, setFirstShowModal] = useState(false);

const [passwordModal, setPasswordModal] = useState(false);

const [name, setName] = useState("1"); //이름

Expand Down Expand Up @@ -290,6 +292,14 @@ function StartAnimation() {
}
};

const handlePasswordModalOpen = () => {
setPasswordModal(true)
}

const handlePasswordModalClose = () => {
setPasswordModal(false)
}

const handleNameChange = (event) => setName(event.target.value);

const handleGenderChange = (event) => setGender(event.target.value);
Expand Down Expand Up @@ -524,7 +534,26 @@ function StartAnimation() {
</Button>
</Form>
</Modal.Body>
<Modal.Footer></Modal.Footer>
<Modal.Footer>
<Button
onClick={handlePasswordModalOpen}
>
비밀번호 찾기
</Button>
<Modal
show={passwordModal}
onHide={handlePasswordModalClose}
>
<Modal.Header closeButton>
<Modal.Title>Find Password</Modal.Title>
</Modal.Header>
<Modal.Body>
<Form>
<Form.Control />
</Form>
</Modal.Body>
</Modal>
</Modal.Footer>
</Modal>
</td>
<td>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/GraduationProject/TripPlannerZ/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public RedisConnectionFactory redisConnectionFactory() {
return redisTemplate;
}

@Bean
public RedisTemplate<?, ?> blackList() {
RedisTemplate<byte[], byte[]> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory((redisConnectionFactory()));
return redisTemplate;
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package GraduationProject.TripPlannerZ.config;

import GraduationProject.TripPlannerZ.util.RedisUtil;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
Expand All @@ -16,6 +17,7 @@
public class JwtAuthFilter extends OncePerRequestFilter {

private final UserAuthProvider userAuthProvider;
private final RedisUtil redisUtil;

@Override
protected void doFilterInternal(HttpServletRequest request,
Expand All @@ -29,6 +31,12 @@ protected void doFilterInternal(HttpServletRequest request,
String[] elements = header.split(" ");
System.out.println("elements[1] = " + elements[1]);

if (elements.length == 2 && "Bearer".equals(elements[0])) {
if (redisUtil.existBlackList(elements[1])) {
throw new RuntimeException("유효하지 않은 토큰 입니다.");
}
}

// key가 Bearer이고 value가 멤버의 토큰값
if (elements.length == 2 && "Bearer".equals(elements[0])) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package GraduationProject.TripPlannerZ.config;

import GraduationProject.TripPlannerZ.util.RedisUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -17,13 +18,14 @@ public class SecurityConfig {

private final UserAuthenticationEntryPoint userAuthenticationEntryPoint;
private final UserAuthProvider userAuthProvider;
private final RedisUtil redisUtil;

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.exceptionHandling().authenticationEntryPoint(userAuthenticationEntryPoint)
.and()
.addFilterBefore(new JwtAuthFilter(userAuthProvider), BasicAuthenticationFilter.class)
.addFilterBefore(new JwtAuthFilter(userAuthProvider, redisUtil), BasicAuthenticationFilter.class)
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

import GraduationProject.TripPlannerZ.config.UserAuthProvider;
import GraduationProject.TripPlannerZ.domain.MemberPreference;
import GraduationProject.TripPlannerZ.dto.member.Credential;
import GraduationProject.TripPlannerZ.dto.member.MemberDto;
import GraduationProject.TripPlannerZ.dto.member.MemberRegister;
import GraduationProject.TripPlannerZ.dto.member.*;
import GraduationProject.TripPlannerZ.domain.Member;
import GraduationProject.TripPlannerZ.dto.member.ChangeMemberInfo;
import GraduationProject.TripPlannerZ.delete.MemberLogin;
import GraduationProject.TripPlannerZ.dto.member.MemberTrip;
import GraduationProject.TripPlannerZ.dto.member.MyPage;
import GraduationProject.TripPlannerZ.service.*;


import GraduationProject.TripPlannerZ.service.TripService;
import GraduationProject.TripPlannerZ.sseEmitter.SseEmitterService;
import GraduationProject.TripPlannerZ.util.RedisUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
Expand All @@ -38,12 +34,10 @@
public class MemberController {

private final MemberService memberService;
private final LoginService loginService;
private final TripService tripService;
private final MemberPreferenceService memberPreferenceService;
private final UserAuthProvider userAuthProvider;
private final SseEmitterService sseEmitterService;
private final PartyService partyService;
private final AuthService authService;



Expand Down Expand Up @@ -81,12 +75,10 @@ public SseEmitter subscribe() {

}

@GetMapping("/members/logout")
public void logout(HttpServletRequest request) {
HttpSession session = request.getSession(false);

if (session != null)
session.invalidate();
@PostMapping("/members/logout")
public void logout(@RequestBody BlackList blackList) {
System.out.println("blackList.getToken() = " + blackList.getToken());
authService.logout(blackList.getToken());
}

@GetMapping("/members/tripInfo")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package GraduationProject.TripPlannerZ.dto.member;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BlackList {

private String token;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package GraduationProject.TripPlannerZ.service;

import GraduationProject.TripPlannerZ.util.RedisUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AuthService {

private final RedisUtil redisUtil;

public void logout(String accessToken) {
redisUtil.setBlackList(accessToken, "BlackList", 3_600_000);
}
}
11 changes: 11 additions & 0 deletions src/main/java/GraduationProject/TripPlannerZ/util/RedisUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class RedisUtil {

private final StringRedisTemplate redisTemplate;
private final StringRedisTemplate blackList;

public String getData(String key) {
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
Expand All @@ -27,6 +28,12 @@ public void setDataExpire(String key, String value, long duration) {
valueOperations.set(key, value, expireDuration);
}

public void setBlackList(String key, String value, long duration) {
ValueOperations<String, String> valueOperations = blackList.opsForValue();
Duration expireDuration = Duration.ofSeconds(duration);
valueOperations.set(key, "BlackList", expireDuration);
}

public void deleteData(String key) {
// 데이터 삭제
redisTemplate.delete(key);
Expand All @@ -36,4 +43,8 @@ public boolean existData(String key) {
return Boolean.TRUE.equals(redisTemplate.hasKey(key));
}

public boolean existBlackList(String key) {
return Boolean.TRUE.equals(blackList.hasKey(key));
}

}
Loading