This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add 회원가입 기능 - 회원가입 기능을 통해 Careers를 로그인 한 사용자들만 이용할 수 있도록 한다. - 이름, 이메일, 비밀번호 모두를 입력 받는다.(Null 체크) - 이메일은 이메일 형식에 맞게 작성해야 한다. - 비밀번호는 문자, 숫자, 특수문자로 구성되어야 한다. - 비밀번호는 암호화하여 DB에 저장한다.(sha-256) - 중복된 이메일인지 체크하여 중복가입을 제한한다. #3 * Fix 디비 primary key id로 수정 * Fix 큐레이터 테이블 unique index 설정 * Fix 회원가입 http method 변경 put -> post * Fix 롬복사용하여 생성자 자동주입 * Fix 사용하지 않는 요청 메서드 제거 * Fix 이메일 중복 예외처리 * Fix http status code 처리 이메일, 비밀번호 위반 시 status code 반환하도록 수정 * Fix model코드 가독성 처리 * Fix 암호화코드와 유저서비스 기능 분리 단일책임원칙 적용 * Fix Select쿼리문 email컬럼 명시적으로 표현 * Fix mysql 사용자계정 변경 * Fix 롬복 Data 애노테이션 제거 명확한 의도를 설정하기위해 Data 애노테이션 대신 각각 설정 * Fix 롬복 애노테이션 정리 * Fix StringBuffer를 StringBuilder로 변경 여러 스레드가 해당 부분을 접근할 일이 현재로서는 없으므로 StringBuilder로 수정 * Fix 사용하지 않는 애노테이션 제거 * Update src/main/java/com/dev/careers/service/encryption/SHA256Encryption.java Fix 코딩 컨벤션 위반 수정 Co-authored-by: f-lab <54677861+f-lab-dev@users.noreply.github.com> * Fix 인터페이스, 클래스 명명규칙 수정 Encryption -> Encryptor 로 변경 * Fix 메소드 명명규칙 수정 * Add 로그인 기능 추가 - 이메일, 비밀번호를 입력받는다.(Null 체크) - DB에 등록되어있는 회원인지 체크한다. - 앱 종료 후 앱을 실행하면 자동 로그인이 되어 사용 가능하도록 한다.(세션방식) #4 * Fix 요청에따른 결과 반환 void로 수정 * Fix void반환으로 인한 테스트케이스 수정 * Fix 성능보완을 위해 쿼리로 중복검증 체크 * Fix 성능향상을 위해 쿼리문 수정 exists를 사용하여 쿼리성능향상 및 이메일 존재 유무에 대해 명확하게 표현 * Fix Optional 사용하여 코드정리 * Fix HttpSession 으로 세션처리 * Fix 서비스로 세션로직 분리 Controller에서 처리한 세션로직을 Service에서 처리하도록 처리 단일책임원칙을 준수하도록하여 별도의 SessionController클래스생성 * Fix checkstyle 위반된 부분 수정 카멜케이스 적용 * Fix session처리 클래스 이름변경 * Fix 클래스 이름변경에 따른 누락된 부분 커밋 * Fix 로그인 인증부분 SRP적용 로그인/로그아웃에 대한 세션처리부분을 SessionAuthenticator에서 담당하도록 수정 * Fix 세션을 주입 처리 - SetAttribute를 호춣한 시점에 Servlet Container가 생성한 Session을 주입받도록 수정 - Session 인증 처리 메서드 이름 변경 * Fix session처리 메소드 이름변경 Co-authored-by: f-lab <54677861+f-lab-dev@users.noreply.github.com>
- Loading branch information
1 parent
60ed0cc
commit 1a96838
Showing
12 changed files
with
211 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 32 additions & 4 deletions
36
src/main/java/com/dev/careers/controller/CuratorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,62 @@ | ||
package com.dev.careers.controller; | ||
|
||
import com.dev.careers.model.Curator; | ||
import com.dev.careers.model.LoginParamter; | ||
import com.dev.careers.service.CuratorService; | ||
import com.dev.careers.service.error.ViolationException; | ||
import com.dev.careers.service.session.SessionAuthenticator; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Optional; | ||
import javax.servlet.http.HttpSession; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.ObjectError; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("curators") | ||
public class CuratorController { | ||
|
||
private final CuratorService curatorService; | ||
private final SessionAuthenticator sessionAuthenticator; | ||
|
||
@PostMapping("/curators/join") | ||
public void putMember(@Valid @ModelAttribute Curator curator, BindingResult bindingResult) | ||
@PostMapping("join") | ||
public void joinMember(@Valid @ModelAttribute Curator curator, BindingResult bindingResult) | ||
throws Exception { | ||
verifyCuratorParameter(bindingResult); | ||
|
||
curatorService.join(curator); | ||
} | ||
|
||
@PostMapping("login") | ||
public void loginMember(@Valid @ModelAttribute LoginParamter loginParamter, | ||
HttpSession httpSession, | ||
BindingResult bindingResult) | ||
throws NoSuchAlgorithmException { | ||
|
||
verifyCuratorParameter(bindingResult); | ||
curatorService.login(loginParamter); | ||
sessionAuthenticator.login(loginParamter); | ||
} | ||
|
||
@DeleteMapping("logout") | ||
public void logout() { | ||
sessionAuthenticator.logout(); | ||
} | ||
|
||
public void verifyCuratorParameter(BindingResult bindingResult) { | ||
if (bindingResult.hasErrors()) { | ||
Optional<ObjectError> objectError = bindingResult.getAllErrors().stream().findFirst(); | ||
if (objectError.isPresent()) { | ||
throw new ViolationException(); | ||
} | ||
} | ||
|
||
curatorService.join(curator); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
package com.dev.careers.mapper; | ||
|
||
import java.util.HashMap; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
@Mapper | ||
public interface CuratorMapper { | ||
|
||
Integer insertCurator( | ||
@Param("email") String email, | ||
@Param("name") String name, | ||
@Param("password") String password, | ||
@Param("salt") String salt); | ||
@Param("email") String email, | ||
@Param("name") String name, | ||
@Param("password") String password, | ||
@Param("salt") String salt); | ||
|
||
HashMap<String, String> getMemberInfo(@Param("email") String email); | ||
|
||
boolean checkEmailExists(@Param("email") String email); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.dev.careers.model; | ||
|
||
import javax.validation.constraints.Email; | ||
import javax.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class LoginParamter { | ||
|
||
@NonNull | ||
@Email(message = "Email Format Violation") | ||
private String email; | ||
|
||
//최소 8자리에 숫자, 문자, 특수문자 각각 1개 이상 포함 | ||
@Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[$@$!%*#?&])[A-Za-z\\d$@$!%*#?&]{8,}$", | ||
message = "Password Format Violation") | ||
@NonNull | ||
private String password; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/dev/careers/service/session/SessionAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.dev.careers.service.session; | ||
|
||
import com.dev.careers.model.LoginParamter; | ||
import java.util.Optional; | ||
import javax.servlet.http.HttpSession; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SessionAuthenticator { | ||
|
||
private final static String sessionName = "sessionInfo"; | ||
private final HttpSession httpSession; | ||
|
||
public SessionAuthenticator(HttpSession httpSession) { | ||
this.httpSession = httpSession; | ||
} | ||
|
||
public void login(LoginParamter loginParamter) { | ||
httpSession.setAttribute(sessionName,loginParamter); | ||
} | ||
|
||
public void logout() { | ||
httpSession.removeAttribute(sessionName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters