[EDIT] 会員登録・ログインにパスワード暗号化機能を追加しました。
This commit is contained in:
@@ -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;
|
||||||
@@ -18,14 +19,21 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
@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;
|
||||||
@@ -25,13 +26,16 @@ public class UserServiceImpl implements UserService {
|
|||||||
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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user