Examples of CaprabankException


Examples of org.goat.caprabank.shared.CaprabankException

    validateNotEmpty(username, "username");
    validateNotEmpty(password, "password");
    User user = dataStore.findUserByUsername(username);
    if (user == null || !Arrays.equals(user.passwordHash, hash(password))) {
      log.warning("Failed login attempt: " + username + "/" + password + ": " + (user == null ? "user not found." : "incorrect password."));
      throw new CaprabankException("Login failed - incorrect username or password.");
    }
    log.info("Logged in user " + username + ".");
    fillDetails(user);
    setCurrentUser(user);
    return user;
View Full Code Here

Examples of org.goat.caprabank.shared.CaprabankException

  @Override
  public User register(String firstName, String lastName, String email, String username, String password) throws CaprabankException {
    if (dataStore.countUsers() > USER_LIMIT) {
      log.warning("Failed registration attempt - user count exceeded.");
      throw new CaprabankException("CapraBank is not accepting new customers at the moment.");
    }
    validateNotEmpty(firstName, "first name");
    validateNotEmpty(lastName, "last name");
    validateNotEmpty(email, "email");
    validateNotEmpty(username, "username");
    validateNotEmpty(password, "password");
    if (dataStore.findUserByUsername(username) != null) {
      log.warning("Failed registration attempt - username already exists: '" + username + ".");
      throw new CaprabankException("The username is already in use.");
    }
    User newUser = new User();
    newUser.accountNum = generateId();
    newUser.firstName = firstName;
    newUser.lastName = lastName;
View Full Code Here

Examples of org.goat.caprabank.shared.CaprabankException

  @Override
  public User transfer(long toAccount, long amount, String comment) throws CaprabankException {
    User currentUser = getCurrentUser();
    if (toAccount == currentUser.accountNum) {
      log.warning("Self-tranfer attempted by user " + currentUser.username + ".");
      throw new CaprabankException("Very funny... That's you.");
    }
    if (amount <= 0) {
      log.warning("Negative amount tranfer attempted by user " + currentUser.username + " (amount=" + formatAmount(amount) + ").");
      throw new CaprabankException("Very funny...");
    }
    User toUser = dataStore.findUserByAccountNum(toAccount);
    if (toUser == null) {
      log.warning("Tranfer to nonexistent account attempted by user " + currentUser.username + " (account=" + toAccount + ").");
      throw new CaprabankException("Account " + toAccount + " not found.");
    }

    if (!"admin".equals(currentUser.username)) {
      if (amount > currentUser.balance) {
        log.warning("Insufficient funds for tranfer attempted by user " + currentUser.username + " (amount=" + formatAmount(amount) + ", balance=" + formatAmount(currentUser.balance) + ").");
        throw new CaprabankException("Insufficient funds.");
      }
    }

    BankTransaction transferTransaction = new BankTransaction();
    transferTransaction.transactionId = generateId();
View Full Code Here

Examples of org.goat.caprabank.shared.CaprabankException

    HttpServletRequest request = getThreadLocalRequest();
    if (request != null) {
      currentUser = (User) request.getSession(true).getAttribute(SESSION_USER_KEY);
    }
    if (currentUser == null) {
      throw new CaprabankException("User not logged in.");
    }
    fillDetails(currentUser);
    return currentUser;
  }
View Full Code Here

Examples of org.goat.caprabank.shared.CaprabankException

    return String.format("%.2f", ((double) amount / 100));
  }

  private void validateNotEmpty(String value, String name) throws CaprabankException {
    if (value == null || value.trim().isEmpty()) {
      throw new CaprabankException("The " + name + " cannot be empty.");
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.