/**
  * Checks if the current logged in account does not exceed the maximum amount of detentions a FREE
  * account should have
  *
  * @return true or false
  */
 public boolean doesFreeAccountNotHaveMaxDetentions() {
   loadLogin();
   if (currentLogin.getAccountType() == AccountType.Free
       && currentLogin.getDetentions().size() < MAX_DETENTIONS_FOR_FREE) {
     return true;
   }
   return currentLogin.getAccountType() != AccountType.Free;
 }
 /**
  * Will log the user into the web site using container managed security
  *
  * @return Will take the user to the Welcome page or will return the user back to the log in page
  *     with an error message
  */
 public String login() {
   FacesContext context = FacesContext.getCurrentInstance();
   HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
   try {
     // If the log in is successful..
     request.login(currentLogin.getUsername(), currentLogin.getPassword());
     return "welcome?faces-redirect=true";
   } catch (ServletException e) {
     // else...
     displayMessage("Username or password is incorrect!");
     return null;
   }
 }
  /**
   * Sends the current log in object to the EJB
   *
   * @return Will either return the user to the log in page (if creation was successful) OR will
   *     return user back to the register page with an error message
   * @throws NoSuchAlgorithmException This error is thrown if the password encryption fails
   */
  public String createUser() throws NoSuchAlgorithmException {
    if (!detentionTrackerBean.userExists(currentLogin.getUsername())) {
      // If new username does not already exists...

      detentionTrackerBean.createInitialLogin(currentLogin);
      return "login?faces-redirect=true";
    }
    // else if it does already exists...
    displayMessage(
        "Username already exists OR you have entered incorrect characters (letters & numbers only!)");
    return null;
  }
 /**
  * Checks if the current logged in account is a Premium account
  *
  * @return true or false
  */
 public boolean isPremiumAccount() {
   loadLogin();
   return currentLogin.getAccountType() == AccountType.Premium;
 }
 /**
  * Checks if the current logged in account is a Premium account with a valid customer token
  *
  * @return true or false
  */
 public boolean isPremiumAccountWithToken() {
   loadLogin();
   return currentLogin.getAccountType() == AccountType.Premium && currentLogin.getToken() != null;
 }
 /**
  * Checks if the current logged in account has a token and is not a FREE account
  *
  * @return true or false
  */
 public boolean doesHaveTokenAndValidAccount() {
   loadLogin();
   return !(currentLogin.getToken() == null
       && !"Free".equals(currentLogin.getAccountType().toString()));
 }
 /**
  * Returns the account type of the current logged in user
  *
  * @return Account type
  */
 public String returnCurrentAccount() {
   loadLogin();
   return currentLogin.getAccountType().toString();
 }
 /**
  * Returns the customer token of the current logged in user
  *
  * @return Customer token
  */
 public String returnCurrentToken() {
   loadLogin();
   return currentLogin.getToken();
 }