Package org.goat.caprabank.shared.entity

Examples of org.goat.caprabank.shared.entity.User


  @Override
  public User login(String username, String password) throws 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 + ".");
View Full Code Here


    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;
    newUser.email = email;
    newUser.username = username;
View Full Code Here

    return getCurrentUser();
  }

  @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.");
    }
View Full Code Here

    boolean loggedOut = false;
    HttpServletRequest request = getThreadLocalRequest();
    if (request != null) {
      HttpSession session = request.getSession();
      if (session != null) {
        User currentUser = (User) session.getAttribute(SESSION_USER_KEY);
        if (currentUser != null) {
          loggedOut = true;
          session.invalidate();
          log.info("Logged out user " + currentUser.username + ".");
        }
View Full Code Here

  }

  //////////////// Private helpers

  private User getCurrentUser() throws CaprabankException {
    User currentUser = null;
    HttpServletRequest request = getThreadLocalRequest();
    if (request != null) {
      currentUser = (User) request.getSession(true).getAttribute(SESSION_USER_KEY);
    }
    if (currentUser == null) {
View Full Code Here

TOP

Related Classes of org.goat.caprabank.shared.entity.User

Copyright © 2018 www.massapicom. 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.