From 634761ef169f18ecfbe5c789e8a02a5a5e47b348 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 28 Jan 2016 17:04:44 +0100 Subject: [PATCH] WIP: Added a controller, to manage permissions --- .../yourshouter/PermissionsController.java | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/juplo/yourshouter/PermissionsController.java b/src/main/java/de/juplo/yourshouter/PermissionsController.java index 1ce9c1d..e3a9820 100644 --- a/src/main/java/de/juplo/yourshouter/PermissionsController.java +++ b/src/main/java/de/juplo/yourshouter/PermissionsController.java @@ -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 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); + } } -- 2.20.1