1 package de.juplo.yourshouter;
3 import javax.inject.Inject;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
7 import org.springframework.social.facebook.api.Facebook;
8 import org.springframework.social.facebook.api.User;
9 import org.springframework.stereotype.Controller;
10 import org.springframework.ui.Model;
11 import org.springframework.web.bind.annotation.RequestMapping;
12 import org.springframework.web.bind.annotation.RequestMethod;
16 * Controller, that handles the welcome-page.
22 public class HomeController
24 private final static Logger LOG = LoggerFactory.getLogger(HomeController.class);
27 private final Facebook facebook;
31 public HomeController(Facebook facebook)
33 this.facebook = facebook;
37 @RequestMapping(method = RequestMethod.GET)
38 public String home(Model model)
40 boolean authorized = true;
43 authorized = facebook.isAuthorized();
45 catch (NullPointerException e)
47 LOG.debug("NPE while acessing Facebook: {}", e);
52 LOG.info("no authorized user, redirecting to /connect/facebook");
53 return "redirect:/connect/facebook";
56 User user = facebook.userOperations().getUserProfile();
57 LOG.info("authorized user {}, id: {}", user.getName(), user.getId());
58 model.addAttribute("user", user);