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