Package com.simpletwitter.common

Source Code of com.simpletwitter.common.Authenticator

package com.simpletwitter.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;

import 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;
  }

  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");
  }

  public static void saveUserToSession(HttpServletRequest request,
      TwitterUser objectByExample) {
    HttpSession session = request.getSession();
    session.setAttribute("twitteruser", objectByExample);
  }
}
TOP

Related Classes of com.simpletwitter.common.Authenticator

TOP
Copyright © 2018 www.massapi.com. 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.