示例#1
0
文件: members.java 项目: ronsch/barks
  /*
   * Open screen which shows own barks
   */
  private void openOwnBarkScreen(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // get list of own barks
    memberModel mM = new memberModel();
    // TweetModel tM = new TweetModel();
    mM.setCluster(cluster);
    // tM.setCluster(cluster);
    ownBarks = new LinkedList<TweetStore>(); // empty list to avoid duplications
    ownBarks = mM.getOwnBarks(currentUserName);

    RequestDispatcher rd = request.getRequestDispatcher("ownBarks.jsp");
    request.setAttribute("username", currentUserName); // Set a bean with the username in it
    request.setAttribute("ownBarks", ownBarks); // Set a bean with the username in it

    rd.forward(request, response);
  }
示例#2
0
文件: members.java 项目: ronsch/barks
  private void openMemberHome(
      HttpServletRequest request, HttpServletResponse response, String userName)
      throws ServletException, IOException {
    memberModel mM = new memberModel();
    mM.setCluster(cluster);

    currentUserName = userName; // get username
    userloggedIn = true;
    currentUserEmailAddress =
        request.getParameter("emailAddress"); // save current users email locally

    userList = new LinkedList<usersStore>(); // empty userlist

    // check if there was a user search involved
    if (request.getParameter("searchUsernameUser") != null) {
      String searchterm =
          request
              .getParameter("searchUsernameUser")
              .toLowerCase(); // get requested username, but lower case
      if (!searchterm.equals("")) { // there is a value
        userList = mM.getUsers(searchterm, currentUserName);
      } else { // valueless search
        userList = mM.getUsers("|", currentUserName);
      }
    }

    barks = new LinkedList<TweetStore>(); // final list (empty it)
    LinkedList<TweetStore> tempStore =
        new LinkedList<TweetStore>(); // temp list to be added to final list
    LinkedList<String> followers =
        new LinkedList<String>(); // will hold the names of users this user follows
    followers = mM.getFollowers(userName); // pass username to find followed users

    // print barks from followed members
    for (String followed : followers) {
      // System.out.println("followed user: "******"followedBarks", barks); // Set a bean with the list in it
    request.setAttribute("username", currentUserName); // Set a bean with the username in it
    request.setAttribute("memberList", userList); // Set a bean with the list in it
    request.setAttribute(
        "emailAddress", currentUserEmailAddress); // Set a bean with the email address in it

    RequestDispatcher rd = request.getRequestDispatcher("members.jsp");
    rd.forward(request, response);
  }
示例#3
0
文件: members.java 项目: ronsch/barks
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) gets the
   *     tweet from the jsp page, from the user and sends it on to the tweetmodel where it is stored
   *     in the db gets the login data from the login screen and directs it to the login procedure
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    memberModel mM = new memberModel();
    mM.setCluster(cluster);
    request.setAttribute("userloggedIn", userloggedIn); // set bean whether user is logged in or not

    if (request.getParameter("logMeIn") != null) { // login a user
      String isLogin =
          mM.login(request.getParameter("emailAddress"), request.getParameter("password"));
      if (isLogin != null) {
        openMemberHome(request, response, isLogin); // open members page
      } else {
        request.setAttribute("warningMessage", "username or password are incorrect");
        openLoginScreen(request, response); // back to login screen
      }
    } else if (request.getParameter("NewEmailAddress") != null
        && request.getParameter("userName") != null
        && request.getParameter("NewPassword") != null
        && request.getParameter("RepeatPassword") != null) { // if a new user is to be created
      String warningMessage = ""; // the message the user gets displayed
      boolean success = false;
      if (request
          .getParameter("NewPassword")
          .equals(request.getParameter("RepeatPassword"))) { // add user data to db
        success =
            mM.newUser(
                request.getParameter("NewEmailAddress"),
                request.getParameter("userName"),
                request.getParameter("RepeatPassword"));
      } else {
        warningMessage = "The passwords did not match";
      }

      if (success) // if the user was added successfully
      {
        warningMessage = "Your account has been created!";
        request.setAttribute(
            "warningMessage", warningMessage); // set bean whether user is logged in or not

        openMemberHome(request, response, request.getParameter("userName")); // open members page
      } else {
        if (warningMessage.equals("")) { // some other problem occured
          warningMessage = "Maybe your email/username combination exists already?";
        } else {
          // the message is already statingthat passwords are not alike, leave it that way
        }
        request.setAttribute("warningMessage", warningMessage);
        openRegisterScreen(request, response); // open register page again
      }
    } else if (request.getParameter("insertNewBark") != null
        && request.getParameter("name") != null
        && request.getParameter("bark") != null) { // post a new bark
      System.out.println("Add tweet");
      mM.addBark(request.getParameter("name"), request.getParameter("bark"));

      request.setAttribute("followedBarks", barks); // Set a bean with the list in it
      request.setAttribute("username", currentUserName); // Set a bean with the username in it
      request.setAttribute("memberList", userList); // Set a bean with the list in it
      request.setAttribute(
          "emailAddress", currentUserEmailAddress); // Set a bean with the email address in it

      openOwnBarkScreen(request, response);
    } else if (request.getParameter("searchUsernameUser")
        != null) // if the request is to search for a user, by a user
    {
      openMemberHome(request, response, currentUserName);
    } else if (request.getParameter("followUser")
        != null) { // if a user wants to follow another user
      if (userList != null) {
        String userToBefollowed = request.getParameter("followUser");
        int foo = Integer.parseInt(userToBefollowed); // find which bark to delete
        mM.followUser(currentUserName, userList.get(foo).getUsername()); // delete user
        openMemberHome(request, response, currentUserName);
      } else {
        openMemberHome(request, response, currentUserName);
      }
    } else if (request.getParameter("logOff") != null) // post
    { // log user off
      openLoginScreen(request, response);
    } // "viewOwnBarks"
    else if (request.getParameter("changeUserPassword") != null) { // change the password
      boolean success = false;
      String warningMessage = "";
      if (request
          .getParameter("NewUserPassword")
          .equals(request.getParameter("RepeatUserPassword"))) { // change password in db
        // will return false if old password did not match
        success =
            mM.changePassword(
                request.getParameter("oldPassword"),
                request.getParameter("NewUserPassword"),
                currentUserName,
                currentUserEmailAddress);
      } else {
        warningMessage = "The new passwords did not match";
      }

      if (success) // if the password was changed successfully
      {
        warningMessage = "Your Password has been changed";
      } else {
        if (warningMessage.equals(
            "")) { // some other problem occured - probably incorrect old password
          warningMessage = "Was the old password correct?";
        }
      }
    } else if (request.getParameter("deleteUser") != null) // if delete user was requested
    {
      // deleteUser
      System.out.println("Delete user: "******"deleteUser"));

      String userToBeDeleted = request.getParameter("deleteUser");
      int foo = Integer.parseInt(userToBeDeleted); // find which bark to delete
      mM.deleteUser(
          userList.get(foo).getEmail(),
          userList.get(foo).getUsername()); // delete user in list at foo
      openMemberHome(request, response, currentUserName);
    } else if (request.getParameter("unfollowUser") != null) // if a user needs to be unfollowed
    { // unfollowUser - delete follower entry
      String userToBeUnfollowed = request.getParameter("unfollowThisUser");
      System.out.println("Your name: " + currentUserName);
      System.out.println("unfollow this user: "******"deleteBark") != null) // if the request is to delete a own bark
    {
      System.out.println("Delete Bark");
      String barkToBeDeleted = request.getParameter("deleteBark");
      int foo = Integer.parseInt(barkToBeDeleted); // find which bark to delete
      mM.deleteBark(
          ownBarks.get(foo).getUUID().toString(),
          ownBarks.get(foo).getUser().toString()); // delete bark
      openOwnBarkScreen(request, response);
    } else { // if nothing was selected or there was some problem - go to login screen
      openLoginScreen(request, response);
    }
  }