From a7f87f09e6c2e48b7ff7733ab9cdf88d98d18244 Mon Sep 17 00:00:00 2001 From: 82everywin <82everywin@gmail.com> Date: Mon, 27 May 2024 18:16:40 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EC=8A=A4=ED=94=84=EB=A7=81=20?= =?UTF-8?q?=EC=8B=9C=ED=81=90=EB=A6=AC=ED=8B=B0=20&=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=95=94=ED=98=B8=20-=20#63?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todolist/todolist/controller/MemberController.java | 4 ++-- .../com/todolist/todolist/security/PasswordConfig.java | 1 + .../com/todolist/todolist/service/MemberService.java | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/controller/MemberController.java b/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/controller/MemberController.java index 6d0a0f3..2027635 100644 --- a/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/controller/MemberController.java +++ b/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/controller/MemberController.java @@ -42,12 +42,12 @@ public ResponseEntity createMember(@Valid @RequestBody Member @Operation(summary = "로그인") @PostMapping("/login") - public String loginMember(@RequestBody @Valid MemberRequestDto.LoginRequestDto request){ + public ResponseEntity loginMember(@RequestBody @Valid MemberRequestDto.LoginRequestDto request){ MemberLoginResponseDto responseDto = memberService.login(request); String jwtToken = jwtTokenProvider.createToken(request.getLoginId()); - return jwtToken; + return ResponseEntity.status(HttpStatus.OK).body(jwtToken); // return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); } @Operation(summary = "회원정보 수정") diff --git a/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/security/PasswordConfig.java b/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/security/PasswordConfig.java index a9ade69..9cb386d 100644 --- a/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/security/PasswordConfig.java +++ b/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/security/PasswordConfig.java @@ -11,4 +11,5 @@ public class PasswordConfig { public PasswordEncoder passwordEncoder(){ return new BCryptPasswordEncoder(); } + } diff --git a/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/service/MemberService.java b/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/service/MemberService.java index fcd91d5..e095164 100644 --- a/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/service/MemberService.java +++ b/contents/todoListAPI/hyeonseung/todolist/src/main/java/com/todolist/todolist/service/MemberService.java @@ -7,6 +7,7 @@ import com.todolist.todolist.dto.member.MemberResponseDto; import com.todolist.todolist.repository.MemberRepository; +import com.todolist.todolist.security.PasswordConfig; import com.todolist.todolist.validators.BaseException; import com.todolist.todolist.validators.ErrorCode; import lombok.RequiredArgsConstructor; @@ -21,6 +22,8 @@ public class MemberService { private final MemberRepository memberRepository; + private final PasswordConfig passwordConfig; + /* 1. 가입 2. 로그인 @@ -36,6 +39,8 @@ public MemberResponseDto create(MemberRequestDto request) { throw new BaseException(ErrorCode.DUPLICATE_LOGINID); Member member = MemberMapper.INSTANCE.toEntity(request); + // 비밀번호 암호화 + member.updatePassword(passwordConfig.passwordEncoder().encode(request.getPassword())); memberRepository.save(member); return MemberMapper.INSTANCE.toDto(member); @@ -45,7 +50,7 @@ public MemberResponseDto create(MemberRequestDto request) { // 2. 로그인 public MemberLoginResponseDto login(MemberRequestDto.LoginRequestDto request){ Member member = throwFindbyLoginId(request.getLoginId()); - if (!member.getPassword().equals(request.getPassword())) + if (!passwordConfig.passwordEncoder().matches(request.getPassword(), member.getPassword())) throw new BaseException(ErrorCode.UNAUTHORIZED_LOGIN); return new MemberLoginResponseDto(member.getLoginId()); } @@ -74,7 +79,7 @@ public MemberResponseDto update(Long id, MemberRequestDto request){ throw new BaseException(ErrorCode.DUPLICATE_LOGINID); else { member.updateLoginId(request.getLoginId()); - member.updatePassword(request.getPassword()); + member.updatePassword(passwordConfig.passwordEncoder().encode(request.getPassword())); member.updateName(request.getName()); }