Compare commits
4 Commits
29749c444a
...
2b3cecf55d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b3cecf55d | ||
|
|
9872405377 | ||
|
|
b9742d87c0 | ||
|
|
cdc5ea21c7 |
5
pom.xml
5
pom.xml
@@ -83,6 +83,11 @@
|
|||||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mindrot</groupId>
|
||||||
|
<artifactId>jbcrypt</artifactId>
|
||||||
|
<version>0.4</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.example.demo.app.presentation.form.UserForm;
|
|||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
|
|
||||||
public void register(UserForm userForm, Long courseId, Long userId);
|
public void register(UserForm userForm, Long courseId);
|
||||||
|
|
||||||
public void updateCourse(Long userId, Long courseId);
|
public void updateCourse(Long userId, Long courseId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.demo.app.domain.service.impl;
|
package com.example.demo.app.domain.service.impl;
|
||||||
|
|
||||||
|
import org.mindrot.jbcrypt.BCrypt;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.LoginModel;
|
import com.example.demo.app.domain.model.LoginModel;
|
||||||
@@ -13,19 +14,26 @@ import lombok.RequiredArgsConstructor;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class LoginServiceImpl implements LoginService {
|
public class LoginServiceImpl implements LoginService {
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoginModel login(String mailAddress, String password) {
|
public LoginModel login(String mailAddress, String password) {
|
||||||
|
|
||||||
UserEntity userEntity = userRepository.findByMailAddressAndPassword(
|
UserEntity userEntity = userRepository
|
||||||
mailAddress,
|
.findByMailAddress(mailAddress)
|
||||||
password).orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
if (userEntity == null) {
|
if (userEntity == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isValidPassword = BCrypt.checkpw(password, userEntity.getPassword());
|
||||||
|
|
||||||
|
if (!isValidPassword) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LoginModel(userEntity.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
return new LoginModel(userEntity.getUserId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.demo.app.domain.service.impl;
|
package com.example.demo.app.domain.service.impl;
|
||||||
|
|
||||||
|
import org.mindrot.jbcrypt.BCrypt;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.UserModel;
|
import com.example.demo.app.domain.model.UserModel;
|
||||||
@@ -24,14 +25,17 @@ public class UserServiceImpl implements UserService {
|
|||||||
private final GoalRepository goalRepository;
|
private final GoalRepository goalRepository;
|
||||||
private final CourseRepository courseRepository;
|
private final CourseRepository courseRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(UserForm userForm, Long courseId, Long userId) {
|
public void register(UserForm userForm, Long courseId) {
|
||||||
|
|
||||||
UserEntity userEntity = new UserEntity();
|
UserEntity userEntity = new UserEntity();
|
||||||
|
|
||||||
userEntity.setUserName(userForm.getUserName());
|
userEntity.setUserName(userForm.getUserName());
|
||||||
userEntity.setMailAddress(userForm.getMailAddress());
|
userEntity.setMailAddress(userForm.getMailAddress());
|
||||||
userEntity.setPassword(userForm.getPassword());
|
|
||||||
|
String passwordHashed = BCrypt.hashpw(userForm.getPassword(), BCrypt.gensalt());
|
||||||
|
|
||||||
|
userEntity.setPassword(passwordHashed);
|
||||||
userEntity.setSecretQuestionAnswer(userForm.getSecretAnswer());
|
userEntity.setSecretQuestionAnswer(userForm.getSecretAnswer());
|
||||||
userEntity.setBirthDate(userForm.getBirthDate());
|
userEntity.setBirthDate(userForm.getBirthDate());
|
||||||
userEntity.setSaving(userForm.getSaving());
|
userEntity.setSaving(userForm.getSaving());
|
||||||
@@ -44,7 +48,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
GoalEntity goalEntity = new GoalEntity();
|
GoalEntity goalEntity = new GoalEntity();
|
||||||
goalEntity.setTargetAmount(Integer.parseInt(String.valueOf(userForm.getGoalId())));
|
goalEntity.setTargetAmount(Integer.parseInt(String.valueOf(userForm.getGoalId())));
|
||||||
goalEntity.setUserEntity(userRepository.findById(userId).get());
|
|
||||||
|
|
||||||
CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);
|
CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);
|
||||||
|
|
||||||
|
|||||||
@@ -378,34 +378,24 @@ public class TransactionController {
|
|||||||
|
|
||||||
List<GoalForm> resultList = goalForm.stream().filter(goal -> goal.getGoalComplete() == 0)
|
List<GoalForm> resultList = goalForm.stream().filter(goal -> goal.getGoalComplete() == 0)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
GoalForm result = new GoalForm();
|
|
||||||
|
if (!resultList.isEmpty()) {
|
||||||
if (resultList.getFirst() != null) {
|
GoalForm result = resultList.getFirst();
|
||||||
result = resultList.getFirst();
|
|
||||||
model.addAttribute("achievementRate", result.getAchievementRate());
|
model.addAttribute("achievementRate", result.getAchievementRate());
|
||||||
|
|
||||||
model.addAttribute("currentAmount", result.getCurrentAmount());
|
model.addAttribute("currentAmount", result.getCurrentAmount());
|
||||||
|
|
||||||
model.addAttribute("targetAmount", result.getTargetAmount());
|
model.addAttribute("targetAmount", result.getTargetAmount());
|
||||||
|
|
||||||
model.addAttribute("saving", userForm.getSaving());
|
model.addAttribute("saving", userForm.getSaving());
|
||||||
|
|
||||||
model.addAttribute("deadline", result.getDeadline());
|
model.addAttribute("deadline", result.getDeadline());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
model.addAttribute("achievementRate", "目標を設定してください");
|
model.addAttribute("achievementRate", "目標を設定してください");
|
||||||
|
|
||||||
model.addAttribute("currentAmount", "目標を設定してください");
|
model.addAttribute("currentAmount", "目標を設定してください");
|
||||||
|
|
||||||
model.addAttribute("targetAmount", "目標を設定してください");
|
model.addAttribute("targetAmount", "目標を設定してください");
|
||||||
|
|
||||||
model.addAttribute("saving", userForm.getSaving());
|
model.addAttribute("saving", userForm.getSaving());
|
||||||
|
|
||||||
model.addAttribute("deadline", "目標を設定してください");
|
model.addAttribute("deadline", "目標を設定してください");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return "menu";
|
return "menu";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.LoginModel;
|
|
||||||
import com.example.demo.app.domain.service.CourseService;
|
import com.example.demo.app.domain.service.CourseService;
|
||||||
import com.example.demo.app.domain.service.QuestionService;
|
import com.example.demo.app.domain.service.QuestionService;
|
||||||
import com.example.demo.app.domain.service.UserService;
|
import com.example.demo.app.domain.service.UserService;
|
||||||
@@ -84,11 +83,9 @@ public class UserController {
|
|||||||
Model model,
|
Model model,
|
||||||
HttpSession session) {
|
HttpSession session) {
|
||||||
|
|
||||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
|
||||||
|
|
||||||
Long courseId = courseService.findByName((String) session.getAttribute("selectedCourseName"));
|
Long courseId = courseService.findByName((String) session.getAttribute("selectedCourseName"));
|
||||||
|
|
||||||
userService.register(userForm, courseId, loginUser.getUserId());
|
userService.register(userForm, courseId);
|
||||||
|
|
||||||
return "redirect:/login";
|
return "redirect:/login";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user