Subversion Repositories SmartDukaan

Rev

Rev 21561 | Rev 21574 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.tool.schema.extract.internal.ForeignKeyInformationImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.web.model.FofoDetails;
import com.spice.profitmandi.web.util.GoogleLoginUtil;

@Controller
public class LoginController {

        private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
        
        @Autowired
        GoogleLoginUtil googleLoginUtil;
        
        @RequestMapping(value = "/login", method = RequestMethod.GET)
        public String loginPage(@ModelAttribute("model") ModelMap model) {
                return "login";
        }
        
        @RequestMapping(value = "/login", method = RequestMethod.POST)
        public String login(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.TOKEN) String token){
                try{
                        FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
                        request.getSession().setAttribute(ProfitMandiConstants.FOFO_DETAILS, fofoDetails);
                        return "redirect: dashboard";
                }catch(ProfitMandiBusinessException profitMandiBusinessException){
                        LOGGER.error("Error : ", profitMandiBusinessException);
                        return "redirect: error";
                }
        }
}