WIP: Added a controller, to manage permissions
authorKai Moritz <kai@juplo.de>
Thu, 28 Jan 2016 16:04:44 +0000 (17:04 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 3 Jul 2018 15:18:12 +0000 (17:18 +0200)
src/main/java/de/juplo/yourshouter/PermissionsController.java

index 1ce9c1d..e3a9820 100644 (file)
@@ -2,6 +2,9 @@ package de.juplo.yourshouter;
 
 import java.util.List;
 import javax.inject.Inject;
+import org.springframework.social.connect.ConnectionFactoryLocator;
+import org.springframework.social.connect.ConnectionRepository;
+import org.springframework.social.connect.web.ConnectController;
 
 import org.springframework.social.facebook.api.Facebook;
 import org.springframework.social.facebook.api.Permission;
@@ -9,6 +12,8 @@ import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.servlet.view.RedirectView;
 
 
 /**
@@ -17,23 +22,44 @@ import org.springframework.web.bind.annotation.RequestMethod;
  * @author Kai Moritz
  */
 @Controller
-public class PermissionsController
+@RequestMapping("/permissions.html")
+public class PermissionsController extends ConnectController
 {
   private final Facebook facebook;
 
 
   @Inject
-  public PermissionsController(Facebook facebook)
+  public PermissionsController(
+      ConnectionFactoryLocator connectionFactoryLocator,
+      ConnectionRepository connectionRepository,
+      Facebook facebook
+      )
   {
+    super(connectionFactoryLocator, connectionRepository);
     this.facebook = facebook;
   }
 
 
-  @RequestMapping(value = "/permissions.html", method = RequestMethod.GET)
-  public String list(Model model)
+  @Override
+  public String connectionStatus(NativeWebRequest request, Model model)
   {
     List<Permission> permissions = facebook.userOperations().getUserPermissions();
     model.addAttribute("permissions", permissions);
     return "permissions";
   }
+
+  @RequestMapping(method=RequestMethod.POST)
+  public RedirectView connect(NativeWebRequest request)
+  {
+    return super.connect("facebook", request);
+  }
+
+  @Override
+  protected RedirectView connectionStatusRedirect(
+      String providerId,
+      NativeWebRequest request
+      )
+  {
+    return new RedirectView("/permissions.html", true);
+  }
 }