[EDIT] 会員登録・ログインにパスワード暗号化機能を追加しました。
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user