|
|
@ -1,5 +1,7 @@ |
|
|
|
package hs.fulda.de.ci.exam.project; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
public class AccountService { |
|
|
|
private final AccountRepository accountRepository; |
|
|
|
private final PasswordEncoder passwordEncoder; |
|
|
@ -21,4 +23,23 @@ public class AccountService { |
|
|
|
String encodedPassword = passwordEncoder.encode(password); |
|
|
|
return encodedPassword.equals(account.getPasswordHash()); |
|
|
|
} |
|
|
|
public void validateAccount(Account account){ |
|
|
|
account.validateAccountStatus(); |
|
|
|
account.validateId(); |
|
|
|
account.validatePassword(); |
|
|
|
} |
|
|
|
|
|
|
|
public void checkIfAccountAlreadyExist(Account account){ |
|
|
|
if(accountRepository.checkIfAccountAlreadyExist(account)){ |
|
|
|
throw new RuntimeException("Account Already Exists"); |
|
|
|
} |
|
|
|
} |
|
|
|
public void createAccount(String id, String password, Account.AccountStatus accountStatus){ |
|
|
|
Account account = new Account(id, password, accountStatus); |
|
|
|
validateAccount(account); |
|
|
|
checkIfAccountAlreadyExist(account); |
|
|
|
accountRepository.save(account); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |