-
Notifications
You must be signed in to change notification settings - Fork 10
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주차 과제] 박해원 과제 제출합니다. #17
base: haewon
Are you sure you want to change the base?
Changes from 4 commits
1abbb19
2bd59ad
6b57613
0b7b5c4
556f7ea
722a89d
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#Thu Aug 15 22:04:20 KST 2024 | ||
gradle.version=7.6.1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE HTML> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<body> | ||
<div class="container"> | ||
<form action="/members/login" method="post"> | ||
|
||
<label for="email">이메일</label> | ||
<input type="email" id="email" name="email" placeholder="이메일을 입력하세요"> | ||
<br> | ||
<label for="password">비밀번호</label> | ||
<input type="password" id="password" name="password" placeholder="비밀번호를 입력하세요"> | ||
<br> | ||
|
||
<button type="submit">로그인</button> | ||
</form> | ||
</div> <!-- /container --> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -27,6 +29,8 @@ public String create(MemberForm form) { | |
Member member = new Member(); | ||
member.setName(form.getName()); | ||
memberService.join(member); | ||
member.setEmail(form.getEmail()); //추가 | ||
member.setPassword(form.getPassword()); | ||
return "redirect:/"; | ||
} | ||
|
||
|
@@ -36,4 +40,33 @@ public String list(Model model) { | |
model.addAttribute("members", members); | ||
return "members/memberList"; | ||
} | ||
//폼 데이터: 사용자가 HTML 폼을 통해 제출한 데이터, MemberForm은 사용자가 입력한 데이터를 담기위한 객체 | ||
//모델: 컨트롤러에서 처리된 결과를 뷰에 넘겨서 표시하기 위해 사용(사용자목록) | ||
@PostMapping(value = "/members/login") | ||
public String loginPost(MemberForm form, Model model){ | ||
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. 이메일로 사용자를 찾고 비밀번호가 일치한지 판단하는 로직은 비즈니스 로직입니다. |
||
String email = form.getEmail(); | ||
String password = form.getPassword(); | ||
Optional<Member> member = memberService.findByEmail(email); | ||
if(member.isPresent()){ //비번일치-> 블로그페이지, 불일치->홈 | ||
if(member.get().getPassword().equals(password)){ | ||
return "redirect:/blogs?creatorId="+member.get().getId(); | ||
} | ||
else{ | ||
return "redirect:/"; | ||
} | ||
} | ||
else{ | ||
return "redirect:/"; //로그인 실패 | ||
} | ||
} | ||
@GetMapping(value = "/members/login") | ||
public String login(){ | ||
return "members/loginForm"; | ||
} | ||
@GetMapping(value = "/blogs") | ||
public String blog(@RequestParam("creatorId")Long Id,Model model){ //url에 적힌값 복사해서 변수에 넣기 | ||
Optional<Member> member = memberService.findOne(Id); | ||
model.addAttribute("name",member.get().getName()); | ||
return "blogList"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
package com.landvibe.landlog.controller; | ||
|
||
public class MemberForm { | ||
public class MemberForm { // 게터세터추가 | ||
private String name; | ||
|
||
private String email; | ||
private String password; | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getEmail(){return email;} | ||
|
||
public void setEmail(String email){this.email = email;} | ||
|
||
public String getPassword(){return password;} | ||
|
||
public void setPassword(String password){this.password = password;} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,17 @@ public class Member { | |
|
||
private Long id; | ||
private String name; | ||
private String email; | ||
private String password; | ||
|
||
public Member() { | ||
} | ||
|
||
public Member(Long id, String name) { | ||
public Member(Long id, String name,String email, String password) { | ||
this.id = id; | ||
this.name = name; | ||
this.email = email; | ||
this.password = password; | ||
} | ||
|
||
public Long getId() { | ||
|
@@ -28,4 +32,20 @@ public String getName() { | |
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
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. 말했듯 최대한 setter를 지양하고 왜 setter를 지양하는지 찾아보세요!! |
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email){this.email=email;} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password){this.password=password;} | ||
|
||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ public interface MemberRepository { | |
|
||
Optional<Member> findById(Long id); | ||
|
||
Optional<Member> findByEmail(String email); | ||
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. 하하하 감사함니다 |
||
|
||
Optional<Member> findByName(String name); | ||
|
||
List<Member> findAll(); | ||
|
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE HTML> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<body> | ||
<div class="container"> | ||
<form action="/members/login" method="post"> | ||
|
||
<label for="email">이메일</label> | ||
<input type="email" id="email" name="email" placeholder="이메일을 입력하세요"> | ||
<br> | ||
<label for="password">비밀번호</label> | ||
<input type="password" id="password" name="password" placeholder="비밀번호를 입력하세요"> | ||
<br> | ||
|
||
<button type="submit">로그인</button> | ||
</form> | ||
</div> <!-- /container --> | ||
</body> | ||
</html> |
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.
setter를 지양하는게 어떨까요? 지금 상태로는 생성자만으로 충분히 요구사항을 지킬 수 있을것 같습니다!!