Beispiel #1
0
  /** GET /users/suggestions -> suggest users to follow */
  @RequestMapping(
      value = "/rest/users/suggestions",
      method = RequestMethod.GET,
      produces = "application/json")
  @ResponseBody
  public Collection<User> suggestions() {
    User currentUser = userService.getCurrentUser();
    final String login = currentUser.getLogin();
    if (log.isDebugEnabled()) {
      log.debug("REST request to get the last active tweeters list (except " + login + ").");
    }

    Collection<String> exceptions = userService.getFriendsForUser(login);
    exceptions.add(login);

    Collection<Tweet> tweets = timelineService.getDayline("");
    Map<String, User> users = new HashMap<String, User>();
    for (Tweet tweet : tweets) {
      if (exceptions.contains(tweet.getLogin())) continue;

      users.put(tweet.getLogin(), userService.getUserProfileByLogin(tweet.getLogin()));
      if (users.size() == 3) break; // suggestions list limit
    }
    return users.values();
  }
  @RequestMapping(value = "/account/groups/edit/removeMember", method = RequestMethod.POST)
  public ModelAndView removeMembership(
      @RequestParam String groupId, @RequestParam String username) {

    Collection<Group> groups = groupService.getGroupsWhereCurrentUserIsAdmin();
    Group currentGroup = null;
    for (Group group : groups) {
      if (group.getGroupId().equals(groupId)) {
        currentGroup = group;
        break;
      }
    }
    if (currentGroup == null) {
      return reinitializePage();
    }
    User memberToRemove = userService.getUserByUsername(username);
    if (memberToRemove == null) {
      return new ModelAndView(
          "redirect:/tatami/account/groups/edit?wrongUser=true&groupId="
              + currentGroup.getGroupId());
    }
    groupService.removeMemberFromGroup(memberToRemove, currentGroup);
    return new ModelAndView(
        "redirect:/tatami/account/groups/edit?memberRemove=true&groupId="
            + currentGroup.getGroupId());
  }
 /** Common code for all "GET" requests. */
 private ModelAndView basicModelAndView() {
   ModelAndView mv = new ModelAndView();
   User currentUser = authenticationService.getCurrentUser();
   User user = userService.getUserByLogin(currentUser.getLogin());
   mv.addObject("user", user);
   mv.addObject("group", new Group());
   return mv;
 }
Beispiel #4
0
 @RequestMapping(value = "/register", method = RequestMethod.POST)
 public String register(@RequestParam String email) {
   log.debug("Registration page");
   // TODO validate email
   User user = new User();
   user.setLogin(email);
   userService.registerUser(user);
   return "redirect:/tatami/login";
 }
Beispiel #5
0
 // TODO
 @RequestMapping(value = "/profile/{login}", method = RequestMethod.GET)
 @ResponseBody
 public ModelAndView getUserProfile(@PathVariable("login") String login) {
   if (log.isDebugEnabled()) {
     log.debug("Request to get Profile : " + login);
   }
   ModelAndView mav = new ModelAndView();
   mav.setViewName("profile");
   User user = userService.getUserProfileByLogin(login);
   if (null != user) {
     mav.addObject("user", user);
     mav.addObject("followed", userService.isFollowed(login));
     mav.addObject("nbTweets", counterService.getNbTweets(login));
     mav.addObject("nbFollowed", counterService.getNbFollowed(login));
     mav.addObject("nbFollowers", counterService.getNbFollowers(login));
   }
   return mav;
 }
Beispiel #6
0
 /** GET /users/show?screen_name=jdubois -> get the "jdubois" user */
 @RequestMapping(
     value = "/rest/users/show",
     method = RequestMethod.GET,
     produces = "application/json")
 @ResponseBody
 public User getUser(@RequestParam("screen_name") String login) {
   if (log.isDebugEnabled()) {
     log.debug("REST request to get Profile : " + login);
   }
   User user = userService.getUserProfileByLogin(login);
   return user;
 }
 @Override
 public UserDetails loadUserByUsername(final String login) throws UsernameNotFoundException {
   log.debug("Authenticating {} with Cassandra", login);
   String lowercaseLogin = login.toLowerCase();
   User userFromCassandra = userService.getUserByLogin(lowercaseLogin);
   if (userFromCassandra == null) {
     throw new UsernameNotFoundException("User " + lowercaseLogin + " was not found in Cassandra");
   } else if (userFromCassandra.getActivated() != null
       && userFromCassandra.getActivated() == false) {
     throw new UsernameNotFoundException(
         "User " + lowercaseLogin + " is deactivated. Contact administrator for further details.");
   }
   return getTatamiUserDetails(lowercaseLogin, userFromCassandra.getPassword());
 }
  @RequestMapping(value = "/account/groups/edit/addMember", method = RequestMethod.POST)
  public ModelAndView addMembership(
      @ModelAttribute("userGroupMembership") UserGroupMembership userGroupMembership) {

    if (log.isDebugEnabled()) {
      log.debug("Managing group membership for : " + userGroupMembership);
    }
    String groupId = userGroupMembership.getGroupId();
    if (groupId == null || groupId.equals("")) {
      return reinitializePage();
    }
    Collection<Group> groups = groupService.getGroupsWhereCurrentUserIsAdmin();
    Group currentGroup = null;
    for (Group group : groups) {
      if (group.getGroupId().equals(groupId)) {
        currentGroup = group;
        break;
      }
    }
    if (currentGroup == null) {
      return reinitializePage();
    }
    String username = userGroupMembership.getUsername();
    if (username == null || username.equals("")) {
      return new ModelAndView(
          "redirect:/tatami/account/groups/edit?noUser=true&groupId=" + currentGroup.getGroupId());
    }
    User newMember = userService.getUserByUsername(username);
    if (newMember == null) {
      return new ModelAndView(
          "redirect:/tatami/account/groups/edit?wrongUser=true&groupId="
              + currentGroup.getGroupId());
    }
    groupService.addMemberToGroup(newMember, currentGroup);
    return new ModelAndView(
        "redirect:/tatami/account/groups/edit?memberAdd=true&groupId=" + currentGroup.getGroupId());
  }