-
Notifications
You must be signed in to change notification settings - Fork 1
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
[BE] 회원가입 중복 확인 로그인 개인정보 조회 #62
Changes from all commits
a527714
ec8b54e
b484814
0aa3fad
3177977
7374252
dd60c71
e3b2e0b
596e799
7e24025
96afac9
0234448
8708346
2f6ca60
b86e3e8
ed6e2e3
4b61e3c
edc9b32
3e9db3b
8e1c59b
aa573ac
54d6c29
9f8cbfa
b88d065
c42d674
6192521
2cd3817
d347b16
5289c36
50fb895
e8ae29f
e017496
b224be7
f09cf63
9216e38
0c00bd4
080cb79
f2e28ff
fcf5f69
429d8ba
b029fb8
7f57c44
1d2cbec
4fd0194
82e7a8d
9241bdf
965b8a6
8ab8e75
b250552
b19dc23
15fa6db
cb203dd
ad99b02
0258dbe
b79260e
3b70223
28fc6ae
ee062ae
9e552c5
de55678
b1c924e
75b8d89
1909d17
9bb0601
9498a50
986c43b
c1f7c9d
dce3962
cbfa738
edb8a50
c2afc79
86acde0
c7d50cf
f845aea
e84724d
e8e4a4e
4435c12
08a4289
4b109d1
94118ad
e96ff41
d2474cc
13fcdf0
cf32fdc
3a614bc
b61bb81
23ab6d1
8fbdd4c
08df9e9
f4ee952
5f0fb40
25d3bcd
d78daf4
fd1dc25
c914786
9788578
bd97020
ac1cc31
8834e9e
215c7c3
64a2328
4e9f622
4ef1f5b
eee260f
6301b43
5f3e670
0d2f2b4
dbf0042
efe280d
3b9caf6
9c4342a
4162197
e1e5bc2
4cd3652
e3031a0
22322d3
6e3b8d8
dd795fe
f4ac2eb
93af823
4dde1da
8a0c5b8
8aa67f1
f35618b
2c953b7
442ce9f
a04fe25
23836ae
f970e4e
225cf4f
4d0d114
30430a2
ec95eb7
04b0f3c
803eec0
0b1db66
d50718e
31dfc84
5fd21c0
c54db8e
66648f2
ef6be90
a2cae34
63e5d5d
743b499
6a04a7a
947fa1c
9e264d1
0f88fc9
f01d4b0
2c25810
b3a1924
bba09ad
858ac06
dffa368
1231a9c
2d10d67
ce55767
bfcc073
0140c3a
4fb4e71
46843c9
64faf40
3fa2384
3375b0f
5940d95
ec77322
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 |
---|---|---|
@@ -1,3 +1,110 @@ | ||
|
||
### macOS ### | ||
# General | ||
.DS_Store | ||
*wcworkspace/xcuserdata/* | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Swift ### | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData/ | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
|
||
## Other | ||
*.moved-aside | ||
*.xccheckout | ||
*.xcscmblueprint | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
# Package.resolved | ||
.build/ | ||
# Add this line if you want to avoid checking in Xcode SPM integration. | ||
# .swiftpm/xcode | ||
|
||
# CocoaPods | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# Pods/ | ||
# Add this line if you want to avoid checking in source code from the Xcode workspace | ||
# *.xcworkspace | ||
|
||
# Carthage | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build | ||
|
||
# Accio dependency management | ||
Dependencies/ | ||
.accio/ | ||
|
||
# fastlane | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
# Code Injection | ||
# After new code Injection tools there's a generated folder /iOSInjectionProject | ||
# https://github.com/johnno1962/injectionforxcode | ||
|
||
<<<<<<< HEAD | ||
iOSInjectionProject/ | ||
======= | ||
iOSInjectionProject/ | ||
>>>>>>> origin/dev |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.codesquad.signup; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addViewControllers(ViewControllerRegistry registry) { | ||
registry.setOrder(Ordered.HIGHEST_PRECEDENCE); | ||
registry.addViewController("/main").setViewName("main"); | ||
registry.addViewController("/joinForm").setViewName("signup"); | ||
registry.addViewController("/loginForm").setViewName("login"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.codesquad.signup.controller; | ||
|
||
import com.codesquad.signup.exception.UnauthorizedException; | ||
import com.codesquad.signup.message.ErrorMessages; | ||
import com.codesquad.signup.message.SuccessMessages; | ||
import com.codesquad.signup.repository.ApiResponse; | ||
import com.codesquad.signup.repository.User; | ||
import com.codesquad.signup.repository.UserRepository; | ||
import com.codesquad.signup.util.HttpSessionUtil; | ||
import com.codesquad.signup.util.VerifyFormatUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.http.HttpSession; | ||
import java.util.Map; | ||
|
||
@RestController | ||
public class AuthController { | ||
static final String USER_ID = "userId"; | ||
static final String PASSWORD = "password"; | ||
Comment on lines
+21
to
+22
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.
|
||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@PostMapping("/login") | ||
public ResponseEntity<ApiResponse> login(@RequestBody Map<String, String> loginInfo, HttpSession session) { | ||
|
||
String userId = loginInfo.get(USER_ID); | ||
String password = loginInfo.get(PASSWORD); | ||
|
||
if (!VerifyFormatUtil.isCorrectUserIdFormat(userId)){ | ||
throw new UnauthorizedException(ErrorMessages.FAIL_LOGIN); | ||
} | ||
|
||
if (!VerifyFormatUtil.isCorrectPasswordFormat(password)) { | ||
throw new UnauthorizedException(ErrorMessages.FAIL_LOGIN); | ||
} | ||
|
||
User user = userRepository.findByUserId(userId) | ||
.orElseThrow(() -> new UnauthorizedException(ErrorMessages.FAIL_LOGIN)); | ||
|
||
if (!user.isCorrectPassword(password)) { | ||
throw new UnauthorizedException(ErrorMessages.FAIL_LOGIN); | ||
} | ||
|
||
session.setAttribute(HttpSessionUtil.USER_SESSION_KEY, user); | ||
|
||
return new ResponseEntity<>(new ApiResponse(SuccessMessages.SUCCESS, SuccessMessages.SUCCESS_LOGIN), HttpStatus.OK); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.codesquad.signup.controller; | ||
|
||
import com.codesquad.signup.exception.NotFoundPathException; | ||
import com.codesquad.signup.exception.NotUniqueException; | ||
import com.codesquad.signup.exception.WrongFormatException; | ||
import com.codesquad.signup.message.ErrorMessages; | ||
import com.codesquad.signup.message.SuccessMessages; | ||
import com.codesquad.signup.repository.ApiResponse; | ||
import com.codesquad.signup.repository.User; | ||
import com.codesquad.signup.repository.UserRepository; | ||
import com.codesquad.signup.util.VerifyFormatUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping("/duplicate") | ||
public class DuplicateController { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@GetMapping | ||
public Object isDuplicate(String userId, String email, String phone) { | ||
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. 리턴타입으로 Object를 쓰는 건 자제해주세요. |
||
|
||
if (userId != null) | ||
return isUserIdDuplicate(userId); | ||
|
||
if (email != null) | ||
return isEmailDuplicate(email); | ||
|
||
if (phone != null) | ||
return isPhoneNumberDuplicate(phone); | ||
|
||
return new NotFoundPathException(ErrorMessages.NOTFOUND_PATH); | ||
} | ||
|
||
private ResponseEntity<ApiResponse> isUserIdDuplicate(String userId) { | ||
|
||
if (!VerifyFormatUtil.isCorrectUserIdFormat(userId)) { | ||
throw new WrongFormatException(ErrorMessages.WRONG_FORMAT); | ||
} | ||
|
||
Optional<User> user = userRepository.findByUserId(userId); | ||
|
||
if (user.isPresent()) | ||
throw new NotUniqueException(ErrorMessages.DUPLICATED_USER_ID); | ||
|
||
return new ResponseEntity<>(new ApiResponse(SuccessMessages.SUCCESS, SuccessMessages.VALID_USER_ID), HttpStatus.OK); | ||
} | ||
|
||
|
||
private ResponseEntity<ApiResponse> isEmailDuplicate(@RequestParam("email") String email) { | ||
|
||
if (!VerifyFormatUtil.isCorrectEmailFormat(email)) { | ||
throw new WrongFormatException(ErrorMessages.WRONG_FORMAT); | ||
} | ||
|
||
Optional<User> user = userRepository.findByEmail(email); | ||
|
||
if (user.isPresent()) | ||
throw new NotUniqueException(ErrorMessages.DUPLICATED_EMAIL); | ||
|
||
return new ResponseEntity<>(new ApiResponse(SuccessMessages.SUCCESS, SuccessMessages.VALID_EMAIL), HttpStatus.OK); | ||
} | ||
|
||
private ResponseEntity<ApiResponse> isPhoneNumberDuplicate(@RequestParam(value = "phone") String phone) { | ||
|
||
if (!VerifyFormatUtil.isCorrectPhoneNumberFormat(phone)) { | ||
throw new WrongFormatException(ErrorMessages.WRONG_FORMAT); | ||
} | ||
|
||
Optional<User> user = userRepository.findByPhoneNumber(phone); | ||
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. 단순히 전화번호 중복체크를 위해서 유저 전체를 받아오는 건 좋지 않아보이고요, 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. |
||
|
||
if (user.isPresent()) | ||
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. 조건문에 중괄호 |
||
throw new NotUniqueException(ErrorMessages.DUPLICATED_PHONE); | ||
|
||
return new ResponseEntity<>(new ApiResponse(SuccessMessages.SUCCESS, SuccessMessages.VALID_PHONE), HttpStatus.OK); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.codesquad.signup.controller; | ||
|
||
import com.codesquad.signup.exception.ForbiddenException; | ||
import com.codesquad.signup.exception.UserJoinFailedException; | ||
import com.codesquad.signup.message.ErrorMessages; | ||
import com.codesquad.signup.message.SuccessMessages; | ||
import com.codesquad.signup.repository.ApiResponse; | ||
import com.codesquad.signup.repository.User; | ||
import com.codesquad.signup.repository.UserRepository; | ||
import com.codesquad.signup.util.HttpSessionUtil; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.http.HttpSession; | ||
|
||
@Slf4j | ||
@RestController | ||
public class UserController { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@PostMapping("/join") | ||
@ResponseBody | ||
public ResponseEntity<ApiResponse> joinUser(@RequestBody User user) { | ||
log.debug("### joinUser : {}", user); | ||
|
||
user.checkValidUser(); | ||
|
||
try { | ||
User joinedUser = userRepository.save(user); | ||
return new ResponseEntity<>(new ApiResponse(SuccessMessages.SUCCESS, joinedUser), HttpStatus.OK); | ||
} catch (Exception e) { | ||
throw new UserJoinFailedException(ErrorMessages.FAIL_JOIN); | ||
} | ||
} | ||
|
||
@GetMapping("/user/{id}") | ||
public ResponseEntity<ApiResponse> show(@PathVariable Long id, HttpSession session) { | ||
log.debug("### show : {}", HttpSessionUtil.getUserFromSession(session)); | ||
|
||
User sessionedUser = HttpSessionUtil.getUserFromSession(session); | ||
|
||
if (!sessionedUser.getId().equals(id)) { | ||
throw new ForbiddenException(ErrorMessages.FORBIDDEN); | ||
} | ||
|
||
return new ResponseEntity<>(new ApiResponse(SuccessMessages.SUCCESS, sessionedUser), HttpStatus.OK); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.codesquad.signup.exception; | ||
|
||
import com.codesquad.signup.message.ErrorMessages; | ||
import com.codesquad.signup.repository.ApiResponse; | ||
|
||
public class BaseException extends RuntimeException { | ||
private String errorMessage; | ||
|
||
public BaseException(String errorMessage) { | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public ApiResponse returnErrorMessage() { | ||
return new ApiResponse(ErrorMessages.ERROR, errorMessage); | ||
} | ||
} |
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.
파일에 conflict mark가 그대로 묻어있네요....