def authenticate(self, fn, request, *args, **kwargs): ''' Authenticate the user There are three options a.) We have permissions, proceed with the view b.) We tried getting permissions and failed, abort... c.) We are about to ask for permissions ''' redirect_uri = self.get_redirect_uri(request) oauth_url = get_oauth_url( self.scope_list, redirect_uri, extra_params=self.extra_params) graph = get_persistent_graph(request, redirect_uri=redirect_uri) # See if we have all permissions permissions_granted = has_permissions(graph, self.scope_list) if permissions_granted: response = self.execute_view( fn, request, graph=graph, *args, **kwargs) elif request.REQUEST.get('attempt') == '1': # Doing a redirect could end up causing infinite redirects # If Facebook is somehow not giving permissions # Time to show an error page response = self.authentication_failed(fn, request, *args, **kwargs) else: response = self.oauth_redirect(oauth_url, redirect_uri) return response
def authenticate(self, fn, request, *args, **kwargs): redirect_uri = self.get_redirect_uri(request) oauth_url = get_oauth_url( self.scope_list, redirect_uri, extra_params=self.extra_params) graph = None try: # call get persistent graph and convert the # token with correct redirect uri graph = require_persistent_graph( request, redirect_uri=redirect_uri) # Note we're not requiring a persistent graph here # You should require a persistent graph in the view when you start using this response = self.execute_view( fn, request, graph=graph, *args, **kwargs) except open_facebook_exceptions.OpenFacebookException, e: permission_granted = has_permissions(graph, self.scope_list) if permission_granted: # an error if we already have permissions # shouldn't have been caught # raise to prevent bugs with error mapping to cause issues raise elif request.REQUEST.get('attempt') == '1': # Doing a redirect could end up causing infinite redirects # If Facebook is somehow not giving permissions # Time to show an error page response = self.authentication_failed( fn, request, *args, **kwargs) else: response = self.oauth_redirect(oauth_url, redirect_uri, e)
def authenticate(self, fn, request, *args, **kwargs): ''' Authenticate the user There are three options a.) We have permissions, proceed with the view b.) We tried getting permissions and failed, abort... c.) We are about to ask for permissions ''' redirect_uri = self.get_redirect_uri(request) oauth_url = get_oauth_url(self.scope_list, redirect_uri, extra_params=self.extra_params) graph = get_persistent_graph(request, redirect_uri=redirect_uri) # See if we have all permissions permissions_granted = has_permissions(graph, self.scope_list) if permissions_granted: response = self.execute_view(fn, request, graph=graph, *args, **kwargs) elif request.REQUEST.get('attempt') == '1': # Doing a redirect could end up causing infinite redirects # If Facebook is somehow not giving permissions # Time to show an error page response = self.authentication_failed(fn, request, *args, **kwargs) else: response = self.oauth_redirect(oauth_url, redirect_uri) return response
def authenticate(self, fn, request, *args, **kwargs): redirect_uri = self.get_redirect_uri(request) oauth_url = get_oauth_url(self.scope_list, redirect_uri, extra_params=self.extra_params) graph = None try: # call get persistent graph and convert the # token with correct redirect uri graph = require_persistent_graph(request, redirect_uri=redirect_uri) # Note we're not requiring a persistent graph here # You should require a persistent graph in the view when you start using this response = self.execute_view(fn, request, graph=graph, *args, **kwargs) except open_facebook_exceptions.OpenFacebookException, e: permission_granted = has_permissions(graph, self.scope_list) if permission_granted: # an error if we already have permissions # shouldn't have been caught # raise to prevent bugs with error mapping to cause issues raise elif request.REQUEST.get('attempt') == '1': # Doing a redirect could end up causing infinite redirects # If Facebook is somehow not giving permissions # Time to show an error page response = self.authentication_failed(fn, request, *args, **kwargs) else: response = self.oauth_redirect(oauth_url, redirect_uri, e)
def authenticate(self, fn, request, *args, **kwargs): redirect_uri = self.get_redirect_uri(request) oauth_url = get_oauth_url( self.scope_list, redirect_uri, extra_params=self.extra_params) graph = None try: # call get persistent graph and convert the # token with correct redirect uri graph = require_persistent_graph( request, redirect_uri=redirect_uri) # Note we're not requiring a persistent graph here # You should require a persistent graph in the view when you start # using this facebook = OpenFacebook(graph.access_token) user = facebook.get('me') email = user.get('email') user_model = get_user_model() user = user_model.objects.filter(email=email) a = 0 if user: response = self.execute_view( fn, request, graph=graph, *args, **kwargs) else: response = HttpResponse("Voce nao tem permissao para acessar o sistema<br>Para ter acesso repasse esse email para o administrador: " + email) except open_facebook_exceptions.OpenFacebookException as e: permission_granted = has_permissions(graph, self.scope_list) if permission_granted: # an error if we already have permissions # shouldn't have been caught # raise to prevent bugs with error mapping to cause issues a = 0 if a == 0: response = self.authentication_failed( fn, request, *args, **kwargs) else: raise elif request.REQUEST.get('attempt') == '1': # Doing a redirect could end up causing infinite redirects # If Facebook is somehow not giving permissions # Time to show an error page response = self.authentication_failed( fn, request, *args, **kwargs) else: response = self.oauth_redirect(oauth_url, redirect_uri, e) return response