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주차 과제] 서예원 과제 제출합니다. #11

Open
wants to merge 2 commits into
base: yewon
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 added .gradle/7.6.1/fileHashes/resourceHashesCache.bin
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 @@
#Sat Aug 17 21:59:44 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.

16 changes: 16 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.

7 changes: 7 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.
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
10 changes: 10 additions & 0 deletions build/resources/main/templates/members/blogList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!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>
10 changes: 8 additions & 2 deletions build/resources/main/templates/members/createMemberForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<form action="/members/new" method="post">
<form action="/members/login" 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="text" id="email" name="email" placeholder="이메일을 입력하세요">
<br>
<label for="password">패스워드</label>
<input type="text" id="password" name="password" placeholder="비밀번호를 입력하세요">
</div>
<button type="submit">등록</button>
<button type="submit">로그인</button>
</form>
</div> <!-- /container -->
</body>
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="text" id="email" name="email" placeholder="이메일을 입력하세요">
<br>
<label for="password">비밀번호</label>
<input type="text" id="password" name="password" placeholder="비밀번호를 입력하세요">
</div>
<button type="submit">로그인</button>
</form>
</div> <!-- /container -->
</body>
</html>
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
1 change: 1 addition & 0 deletions spring-summer-coding-shop
Submodule spring-summer-coding-shop added at 791030
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
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 {

private final MemberService memberService;

public MemberController(MemberService memberService) {
Expand All @@ -26,10 +29,43 @@ public String createForm() {
public String create(MemberForm form) {

Choose a reason for hiding this comment

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

service 클래스를 만들었네요~~ 사용자가 회원가입을 하는건 비즈니스 로직 아닐까요? Service를 만든김에 사용자 생성을 service 클래스에서 해보세요~~

Member member = new Member();
member.setName(form.getName());
member.setEmail(form.getEmail());
member.setPwd(form.getPwd());
memberService.join(member);
return "redirect:/";
}

@GetMapping(value = "/members/login")
public String loginForm() {
return "members/loginForm";
}

@PostMapping(value = "/members/login")
public String login(MemberForm form, Model model) {
String email = form.getEmail();
String pwd = form.getPwd();
Optional<Member> member = memberService.findByEmail(email);

if (member.isPresent()) {
model.addAttribute("member",member);
return "redirect:/blogs?creatorId=" + member.get().getId();
} else {
return "redirect:/";
}
}

@GetMapping(value = "/blogs")
public String blog(@RequestParam(name = "creatorId") Long creatorId, Model model) {
List<Member> member = memberService.findMembers();

if (member != null) {
model.addAttribute("member", member);
}

return "members/blogList";

}

@GetMapping(value = "/members")
public String list(Model model) {
List<Member> members = memberService.findMembers();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/landvibe/landlog/controller/MemberForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@ public String getName() {
public void setName(String name) {
this.name = name;
}

private String email;

private String pwd;

public String getEmail(){return email;}

public String getPwd(){return pwd;}

public void setEmail(String email){this.email=email;}

public void setPwd(String password ){this.pwd=pwd;}
}
28 changes: 25 additions & 3 deletions 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(){}

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,22 @@ 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,8 @@ public interface MemberRepository {

Optional<Member> findByName(String name);

Optional<Member> findByEmail(String email);


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

public Optional<Member> findByEmail(String email) {

Choose a reason for hiding this comment

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

emal이 중복된 사용자가 있으면 어떡하죠? findAny()는 너무 무책임한것 같습니다아

return store.values().stream()
.filter(member -> member.getEmail().equals(email))
.findAny();
}

public boolean validatePwd(Long id, String pwd) {
return store.get(id) != null && store.get(id).getPwd().equals(pwd);
}
@Override
public List<Member> findAll() {
return new ArrayList<>(store.values());
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/landvibe/landlog/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ private void validateDuplicateMember(Member member) {
});
}


public Optional<Member> findByEmail(String email) {

Choose a reason for hiding this comment

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

validateDuplicateMember를 보고 이메일 중복 검증을 추가해보세요~~

return memberRepository.findByEmail(email);
}



public Optional<Member> findById(Long memberId) {
return memberRepository.findById(memberId);
}


public List<Member> findMembers() {
return memberRepository.findAll();
}
Expand Down
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
10 changes: 10 additions & 0 deletions src/main/resources/templates/members/blogList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!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>
10 changes: 8 additions & 2 deletions src/main/resources/templates/members/createMemberForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<form action="/members/new" method="post">
<form action="/members/login" 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="text" id="email" name="email" placeholder="이메일을 입력하세요">
<br>
<label for="password">패스워드</label>
<input type="text" id="password" name="password" placeholder="비밀번호를 입력하세요">
</div>
<button type="submit">등록</button>
<button type="submit">로그인</button>
</form>
</div> <!-- /container -->
</body>
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="text" id="email" name="email" placeholder="이메일을 입력하세요">
<br>
<label for="password">비밀번호</label>
<input type="text" id="password" name="password" placeholder="비밀번호를 입력하세요">
</div>
<button type="submit">로그인</button>
</form>
</div> <!-- /container -->
</body>
</html>