@RequestMapping(value = "/login.htm", method = RequestMethod.GET)
    public String login(HttpServletRequest req,HttpServletResponse res) {
        if(req.getAttribute("user") != null) return "redirect:/main.htm";//already loged go to main
        
        //retrieving oath tokens returned from twitter which are used to create accesstoken
        String oauthToken    = req.getParameter("oauth_token");
        String oauthVerifier = req.getParameter("oauth_verifier");
        
        //retrieving request token from cookie (request token is used to construct twitter oath kyes)
        RequestToken requestToken = (RequestToken)req.getSession().getAttribute(REQUEST_TOKEN);
        
        if(requestToken == null||oauthToken==null||oauthVerifier==null) return "redirect:/index.htm?error=1";//couldn't retrieve requestToken go to index

        twitter4j.User twitterUser = null;
        AccessToken accessToken    = null;
        try {
           mainTwitter.setOAuthAccessToken(null); // clearing oath tokens
           accessToken = mainTwitter.getOAuthAccessToken(requestToken, oauthVerifier);// creating new oath token for the user
           mainTwitter.setOAuthAccessToken(accessToken); // setting new access token
           twitterUser = mainTwitter.showUser(accessToken.getUserId());// retrieving user information from twitter
        } catch (TwitterException ex) {
            Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        if(accessToken==null||twitterUser==null)return "redirect:/index.htm?error=2";//failed return to index
        
        long userId = accessToken.getUserId();            
        User user   = service.getUserById(userId);// retrieving user from database
        
        if(user == null){ //user does not exist create new user
            user = new User();
            user.setId(userId);
            user.setProfilePictureUrl(twitterUser.getBiggerProfileImageURL());
            user.setName(twitterUser.getName());
            user.setAccessToken(accessToken.getToken());
            user.setAccessTokenSecret(accessToken.getTokenSecret());
            user.setTwitterAccountName(accessToken.getScreenName());
            service.addUser(user);
        }
        
        req.setAttribute("user",user);//attaching user to request
        return "redirect:/main.htm";
    }