Compare commits
1 Commits
6c24eba7bf
...
s-kikuchi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f9287765d |
0
kikuchi.txt
Normal file
0
kikuchi.txt
Normal file
@@ -1,25 +0,0 @@
|
|||||||
package com.example.demo.app.domain.model;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class UserModel {
|
|
||||||
|
|
||||||
private Long userId;
|
|
||||||
private String userName;
|
|
||||||
private String emailAddress;
|
|
||||||
private String password;
|
|
||||||
private Integer secretQuestionId;
|
|
||||||
private String secretAnswer;
|
|
||||||
private LocalDate brithDate;
|
|
||||||
private Integer saving;
|
|
||||||
private Integer annualIncome;
|
|
||||||
private Integer monthlyBudget;
|
|
||||||
private Integer goalId;
|
|
||||||
private Integer courseId;
|
|
||||||
private Integer deleteFlag;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.example.demo.app.domain.service;
|
|
||||||
|
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
|
||||||
|
|
||||||
public interface LoginService {
|
|
||||||
|
|
||||||
UserEntity login(String mailAddress, String password);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.example.demo.app.domain.service.impl;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import com.example.demo.app.domain.service.LoginService;
|
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
|
||||||
import com.example.demo.app.infra.repository.UserRepository;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class LoginServiceImpl implements LoginService {
|
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserEntity login(String mailAddress, String password) {
|
|
||||||
|
|
||||||
return userRepository.findByMailAddressAndPassword(
|
|
||||||
mailAddress,
|
|
||||||
password).orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
package com.example.demo.app.infra.entity;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.FetchType;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.JoinColumn;
|
|
||||||
import jakarta.persistence.ManyToOne;
|
|
||||||
import jakarta.persistence.OneToMany;
|
|
||||||
import jakarta.persistence.OneToOne;
|
|
||||||
import jakarta.persistence.Table;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "user_t")
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class UserEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@Column(name = "user_id")
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
@Column(name = "user_name", nullable = false)
|
|
||||||
private String userName;
|
|
||||||
|
|
||||||
@Column(name = "mail_address", nullable = false)
|
|
||||||
private String mailAddress;
|
|
||||||
|
|
||||||
@Column(name = "password", nullable = false)
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@Column(name = "secret_answer", nullable = false)
|
|
||||||
private String secretQuestionAnswer;
|
|
||||||
|
|
||||||
@Column(name = "birth_date", nullable = false)
|
|
||||||
private LocalDate birthDate;
|
|
||||||
|
|
||||||
@Column(name = "saving", nullable = false)
|
|
||||||
private Integer saving;
|
|
||||||
|
|
||||||
@Column(name = "annual_income", nullable = false)
|
|
||||||
private Integer annualIncome;
|
|
||||||
|
|
||||||
@Column(name = "monthly_budget", nullable = false)
|
|
||||||
private Integer monthlyBudget;
|
|
||||||
|
|
||||||
@Column(name = "delete_flag", nullable = false)
|
|
||||||
private Integer deleteFlag;
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "userEntity")
|
|
||||||
private List<TransactionEntity> transactionEntityList;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "secret_question_id")
|
|
||||||
private QuestionEntity questionEntity;
|
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "goal_id")
|
|
||||||
private GoalEntity goalEntity;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "course_id")
|
|
||||||
private CourseEntity courseEntity;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.example.demo.app.infra.repository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
|
||||||
|
|
||||||
Optional<UserEntity> findByMailAddressAndPassword(String mailAddress, String password);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package com.example.demo.app.presentation.controller;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
|
|
||||||
import com.example.demo.app.domain.service.LoginService;
|
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
|
||||||
import com.example.demo.app.presentation.form.LoginForm;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class LoginController {
|
|
||||||
|
|
||||||
private final LoginService loginService;
|
|
||||||
|
|
||||||
@GetMapping("/login")
|
|
||||||
public String showLogin(Model model) {
|
|
||||||
|
|
||||||
model.addAttribute(
|
|
||||||
"loginForm",
|
|
||||||
new LoginForm());
|
|
||||||
|
|
||||||
return "login";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/login")
|
|
||||||
public String login(
|
|
||||||
@ModelAttribute LoginForm loginForm,
|
|
||||||
Model model, HttpSession session) {
|
|
||||||
|
|
||||||
UserEntity loginUser = loginService.login(
|
|
||||||
loginForm.getMailAddress(),
|
|
||||||
loginForm.getPassword());
|
|
||||||
|
|
||||||
if (loginUser == null) {
|
|
||||||
model.addAttribute(
|
|
||||||
"errorMessage",
|
|
||||||
"Email address or password is incorrect.");
|
|
||||||
|
|
||||||
return "login";
|
|
||||||
}
|
|
||||||
|
|
||||||
session.setAttribute("loginUser", loginUser);
|
|
||||||
|
|
||||||
return "menu";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.example.demo.app.presentation.form;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class LoginForm {
|
|
||||||
|
|
||||||
private String mailAddress;
|
|
||||||
private String password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ja"xmlns:th="http://www.thymeleaf.org">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>ログイン</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<header></header>
|
|
||||||
|
|
||||||
<main>
|
|
||||||
<h1>ログイン</h1>
|
|
||||||
|
|
||||||
<div th:if="${errorMessage}" th:text="${errorMessage}"></div>
|
|
||||||
<form th:action="@{/login}" th:object="${loginForm}" method="post">
|
|
||||||
<div>
|
|
||||||
<label for="emailAddress">メールアドレス</label>
|
|
||||||
|
|
||||||
<input type="email"
|
|
||||||
id="emailAddress"
|
|
||||||
th:field="{emailAddress}"
|
|
||||||
required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label for="password">パスワード</label>
|
|
||||||
|
|
||||||
<input type="password"
|
|
||||||
id="password"
|
|
||||||
th:field="{password}"
|
|
||||||
required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<button type="submit">ログイン</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<a href="@{user/register}">新規会員登録</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<a href="@{password/authentication}">パスワードを忘れた方</a>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user