-
Notifications
You must be signed in to change notification settings - Fork 309
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
[톰캣 구현하기 - 1,2단계] 이오(이지우) 미션 제출합니다. #343
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
00797bc
test(IOStreamTest): IOStream 학습
LJW25 5d15f31
feat(Http11Request): HttpRequest 객체 생성
LJW25 722eaad
feat(Http11Response): HttpResponse 객체 생성
LJW25 8986f2d
feat(Http11Processor): 인덱스 페이지 접근 구현 (미션1-1)
LJW25 c647bc9
refactor(Http11Processor): NPE 방지 추가
LJW25 e038285
feat(Http11*): css 설정 구현
LJW25 fe1459f
feat(Http11*): QueryString 파싱 구현
LJW25 a83ca3e
feat(Http11Response): Response 객체 상태코드 추가
LJW25 9f0af06
feat(Http11Processor): 로그인 여부에 따른 페이지 이동 구현
LJW25 d95d07c
chore(login.html): 로그인 요청 방식 변경
LJW25 a4f5414
feat(Http11*): POST 구현
LJW25 54dbe20
feat(Http11*): Cookie 구현
LJW25 63ce5fe
feat(Http11*): Session 구현
LJW25 c840b3e
refactor(all): 구조 변경 및 컨벤션 적용
LJW25 6fdde09
test(Http11Processor): 테스트코드 추가
LJW25 40c75a8
refactor(Http11*): 컨벤션 리팩토링
LJW25 e3c9ece
refactor(UserService): Optional 사용 방식 변경
LJW25 a35bb6f
refactor(UserService): 메소드 네이밍 변경
LJW25 5e1f9dd
refactor(Http*): 클래스 네이밍 변경
LJW25 de99202
refactor(Http11Processor): 예외 처리 방식 변경
LJW25 702c0b7
refactor(Constant): 상수처리
LJW25 a0b819c
feat(*Header): Header Enum 구현
LJW25 d62ae11
refactor(Status): status 메소드 위치 변경
LJW25 90b384e
refactor(all): 코드 리팩토링
LJW25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 55 additions & 0 deletions
55
tomcat/src/main/java/nextstep/jwp/service/UserService.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,55 @@ | ||
package nextstep.jwp.service; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import nextstep.jwp.db.InMemoryUserRepository; | ||
import nextstep.jwp.model.User; | ||
import org.apache.coyote.http11.Session; | ||
import org.apache.coyote.http11.SessionManager; | ||
import org.apache.coyote.http11.exception.UnauthorizedException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class UserService { | ||
private static final Logger log = LoggerFactory.getLogger(UserService.class); | ||
|
||
public String logIn(final Map<String, String> requestBody) { | ||
final String account = requestBody.get("account"); | ||
final String password = requestBody.get("password"); | ||
|
||
final User user = InMemoryUserRepository.findByAccount(account) | ||
.orElseThrow(() -> new UnauthorizedException(account)); | ||
|
||
if (!user.checkPassword(password)) { | ||
throw new UnauthorizedException(account); | ||
} | ||
log.info("{}", user); | ||
|
||
return setSession(user); | ||
} | ||
|
||
private String setSession(final User user) { | ||
final String id = UUID.randomUUID().toString(); | ||
final Session session = new Session(id); | ||
session.setAttribute("user", user); | ||
SessionManager.add(session); | ||
return id; | ||
} | ||
|
||
public String register(final Map<String, String> requestBody) { | ||
final String account = requestBody.get("account"); | ||
final String password = requestBody.get("password"); | ||
final String email = requestBody.get("email"); | ||
|
||
InMemoryUserRepository.findByAccount(account) | ||
.ifPresent(ignored -> { | ||
throw new UnauthorizedException(account); | ||
}); | ||
|
||
final User user = new User(account, password, email); | ||
InMemoryUserRepository.save(user); | ||
|
||
return setSession(user); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
UserService 👍
전 이 생각을 못하고 그냥 InMemoryUserRepository를 가져다 썼는데 좋은 접근 방법인 것 같습니다