コード例 #1
0
ファイル: publicweb.py プロジェクト: jonathanj/mantissa
    def locateChild(self, ctx, segments):
        """
        Look up children in the normal manner, but then customize them for the
        authenticated user if they support the L{ICustomizable} interface.  If
        the user is attempting to access a private URL, redirect them.
        """
        result = self._getAppStoreResource(ctx, segments[0])
        if result is not None:
            child, segments = result, segments[1:]
            return child, segments

        if segments[0] == '':
            result = self.child_(ctx)
            if result is not None:
                child, segments = result, segments[1:]
                return child, segments

        # If the user is trying to access /private/*, then his session has
        # expired or he is otherwise not logged in. Redirect him to /login,
        # preserving the URL segments, rather than giving him an obscure 404.
        if segments[0] == 'private':
            u = URL.fromContext(ctx).click('/').child('login')
            for seg in segments:
                u = u.child(seg)
            return u, ()

        return rend.NotFound
コード例 #2
0
ファイル: publicweb.py プロジェクト: rcarmo/divmod.org
    def locateChild(self, ctx, segments):
        """
        Look up children in the normal manner, but then customize them for the
        authenticated user if they support the L{ICustomizable} interface.  If
        the user is attempting to access a private URL, redirect them.
        """
        result = self._getAppStoreResource(ctx, segments[0])
        if result is not None:
            child, segments = result, segments[1:]
            return child, segments

        if segments[0] == '':
            result = self.child_(ctx)
            if result is not None:
                child, segments = result, segments[1:]
                return child, segments

        # If the user is trying to access /private/*, then his session has
        # expired or he is otherwise not logged in. Redirect him to /login,
        # preserving the URL segments, rather than giving him an obscure 404.
        if segments[0] == 'private':
            u = URL.fromContext(ctx).click('/').child('login')
            for seg in segments:
                u = u.child(seg)
            return u, ()

        return rend.NotFound
コード例 #3
0
    def renderHTTP(self, ctx):
        """
        Handle the password reset form.

        The following exchange describes the process:

            S: Render C{reset}
            C: POST C{username} or C{email}
            S: L{handleRequestForUser}, render C{reset-check-email}

            (User follows the emailed reset link)

            S: Render C{reset-step-two}
            C: POST C{password1}
            S: L{resetPassword}, render C{reset-done}
        """
        req = inevow.IRequest(ctx)

        if req.method == 'POST':
            if req.args.get('username', [''])[0]:
                user = unicode(usernameFromRequest(req), 'ascii')
                self.handleRequestForUser(user, URL.fromContext(ctx))
                self.fragment = self.templateResolver.getDocFactory(
                    'reset-check-email')
            elif req.args.get('email', [''])[0]:
                email = req.args['email'][0].decode('ascii')
                acct = self.accountByAddress(email)
                if acct is not None:
                    username = '******'.join(
                        userbase.getAccountNames(acct.avatars.open()).next())
                    self.handleRequestForUser(username, URL.fromContext(ctx))
                self.fragment = self.templateResolver.getDocFactory(
                    'reset-check-email')
            elif 'password1' in req.args:
                (password, ) = req.args['password1']
                self.resetPassword(self.attempt, unicode(password))
                self.fragment = self.templateResolver.getDocFactory(
                    'reset-done')
            else:
                # Empty submit;  redirect back to self
                return URL.fromContext(ctx)
        elif self.attempt:
            self.fragment = self.templateResolver.getDocFactory(
                'reset-step-two')

        return PublicPage.renderHTTP(self, ctx)
コード例 #4
0
ファイル: signup.py プロジェクト: fusionapp/mantissa
    def renderHTTP(self, ctx):
        """
        Handle the password reset form.

        The following exchange describes the process:

            S: Render C{reset}
            C: POST C{username} or C{email}
            S: L{handleRequestForUser}, render C{reset-check-email}

            (User follows the emailed reset link)

            S: Render C{reset-step-two}
            C: POST C{password1}
            S: L{resetPassword}, render C{reset-done}
        """
        req = inevow.IRequest(ctx)

        if req.method == 'POST':
            if req.args.get('username', [''])[0]:
                user = unicode(usernameFromRequest(req), 'ascii')
                self.handleRequestForUser(user, URL.fromContext(ctx))
                self.fragment = self.templateResolver.getDocFactory(
                    'reset-check-email')
            elif req.args.get('email', [''])[0]:
                email = req.args['email'][0].decode('ascii')
                acct = self.accountByAddress(email)
                if acct is not None:
                    username = '******'.join(
                        userbase.getAccountNames(acct.avatars.open()).next())
                    self.handleRequestForUser(username, URL.fromContext(ctx))
                self.fragment = self.templateResolver.getDocFactory('reset-check-email')
            elif 'password1' in req.args:
                (password,) = req.args['password1']
                self.resetPassword(self.attempt, unicode(password))
                self.fragment = self.templateResolver.getDocFactory('reset-done')
            else:
                # Empty submit;  redirect back to self
                return URL.fromContext(ctx)
        elif self.attempt:
            self.fragment = self.templateResolver.getDocFactory('reset-step-two')

        return PublicPage.renderHTTP(self, ctx)
コード例 #5
0
 def childFactory(self, ctx, name):
     for T in self.original.store.query(
             Ticket,
             AND(Ticket.booth == self.original,
                 Ticket.nonce == unicode(name, 'ascii'))):
         something = T.claim()
         res = IResource(something)
         lgo = getattr(res, 'logout', lambda: None)
         ISession(ctx).setDefaultResource(res, lgo)
         return URL.fromContext(ctx).click("/private")
     return None
コード例 #6
0
ファイル: signup.py プロジェクト: fusionapp/mantissa
 def childFactory(self, ctx, name):
     for T in self.original.store.query(
         Ticket,
         AND(Ticket.booth == self.original,
             Ticket.nonce == unicode(name, 'ascii'))):
         something = T.claim()
         res = IResource(something)
         lgo = getattr(res, 'logout', lambda : None)
         ISession(ctx).setDefaultResource(res, lgo)
         return URL.fromContext(ctx).click("/private")
     return None
コード例 #7
0
ファイル: renderers.py プロジェクト: timparkin/into-the-light
def render_child_base_href(ctx, data):
    """
    Render a URL that acts as a base for constructing links to child resources.
    In essence, this is url.here with any slashes removed from the end, giving
    it consistent for root and non-root URLs.

    An example of how one might use this to render a link to a child resource is:

        <a href="#"><n:attr name="href"><n:invisible n:render="child_base_href"
            />/<n:slot name="id" /><n:attr>more ...</a>
    """
    url = str(URL.fromContext(ctx))
    url = url.rstrip('/')
    return url
コード例 #8
0
ファイル: website.py プロジェクト: rcarmo/divmod.org
 def renderHTTP(self, ctx):
     return URL.fromContext(ctx).click(self.targetURL)
コード例 #9
0
ファイル: website.py プロジェクト: jonathanj/mantissa
 def renderHTTP(self, ctx):
     return URL.fromContext(ctx).click(self.targetURL)