Skip to content
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

[6주차 과제] 박지현 과제 제출합니다. #10

Open
wants to merge 4 commits into
base: jihyun
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .gradle/7.6.1/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/7.6.1/checksums/md5-checksums.bin
Binary file not shown.
Binary file added .gradle/7.6.1/checksums/sha1-checksums.bin
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added .gradle/7.6.1/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/7.6.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added .gradle/7.6.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file not shown.
Empty file added .gradle/7.6.1/gc.properties
Empty file.
Binary file added .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 2 additions & 0 deletions .gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Sun Aug 18 21:14:11 KST 2024
gradle.version=7.6.1
Binary file added .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file added .gradle/file-system.probe
Binary file not shown.
Empty file added .gradle/vcs-1/gc.properties
Empty file.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file modified build/classes/java/main/com/landvibe/landlog/domain/Member.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions build/resources/main/templates/blogList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<!--블로그 폼-->
<div>
<h1><span th:text="${name}"/>의 블로그</h1>
</div>
</div> <!-- /container -->
</body>
</html>
1 change: 1 addition & 0 deletions build/resources/main/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<h1>Hello Spring</h1>
<p>회원 기능</p>
<p>
<a href="/members/login">로그인</a>
<a href="/members/new">회원 가입</a>
<a href="/members">회원 목록</a>
</p>
Expand Down
8 changes: 7 additions & 1 deletion build/resources/main/templates/members/createMemberForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<form action="/members/new" method="post">
<form action="/members/new" method="post"> <!--회원가입 폼-->
<div class="form-group">
<label for="name">이름</label>
<input type="text" id="name" name="name" placeholder="이름을 입력하세요">
<br>
<label for="email">이메일</label>
<input type="email" id="email" name="email" placeholder="이메일을 입력하세요">
<br>
<label for="pwd">패스워드</label>
<input type="password" id="pwd" name="pwd" placeholder="비밀번호를 입력하세요">
</div>
<button type="submit">등록</button>
</form>
Expand Down
17 changes: 17 additions & 0 deletions build/resources/main/templates/members/loginForm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<form action="/members/login" method="post"> <!--로그인 폼-->
<div class="form-group">
<label for="email">이메일</label>
<input type="email" id="email" name="email" placeholder="이메일을 입력하세요">
<br>
<label for="pwd">비밀번호</label>
<input type="password" id="pwd" name="pwd" placeholder="비밀번호를 입력하세요">
</div>
<button type="submit">로그인</button>
</form>
</div> <!-- /container -->
</body>
</html>
Binary file not shown.
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setter를 지양합시다!! 생성자로 충분할거 같아요!!

member.setEmail(form.getEmail());
member.setPwd(form.getPwd());
memberService.join(member);
return "redirect:/";
}
Expand All @@ -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> member = memberService.findOne(creatorId);
model.addAttribute("creatorId", creatorId);
Member member1 = member.get(); //'Member' 객체를 가져옴
model.addAttribute("name", member1.getName()); //여기서 넘겨줘야 blogList.html에서 사용가능
return "blogList";
}

}
19 changes: 19 additions & 0 deletions src/main/java/com/landvibe/landlog/controller/MemberForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class MemberForm {
private String name;
private String email;
private String pwd;

public String getName() {
return name;
Expand All @@ -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;
}

}
22 changes: 21 additions & 1 deletion src/main/java/com/landvibe/landlog/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ public interface MemberRepository {

Optional<Member> findByName(String name);

Optional<Member> findByEmail(String email);

Optional<Member> findByPwd(String pwd);

List<Member> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ public Optional<Member> findByName(String name) {
.findAny();
}

@Override
public Optional<Member> findByEmail(String email) {
return store.values().stream()
.filter(member -> member.getEmail().equals(email))
.findAny();
}

@Override
public Optional<Member> findByPwd(String pwd) {
return store.values().stream()
.filter(member -> member.getPwd().equals(pwd))
.findAny();
}

@Override
public List<Member> findAll() {
return new ArrayList<>(store.values());
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/landvibe/landlog/service/MemberService.java

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MemberService 만든김에 멤버 생성, 조회 등을 Service에서 처리해보세요!!!!

Original file line number Diff line number Diff line change
Expand Up @@ -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<Member> findMembers() {
return memberRepository.findAll();
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/templates/blogList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<!--블로그 폼-->
<div>
<h1><span th:text="${name}"/>의 블로그</h1>
</div>
</div> <!-- /container -->
</body>
</html>
1 change: 1 addition & 0 deletions src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<h1>Hello Spring</h1>
<p>회원 기능</p>
<p>
<a href="/members/login">로그인</a>
<a href="/members/new">회원 가입</a>
<a href="/members">회원 목록</a>
</p>
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/templates/members/createMemberForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<form action="/members/new" method="post">
<form action="/members/new" method="post"> <!--회원가입 폼-->
<div class="form-group">
<label for="name">이름</label>
<input type="text" id="name" name="name" placeholder="이름을 입력하세요">
<br>
<label for="email">이메일</label>
<input type="email" id="email" name="email" placeholder="이메일을 입력하세요">
<br>
<label for="pwd">패스워드</label>
<input type="password" id="pwd" name="pwd" placeholder="비밀번호를 입력하세요">
</div>
<button type="submit">등록</button>
</form>
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/templates/members/loginForm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<form action="/members/login" method="post"> <!--로그인 폼-->
<div class="form-group">
<label for="email">이메일</label>
<input type="email" id="email" name="email" placeholder="이메일을 입력하세요">
<br>
<label for="pwd">비밀번호</label>
<input type="password" id="pwd" name="pwd" placeholder="비밀번호를 입력하세요">
</div>
<button type="submit">로그인</button>
</form>
</div> <!-- /container -->
</body>
</html>