Package com.simpletwitter.models

Examples of com.simpletwitter.models.TwitterUser


public class Authenticator {

  public static TwitterUser isValid(HttpServletRequest request) {
    HttpSession session = request.getSession();
    TwitterUser currUser = (TwitterUser) session
        .getAttribute("twitteruser");
    return currUser;
  }
View Full Code Here


        .getAttribute("twitteruser");
    return currUser;
  }

  public static void loginFailed(ModelAndView mv, String errorMsg) {
    TwitterUser tuser = new TwitterUser();
    mv.addObject("TwitterUser", tuser);
    if (errorMsg != null) {
      mv.addObject("errormsg", errorMsg);
    }
    mv.setViewName("loginorregister");
View Full Code Here

    if ("".equals(username) && "".equals(password)) {
      return null;
    }

    DatabaseManager da = DatabaseManager.getInstance();
    TwitterUser exm = new TwitterUser();
    exm.setUsername(tuser.getUsername());
    TwitterUser objectByExample = da.getObjectByExample(exm);
    if (objectByExample != null) {
      String expectedPassword = objectByExample.getPassword();
      if (validate(password, expectedPassword)) {
        return objectByExample;
      } else {
        return null;
      }
View Full Code Here

  }

  private static TwitterUser createNewUser(TwitterUser tuser) {
    DatabaseManager da = DatabaseManager.getInstance();
    tuser.setDateCreated(new Date());
    TwitterUser createObject = da.createObject(tuser);
    return createObject;
  }
View Full Code Here

    return result;
  }

  public static Map<String, Integer> getFollowCount(Long objId) {
    DatabaseManager da = DatabaseManager.getInstance();
    TwitterUser tuser = da.getObject(TwitterUser.class, objId);
    int followers = tuser.getFollowers().size();
    int following = tuser.getFollowing().size();
    Map<String, Integer> followCountMap = new HashMap<String, Integer>();
    followCountMap.put("followers", followers);
    followCountMap.put("following", following);
    return followCountMap;
  }
View Full Code Here

    return followCountMap;
  }

  public static TwitterUser getUser(Long ObjId) {
    DatabaseManager da = DatabaseManager.getInstance();
    TwitterUser tuser = da.getObject(TwitterUser.class, ObjId);
    return tuser;
  }
View Full Code Here

  protected final Log logger = LogFactory.getLog(getClass());

  @RequestMapping(value = "/welcome.html", method = RequestMethod.GET)
  public ModelAndView handleRequest() throws Exception {
    ModelAndView mv = new ModelAndView();
    TwitterUser tuser = new TwitterUser();
    mv.addObject("TwitterUser", tuser);
    mv.setViewName("loginorregister");
    return mv;
  }
View Full Code Here

  @RequestMapping(method = RequestMethod.GET)
  public ModelAndView logout(HttpServletRequest request) {
    HttpSession session = request.getSession();
    session.invalidate();
    ModelAndView mv = new ModelAndView();
    TwitterUser tuser = new TwitterUser();
    mv.addObject("TwitterUser", tuser);
    mv.setViewName("loginorregister");
    return mv;
  }
View Full Code Here

public class TweetController {

  @RequestMapping(value = "/tweet.html", method = RequestMethod.POST, params = "bean=tweet")
  public ModelAndView handleRequest(@ModelAttribute("tweet") Tweet tweet,
      HttpServletRequest request) throws Exception {
    TwitterUser currUser = Authenticator.isValid(request);
    ModelAndView mv = new ModelAndView();
    if (currUser != null) {
      if (tweet.getTweetMessage() != null
          && !"".equals(tweet.getTweetMessage())) {
        if (tweet.getTweetMessage().length() <= 100) {
          tweet.setDateCreated(new Date());
          tweet.setTwitterUser(currUser);
          TweetService.createTweet(tweet);
        } else {
          mv.addObject("tweetlengtherror",
              "Not more than 100 charcters are allowed");
        }
      }
      Set<Tweet> tweets = TweetService.getTweetStream(
          currUser.getObjId(), currUser.getFollowing());
      Set<TwitterUser> allUserList = TwitterUserService
          .getAllUserList(currUser);
      Map<String, Integer> followCount = TwitterUserService
          .getFollowCount(currUser.getObjId());
      int tweetCount = TwitterUserService.getTweetCount(currUser);
      Tweet eTweet = new Tweet();
      mv.addObject("tweet", eTweet);
      mv.setViewName("twitterhomepage");
      mv.addObject("tweets", tweets);
View Full Code Here

  }

  @RequestMapping(value = "/tweetdelete.html", method = RequestMethod.GET, params = "objid")
  public ModelAndView viewUser(@RequestParam(value = "objid") String objId,
      HttpServletRequest request) {
    TwitterUser currUser = Authenticator.isValid(request);
    ModelAndView mv = new ModelAndView();
    if (currUser != null) {
      Tweet tweet = TweetService.getTweet(Long.valueOf(objId));
      if (currUser.equals(tweet.getTwitterUser())) {
        TweetService.deleteTweet(tweet);
      }
      Set<Tweet> tweets = TweetService.getTweetStream(
          currUser.getObjId(), currUser.getFollowing());
      Set<TwitterUser> allUserList = TwitterUserService
          .getAllUserList(currUser);
      Map<String, Integer> followCount = TwitterUserService
          .getFollowCount(currUser.getObjId());
      int tweetCount = TwitterUserService.getTweetCount(currUser);
      Tweet eTweet = new Tweet();
      mv.addObject("tweet", eTweet);
      mv.setViewName("twitterhomepage");
      mv.addObject("tweets", tweets);
View Full Code Here

TOP

Related Classes of com.simpletwitter.models.TwitterUser

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.