diff --git a/src/main/java/Service/AccountService.java b/src/main/java/Service/AccountService.java index 3244cbd..a32a423 100644 --- a/src/main/java/Service/AccountService.java +++ b/src/main/java/Service/AccountService.java @@ -3,18 +3,45 @@ import Model.Account; import DAO.AccountDAO; +import java.util.List; + public class AccountService { AccountDAO accountDAO; - public AccountService(){ + public AccountService() { accountDAO = new AccountDAO(); } - public AccountService(AccountDAO accountDAO){ + public AccountService(AccountDAO accountDAO) { this.accountDAO = accountDAO; } - public Account addAccount(Account account){ - return accountDAO.insertAccount(account); + public Account addAccount(Account account) { + String username = account.getUsername(); + String password = account.getPassword(); + return accountDAO.insertAccount(username, password); + } + + public boolean isValidCredentials(String username, String password) { + if (accountIsRegistered(username)) return false; + else if (username.isEmpty()) return false; + if (password.length() < 4) return false; + return true; + } + + public boolean accountIsRegistered(String username) { + if (accountDAO.findAccountByUsername(username) != null) return true; + return false; + } + + public Account login(String username, String password) { + Account registeredAccount = accountDAO.findAccountByUsername(username); + if (registeredAccount == null) return null; + if (!registeredAccount.getPassword().equals(password)) return null; + return registeredAccount; + } + + public List getAllAccounts() { + return accountDAO.getAllAccounts(); } }