diff --git a/.gradle/7.6.1/checksums/checksums.lock b/.gradle/7.6.1/checksums/checksums.lock new file mode 100644 index 0000000..9adeee2 Binary files /dev/null and b/.gradle/7.6.1/checksums/checksums.lock differ diff --git a/.gradle/7.6.1/checksums/md5-checksums.bin b/.gradle/7.6.1/checksums/md5-checksums.bin new file mode 100644 index 0000000..076664d Binary files /dev/null and b/.gradle/7.6.1/checksums/md5-checksums.bin differ diff --git a/.gradle/7.6.1/checksums/sha1-checksums.bin b/.gradle/7.6.1/checksums/sha1-checksums.bin new file mode 100644 index 0000000..9b82eec Binary files /dev/null and b/.gradle/7.6.1/checksums/sha1-checksums.bin differ diff --git a/.gradle/7.6.1/dependencies-accessors/dependencies-accessors.lock b/.gradle/7.6.1/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000..35023ac Binary files /dev/null and b/.gradle/7.6.1/dependencies-accessors/dependencies-accessors.lock differ diff --git a/.gradle/7.6.1/dependencies-accessors/gc.properties b/.gradle/7.6.1/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/7.6.1/executionHistory/executionHistory.bin b/.gradle/7.6.1/executionHistory/executionHistory.bin new file mode 100644 index 0000000..e2170b9 Binary files /dev/null and b/.gradle/7.6.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.6.1/executionHistory/executionHistory.lock b/.gradle/7.6.1/executionHistory/executionHistory.lock new file mode 100644 index 0000000..2ab46cd Binary files /dev/null and b/.gradle/7.6.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.6.1/fileChanges/last-build.bin b/.gradle/7.6.1/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/7.6.1/fileChanges/last-build.bin differ diff --git a/.gradle/7.6.1/fileHashes/fileHashes.bin b/.gradle/7.6.1/fileHashes/fileHashes.bin new file mode 100644 index 0000000..81506a0 Binary files /dev/null and b/.gradle/7.6.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.6.1/fileHashes/fileHashes.lock b/.gradle/7.6.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000..337786c Binary files /dev/null and b/.gradle/7.6.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.6.1/fileHashes/resourceHashesCache.bin b/.gradle/7.6.1/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000..40218de Binary files /dev/null and b/.gradle/7.6.1/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/7.6.1/gc.properties b/.gradle/7.6.1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..1dab492 Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..0fdafb0 --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Sun Aug 18 21:14:11 KST 2024 +gradle.version=7.6.1 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..b9f1ebd Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe new file mode 100644 index 0000000..6c1d4d6 Binary files /dev/null and b/.gradle/file-system.probe differ diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..23baf58 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 디폴트 무시된 파일 +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..4b77bc4 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +landlog \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..f9163b4 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e557731 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build/classes/java/main/com/landvibe/landlog/controller/MemberController.class b/build/classes/java/main/com/landvibe/landlog/controller/MemberController.class index 6d0737d..c0e2e36 100644 Binary files a/build/classes/java/main/com/landvibe/landlog/controller/MemberController.class and b/build/classes/java/main/com/landvibe/landlog/controller/MemberController.class differ diff --git a/build/classes/java/main/com/landvibe/landlog/controller/MemberForm.class b/build/classes/java/main/com/landvibe/landlog/controller/MemberForm.class index 10f5ce3..be7e1d5 100644 Binary files a/build/classes/java/main/com/landvibe/landlog/controller/MemberForm.class and b/build/classes/java/main/com/landvibe/landlog/controller/MemberForm.class differ diff --git a/build/classes/java/main/com/landvibe/landlog/domain/Member.class b/build/classes/java/main/com/landvibe/landlog/domain/Member.class index 7b2fa53..7a00778 100644 Binary files a/build/classes/java/main/com/landvibe/landlog/domain/Member.class and b/build/classes/java/main/com/landvibe/landlog/domain/Member.class differ diff --git a/build/classes/java/main/com/landvibe/landlog/repository/MemberRepository.class b/build/classes/java/main/com/landvibe/landlog/repository/MemberRepository.class index e0954e0..f0c280e 100644 Binary files a/build/classes/java/main/com/landvibe/landlog/repository/MemberRepository.class and b/build/classes/java/main/com/landvibe/landlog/repository/MemberRepository.class differ diff --git a/build/classes/java/main/com/landvibe/landlog/repository/MemoryMemberRepository.class b/build/classes/java/main/com/landvibe/landlog/repository/MemoryMemberRepository.class index ca2c90e..aeb2d62 100644 Binary files a/build/classes/java/main/com/landvibe/landlog/repository/MemoryMemberRepository.class and b/build/classes/java/main/com/landvibe/landlog/repository/MemoryMemberRepository.class differ diff --git a/build/classes/java/main/com/landvibe/landlog/service/MemberService.class b/build/classes/java/main/com/landvibe/landlog/service/MemberService.class index 4020fe9..618397e 100644 Binary files a/build/classes/java/main/com/landvibe/landlog/service/MemberService.class and b/build/classes/java/main/com/landvibe/landlog/service/MemberService.class differ diff --git a/build/resources/main/templates/blogList.html b/build/resources/main/templates/blogList.html new file mode 100644 index 0000000..22634db --- /dev/null +++ b/build/resources/main/templates/blogList.html @@ -0,0 +1,11 @@ + + + +
+ +
+

의 블로그

+
+
+ + \ No newline at end of file diff --git a/build/resources/main/templates/home.html b/build/resources/main/templates/home.html index 109d59d..15a4e6f 100644 --- a/build/resources/main/templates/home.html +++ b/build/resources/main/templates/home.html @@ -6,6 +6,7 @@

Hello Spring

회원 기능

+ 로그인 회원 가입 회원 목록

diff --git a/build/resources/main/templates/members/createMemberForm.html b/build/resources/main/templates/members/createMemberForm.html index c0353f2..676e04e 100644 --- a/build/resources/main/templates/members/createMemberForm.html +++ b/build/resources/main/templates/members/createMemberForm.html @@ -2,10 +2,16 @@
-
+
+
+ + +
+ +
diff --git a/build/resources/main/templates/members/loginForm.html b/build/resources/main/templates/members/loginForm.html new file mode 100644 index 0000000..380ab27 --- /dev/null +++ b/build/resources/main/templates/members/loginForm.html @@ -0,0 +1,17 @@ + + + +
+
+
+ + +
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/MemberController.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/MemberController.class.uniqueId0 new file mode 100644 index 0000000..57d985b Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/MemberController.class.uniqueId0 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/MemberService.class.uniqueId1 b/build/tmp/compileJava/compileTransaction/stash-dir/MemberService.class.uniqueId1 new file mode 100644 index 0000000..0e4242b Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/MemberService.class.uniqueId1 differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 1a81f91..9433f22 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/com/landvibe/landlog/controller/MemberController.java b/src/main/java/com/landvibe/landlog/controller/MemberController.java index dcc95a3..feb6535 100644 --- a/src/main/java/com/landvibe/landlog/controller/MemberController.java +++ b/src/main/java/com/landvibe/landlog/controller/MemberController.java @@ -6,8 +6,10 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; +import java.util.Optional; @Controller public class MemberController { @@ -20,12 +22,14 @@ public MemberController(MemberService memberService) { @GetMapping(value = "/members/new") public String createForm() { return "members/createMemberForm"; - } + } //회원가입 폼 반환 @PostMapping(value = "/members/new") - public String create(MemberForm form) { + public String create(MemberForm form) { //새로운 회원생성, 회원가입 후 메인 페이지로 리다이렉트 Member member = new Member(); member.setName(form.getName()); + member.setEmail(form.getEmail()); + member.setPwd(form.getPwd()); memberService.join(member); return "redirect:/"; } @@ -36,4 +40,33 @@ public String list(Model model) { model.addAttribute("members", members); return "members/memberList"; } + + @GetMapping(value = "/members/login") + public String loginForm() { + return "members/loginForm"; + } //로그인 폼 반환 + + //로그인 폼 요청처리 + @PostMapping(value = "/members/login") + public String login(@RequestParam String email, @RequestParam String pwd, Model model) { + try { + Member member = memberService.checkLogin(email, pwd); //로그인 성공여부 판단 + model.addAttribute("member", member); + Long creatorId = member.getId(); + return "redirect:/blogs?creatorId=" + creatorId; + } catch (IllegalArgumentException e) { + model.addAttribute("error", e.getMessage()); + return "redirect:/"; + } + } + + @GetMapping(value = "/blogs") + public String blogForm(@RequestParam Long creatorId, Model model) { + Optional member = memberService.findOne(creatorId); + model.addAttribute("creatorId", creatorId); + Member member1 = member.get(); //'Member' 객체를 가져옴 + model.addAttribute("name", member1.getName()); //여기서 넘겨줘야 blogList.html에서 사용가능 + return "blogList"; + } + } diff --git a/src/main/java/com/landvibe/landlog/controller/MemberForm.java b/src/main/java/com/landvibe/landlog/controller/MemberForm.java index 32d7a01..87bed17 100644 --- a/src/main/java/com/landvibe/landlog/controller/MemberForm.java +++ b/src/main/java/com/landvibe/landlog/controller/MemberForm.java @@ -2,6 +2,8 @@ public class MemberForm { private String name; + private String email; + private String pwd; public String getName() { return name; @@ -10,4 +12,21 @@ public String getName() { public void setName(String name) { this.name = name; } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPwd() { + return pwd; + } + + public void setPwd(String pwd) { + this.pwd = pwd; + } + } diff --git a/src/main/java/com/landvibe/landlog/domain/Member.java b/src/main/java/com/landvibe/landlog/domain/Member.java index acadd35..d3594b1 100644 --- a/src/main/java/com/landvibe/landlog/domain/Member.java +++ b/src/main/java/com/landvibe/landlog/domain/Member.java @@ -4,13 +4,17 @@ public class Member { private Long id; private String name; + private String email; + private String pwd; public Member() { } - public Member(Long id, String name) { + public Member(Long id, String name, String email, String pwd) { this.id = id; this.name = name; + this.email = email; + this.pwd = pwd; } public Long getId() { @@ -28,4 +32,20 @@ public String getName() { public void setName(String name) { this.name = name; } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPwd() { + return pwd; + } + + public void setPwd(String pwd) { + this.pwd = pwd; + } } diff --git a/src/main/java/com/landvibe/landlog/repository/MemberRepository.java b/src/main/java/com/landvibe/landlog/repository/MemberRepository.java index 0034fe9..714c4cd 100644 --- a/src/main/java/com/landvibe/landlog/repository/MemberRepository.java +++ b/src/main/java/com/landvibe/landlog/repository/MemberRepository.java @@ -13,5 +13,9 @@ public interface MemberRepository { Optional findByName(String name); + Optional findByEmail(String email); + + Optional findByPwd(String pwd); + List findAll(); } diff --git a/src/main/java/com/landvibe/landlog/repository/MemoryMemberRepository.java b/src/main/java/com/landvibe/landlog/repository/MemoryMemberRepository.java index d84e250..994b363 100644 --- a/src/main/java/com/landvibe/landlog/repository/MemoryMemberRepository.java +++ b/src/main/java/com/landvibe/landlog/repository/MemoryMemberRepository.java @@ -30,6 +30,20 @@ public Optional findByName(String name) { .findAny(); } + @Override + public Optional findByEmail(String email) { + return store.values().stream() + .filter(member -> member.getEmail().equals(email)) + .findAny(); + } + + @Override + public Optional findByPwd(String pwd) { + return store.values().stream() + .filter(member -> member.getPwd().equals(pwd)) + .findAny(); + } + @Override public List findAll() { return new ArrayList<>(store.values()); diff --git a/src/main/java/com/landvibe/landlog/service/MemberService.java b/src/main/java/com/landvibe/landlog/service/MemberService.java index c4ac876..a2991c5 100644 --- a/src/main/java/com/landvibe/landlog/service/MemberService.java +++ b/src/main/java/com/landvibe/landlog/service/MemberService.java @@ -28,6 +28,13 @@ private void validateDuplicateMember(Member member) { }); } + //로그인 성공여부 판단 + public Member checkLogin(String email, String pwd) { + return memberRepository.findByEmail(email) //먼저 이메일이 일치하는지 확인하고 + .filter(member -> member.getPwd().equals(pwd)) //그 중에서 비번 일치하는지 확인 + .orElseThrow(() -> new IllegalArgumentException("잘못된 이메일 또는 비밀번호입니다.")); + } + public List findMembers() { return memberRepository.findAll(); } diff --git a/src/main/resources/templates/blogList.html b/src/main/resources/templates/blogList.html new file mode 100644 index 0000000..d74467a --- /dev/null +++ b/src/main/resources/templates/blogList.html @@ -0,0 +1,30 @@ + + + +
+ +
+

의 블로그

+ 생성 +
+
+ + + + + + + + + + + + + + + +
#제목내용
+
+
+ + diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 109d59d..15a4e6f 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -6,6 +6,7 @@

Hello Spring

회원 기능

+ 로그인 회원 가입 회원 목록

diff --git a/src/main/resources/templates/members/createMemberForm.html b/src/main/resources/templates/members/createMemberForm.html index c0353f2..676e04e 100644 --- a/src/main/resources/templates/members/createMemberForm.html +++ b/src/main/resources/templates/members/createMemberForm.html @@ -2,10 +2,16 @@
-
+
+
+ + +
+ +
diff --git a/src/main/resources/templates/members/loginForm.html b/src/main/resources/templates/members/loginForm.html new file mode 100644 index 0000000..380ab27 --- /dev/null +++ b/src/main/resources/templates/members/loginForm.html @@ -0,0 +1,17 @@ + + + +
+
+
+ + +
+ + +
+ +
+
+ + \ No newline at end of file