Exemple #1
0
    def extractCredentials(self, request):
        """This method is called on every request to extract credentials.
        In our case, that means looking for the values we store in the
        session.

        o Return a mapping of any derived credentials.

        o Return an empty mapping to indicate that the plugin found no
          appropriate credentials.
        """

        # Get the session from session_data_manager
        sdm = getToolByName(getSite(), "session_data_manager")
        session = sdm.getSessionData(create=False)

        if session is None:
            return None

        # We have been authenticated and we have a session that has not yet
        # expired:

        if SessionKeys.user_id in session:

            return {
                'src': self.getId(),
                'userid': session[SessionKeys.user_id],
                'username': session[SessionKeys.screen_name],
            }

        return None
Exemple #2
0
    def resetCredentials(self, request, response):
        """This method is called if the user logs out.

        Here, we simply destroy their session.
        """
        sdm = getToolByName(getSite(), "session_data_manager")
        session = sdm.getSessionData(create=False)
        if session is None:
            return

        session.invalidate()