From 8fccfcb675d2e488c1a6746b2561eb4688b5a4f3 Mon Sep 17 00:00:00 2001 From: chwangmin Date: Sun, 19 May 2024 20:33:49 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20memberService=EB=A1=9C=20request?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=20->=20String,=20Long=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B0=94=EA=BE=B8=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 4 ++-- .../domain/member/service/MemberService.java | 21 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/com/ssafy/home/domain/member/controller/MemberController.java b/backend/src/main/java/com/ssafy/home/domain/member/controller/MemberController.java index 925c9b9..d609db2 100644 --- a/backend/src/main/java/com/ssafy/home/domain/member/controller/MemberController.java +++ b/backend/src/main/java/com/ssafy/home/domain/member/controller/MemberController.java @@ -41,7 +41,7 @@ public class MemberController { @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity register(@RequestBody RegisterRequest registerRequest){ - memberService.register(registerRequest); + memberService.register(registerRequest.getEmail(), registerRequest.getPassword(), registerRequest.getName()); return ResponseEntity.status(HttpStatus.OK).body("signup success"); } @@ -51,7 +51,7 @@ public ResponseEntity register(@RequestBody RegisterRequest registerRequ @PostMapping("/login") public ResponseEntity login(@RequestBody LoginRequest loginRequest, HttpServletResponse response){ - TokenResponse tokenResponse = memberService.login(loginRequest); + TokenResponse tokenResponse = memberService.login(loginRequest.getEmail(), loginRequest.getPassword()); response.addHeader(JwtTokenProvider.AUTHORIZATION_HEADER, tokenResponse.getAccessToken()); diff --git a/backend/src/main/java/com/ssafy/home/domain/member/service/MemberService.java b/backend/src/main/java/com/ssafy/home/domain/member/service/MemberService.java index da67c1b..be9088a 100644 --- a/backend/src/main/java/com/ssafy/home/domain/member/service/MemberService.java +++ b/backend/src/main/java/com/ssafy/home/domain/member/service/MemberService.java @@ -1,7 +1,5 @@ package com.ssafy.home.domain.member.service; -import com.ssafy.home.domain.member.dto.request.LoginRequest; -import com.ssafy.home.domain.member.dto.request.RegisterRequest; import com.ssafy.home.domain.member.dto.response.TokenResponse; import com.ssafy.home.domain.member.repository.GeneralMemberRepository; import com.ssafy.home.domain.member.repository.LoginAttemptRepository; @@ -44,32 +42,33 @@ public class MemberService { private final Encryption encryption; @Transactional - public void register(RegisterRequest registerRequest) { + public void register(String email, String password, String name) { - if (memberRepository.existsByEmail(registerRequest.getEmail())) { + if (memberRepository.existsByEmail(email)) { throw new AuthenticationException(ErrorCode.MEMBER_NOT_MATCH); } String salt = encryption.getSalt(); - String password = ""; try { - password = encryption.Hashing(registerRequest.getPassword().getBytes(), salt); + password = encryption.Hashing(password.getBytes(), salt); } catch (Exception e) { throw new BusinessException(ErrorCode.INVALID_AES_KEY); } - Member member = memberRepository.save(registerRequest.toEntity()); + Member member = memberRepository.save(Member.builder() + .name(name) + .email(email) + .build()); GeneralMember generalMember = generalMemberRepository.save(GeneralMember.builder().member(member).userEncPassword(password).build()); memberSecurityRepository.save(MemberSecret.builder().generalMember(generalMember).salt(salt).build()); loginAttemptRepository.save(LoginAttempt.builder().member(member).build()); - } @Transactional - public TokenResponse login(LoginRequest loginRequest) { + public TokenResponse login(String email, String password) { - Member member = memberRepository.findByEmail(loginRequest.getEmail()) + Member member = memberRepository.findByEmail(email) .orElseThrow(() -> new AuthenticationException(ErrorCode.MEMBER_NOT_MATCH)); if (member.getLoginAttempt().getCount() >= 5) { @@ -80,7 +79,7 @@ public TokenResponse login(LoginRequest loginRequest) { String salt = member.getGeneralMember().getMemberSecret().getSalt(); - String encPassword = encryption.Hashing(loginRequest.getPassword().getBytes(), salt); + String encPassword = encryption.Hashing(password.getBytes(), salt); if (!member.getGeneralMember().getUserEncPassword().equals(encPassword)) { throw new AuthenticationException(ErrorCode.MEMBER_NOT_MATCH);