-
Notifications
You must be signed in to change notification settings - Fork 0
#20 회원가입 #21
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
base: main
Are you sure you want to change the base?
#20 회원가입 #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.queuetix.global.config; | ||
|
|
||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
|
|
||
| @Configuration | ||
| @EnableWebSecurity | ||
| @Profile("local") | ||
| public class LocalSecurityConfig { | ||
| @Bean | ||
| public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
| http | ||
| .authorizeHttpRequests(auth -> auth | ||
| .requestMatchers("/api/login","/api/members").permitAll() | ||
| .anyRequest().authenticated() | ||
| ) | ||
| .csrf(AbstractHttpConfigurer::disable) | ||
| .formLogin(AbstractHttpConfigurer::disable) | ||
| .httpBasic(AbstractHttpConfigurer::disable) | ||
| .logout(logout -> logout | ||
| .logoutUrl("/api/logout") | ||
| .invalidateHttpSession(true) | ||
| .clearAuthentication(true) | ||
| .deleteCookies("JSESSIONID") | ||
| .logoutSuccessHandler((request, response, authentication) -> { | ||
| response.setStatus(HttpServletResponse.SC_NO_CONTENT); | ||
| response.sendRedirect("/"); | ||
| })); | ||
| return http.build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public PasswordEncoder passwordEncoder() { | ||
| return new BCryptPasswordEncoder(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package com.queuetix.global.config; | ||
|
|
||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
|
|
||
| @Configuration | ||
| @EnableWebSecurity | ||
| @Profile("!local") | ||
| public class SecurityConfig { | ||
| @Bean | ||
| public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
| http | ||
| .authorizeHttpRequests(auth -> auth | ||
| .requestMatchers("/api/login","/api/members").permitAll() | ||
| .anyRequest().authenticated() | ||
| ) | ||
| .formLogin(AbstractHttpConfigurer::disable) | ||
| .httpBasic(AbstractHttpConfigurer::disable) | ||
| .logout(logout -> logout | ||
| .logoutUrl("/api/logout") | ||
| .invalidateHttpSession(true) | ||
| .clearAuthentication(true) | ||
| .deleteCookies("JSESSIONID") | ||
| .logoutSuccessHandler((request, response, authentication) -> { | ||
| response.setStatus(HttpServletResponse.SC_NO_CONTENT); | ||
| response.sendRedirect("/"); | ||
| })); | ||
| return http.build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public PasswordEncoder passwordEncoder() { | ||
| return new BCryptPasswordEncoder(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,21 @@ | ||
| package com.queuetix.global.exception; | ||
| package com.queuetix.global.exception.code; | ||
|
|
||
| import com.queuetix.global.exception.ErrorCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.HttpStatusCode; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum AuthErrorCode implements ErrorCode { | ||
| UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "인증에 실패하였습니다.") | ||
| , FORBIDDEN(HttpStatus.FORBIDDEN, "권한이 없습니다."); | ||
|
|
||
| private final HttpStatusCode httpStatusCode; | ||
| private final String message; | ||
|
|
||
| AuthErrorCode(HttpStatusCode httpStatusCode, String message) { | ||
| this.httpStatusCode = httpStatusCode; | ||
| this.message = message; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.queuetix.global.exception.code; | ||
|
|
||
| import com.queuetix.global.exception.ErrorCode; | ||
| import lombok.Getter; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.HttpStatusCode; | ||
|
|
||
| @Getter | ||
| public enum MemberErrorCode implements ErrorCode { | ||
| MEMBER_DUPLICATED_LOGIN_ID(HttpStatus.CONFLICT, "중복된 아이디입니다.") | ||
| , MEMBER_DUPLICATED_EMAIL(HttpStatus.CONFLICT, "중복된 이메일입니다.") | ||
| , MEMBER_DUPLICATED_PHONE(HttpStatus.CONFLICT, "중복된 전화번호입니다."); | ||
|
|
||
| private final HttpStatusCode httpStatusCode; | ||
| private final String message; | ||
|
|
||
| MemberErrorCode(HttpStatusCode httpStatusCode, String message) { | ||
| this.httpStatusCode = httpStatusCode; | ||
| this.message = message; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.queuetix.global.support; | ||
|
|
||
| import com.queuetix.global.exception.QueueTixException; | ||
| import com.queuetix.global.exception.code.ReservationErrorCode; | ||
| import com.queuetix.member.dto.MemberLoginRequest; | ||
| import jakarta.validation.Valid; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Profile("local") | ||
| @RestController | ||
| @RequestMapping("/test") | ||
| public class TestController { | ||
| @GetMapping("queue-tix") | ||
| public void queueTixException() { | ||
| throw new QueueTixException(ReservationErrorCode.RESERVATION_NOT_FOUND); | ||
| } | ||
|
|
||
| @GetMapping("/illlegal-argument") | ||
| public void illegalArgumentException() { | ||
| throw new IllegalArgumentException("부적절한 파라미터 오류 테스트"); | ||
| } | ||
|
|
||
| @GetMapping("/server-error") | ||
| public void serverError() throws Exception { | ||
| throw new Exception("서버 오류 테스트"); | ||
| } | ||
|
|
||
| @GetMapping("/validation") | ||
| public void validation(@RequestBody @Valid MemberLoginRequest request) { | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,31 @@ | ||
| package com.queuetix.member.controller; | ||
|
|
||
| import com.queuetix.global.exception.QueueTixException; | ||
| import com.queuetix.global.exception.code.MemberErrorCode; | ||
| import com.queuetix.member.dto.MemberSignUpRequest; | ||
| import com.queuetix.member.service.MemberService; | ||
| import jakarta.validation.Valid; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api") | ||
| public class MemberController { | ||
| private final MemberService memberService; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. controller test 를 추가해보면 어떨까요? |
||
|
|
||
| @Autowired | ||
| public MemberController(MemberService memberService) { | ||
| this.memberService = memberService; | ||
| } | ||
|
|
||
| @PostMapping("/members") | ||
| public ResponseEntity<Void> addMember(@RequestBody @Valid MemberSignUpRequest request) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MemberSignUpRequest가 valid한지 체크하는 부분도 테스트해볼 수 있을까요? |
||
| memberService.addMember(request); | ||
| return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 회원가입이 되고 나서 생성된 회원에 대한 정보를 필요로 할 수 있어 보입니다. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,23 +2,24 @@ | |
|
|
||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Null; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| public class MemberSignUpRequest { | ||
| public record MemberSignUpRequest ( | ||
| @NotBlank(message = "로그인 아이디를 입력해주세요") | ||
| private String loginId; | ||
| String loginId, | ||
|
Comment on lines
-13
to
+14
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private을 지우신 이유가 있으실까요? |
||
| @NotBlank(message = "비밀번호를 입력해주세요.") | ||
| private String password; | ||
| String password, | ||
| @NotBlank(message = "성함을 입력해주세요.") | ||
| private String name; | ||
| String name, | ||
| @Email(message = "이메일 형식이 올바르지 않습니다.") | ||
| @NotBlank(message = "이메일을 입력해주세요.") | ||
| private String email; | ||
| String email, | ||
| @Pattern(regexp = "^\\d{2,3}-\\d{3,4}-\\d{4}$", message = "휴대폰 형식이 올바르지 않습니다.") | ||
| private String phone; | ||
| private String address; | ||
| } | ||
| String phone, | ||
| String address | ||
| ) {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.queuetix.member.repository; | ||
|
|
||
| import com.queuetix.member.domain.Member; | ||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface MemberRepository extends JpaRepository<Member, Long> { | ||
| Optional<Member> findByLoginId(String loginId); | ||
|
|
||
| Optional<Member> findByEmail(String email); | ||
|
|
||
| Optional<Member> findByPhone(String phone); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 컨트롤러는 사용되지 않으면 삭제하면 어떨까요?
controller test 를 위해서 @WebMvcTest를 이용하여 테스트코드로 작성해보면 어떨까요?