当前位置: 首页>>代码示例>>Python>>正文


Python httpexceptions.HTTPFound类代码示例

本文整理汇总了Python中pyramid.httpexceptions.HTTPFound的典型用法代码示例。如果您正苦于以下问题:Python HTTPFound类的具体用法?Python HTTPFound怎么用?Python HTTPFound使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTTPFound类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: record_add

    def record_add(self):
        zonename = self.request.matchdict['zonename']
        zonefile = settings.zones[zonename]
        zone = Zone(zonename, zonefile)

        schema = Record(validator=record_validator)
        form = deform.Form(schema, buttons=('submit',))

        response = {"zonename": zonename,
                    "recordname": "new"}
        response["form"] = form.render()

        if 'submit' in self.request.POST:
            controls = self.request.POST.items()
            try:
                data = form.validate(controls)
            except deform.ValidationFailure, e:
                response['form'] = e.render()
                return response
            if not name_is_protected(zonename, data['name']):
                zone.add_record(**data)
                response = HTTPFound()
                response.location = self.request.route_url('record',
                                                            zonename=zonename,
                                                            recordname=data['name'])
                return response
            else:
                return HTTPForbidden()
开发者ID:MrGlamur,项目名称:bind9-zone-editor,代码行数:28,代码来源:views.py

示例2: skip_persona_selection

 def skip_persona_selection(self):
     # set cookie and redirect
     response = HTTPFound(location=get_redirect_url(self.request))
     response.set_cookie(
         PERSONA_COOKIE_NAME, value=PERSONA_SKIP_COOKIE_VALUE,
         max_age=ONE_YEAR)
     return response
开发者ID:universalcore,项目名称:springboard-iogt,代码行数:7,代码来源:views.py

示例3: account_verify_email

def account_verify_email(request):
    login_store = request.find_service(name="redis_login")

    try:
        user_id = int(request.GET["user_id"].strip())
        email_address = request.GET["email_address"].strip()
        token = request.GET["token"].strip()
    except (KeyError, ValueError):
        raise HTTPNotFound
    stored_token = login_store.get("verify_email:%s:%s" % (user_id, email_address))
    if not user_id or not email_address or not token or not stored_token:
        raise HTTPNotFound

    stored_token = stored_token.decode("utf-8")

    if not stored_token == token:
        raise HTTPNotFound

    try:
        db = request.find_service(name="db")
        user = db.query(User).filter(User.id == user_id).one()
    except NoResultFound:
        raise HTTPNotFound

    user.email = email_address

    response = HTTPFound(request.route_path("account", _query={"saved": "email_address"}))

    if not request.user or request.user.id != user.id:
        new_session_id = str(uuid4())
        login_store.set("session:" + new_session_id, user.id)
        response.set_cookie("cherubplay", new_session_id, 31536000)

    return response
开发者ID:tehdragonfly,项目名称:cherubplay,代码行数:34,代码来源:account.py

示例4: record_edit

    def record_edit(self):
        zonename = self.request.matchdict['zonename']
        recordname = self.request.matchdict['recordname']
        zonefile = settings.zones[zonename]
        zone = Zone(zonename, zonefile)
        protected = name_is_protected(zonename, recordname)
        response = {"zonename": zonename,
                    "recordname": recordname}

        if self.request.POST and protected:
            return HTTPForbidden("You can not modify this domain name")

        elif protected:
            response['protected'] = protected
            response['record'] = zone.get_record(recordname)
            return response

        schema = Record(validator=record_validator)
        form = deform.Form(schema, buttons=('submit',))

        if self.request.POST:
            controls = self.request.POST.items()
            try:
                data = form.validate(controls)
            except deform.ValidationFailure, e:
                response['form'] = e.render()
                return response
            else:
                zone.add_record(**data)
                response = HTTPFound()
                response.location = self.request.route_url('record',
                                                            zonename=zonename,
                                                            recordname=data['name'])
                return response
开发者ID:MrGlamur,项目名称:bind9-zone-editor,代码行数:34,代码来源:views.py

示例5: login

    def login(self):
        hubclient = self.request.registry.hubclient
        response = HTTPFound()

        # redeem ticket to get user data
        ticket = self.request.GET.get('ticket', None)
        if ticket and hubclient:
            try:
                user = hubclient.get_user(
                    ticket, self.request.route_url('redirect_to_login'))
                self.request.session[USER_DATA_SESSION_KEY] = user.data
                user_id = user.get('uuid')
                headers = remember(self.request, user_id)
                response.headerlist.extend(headers)

            except HubClientException:
                # TODO: what to do when ticket is invalid?
                pass

        redirect_url = self.request.GET.get('url', None)
        if not (redirect_url and same_origin(
                redirect_url, self.request.current_route_url())):
            redirect_url = self.request.route_url(route_name='home')
        response.location = redirect_url

        return response
开发者ID:universalcore,项目名称:unicore-cms,代码行数:26,代码来源:cms_views.py

示例6: __call__

    def __call__(self):
        """Log the user out by deleting cookies and redirecting to CAS logout.
        """
        if security.authenticated_userid(self.request):
            # Return to this view once we've logged out.
            here = self.request.route_url(self.request.matched_route.name)
            here += '?return=' + self.request.referrer
            response = HTTPFound(location=here)

            # Drop the current session for the user. Copy the session to the
            # new response so the cookies get cleared.
            response.session = self.request.session
            response.session.invalidate()

            # Forget the user's login cookie
            forget_headers = security.forget(self.request)
            response.headerlist.extend(forget_headers)
            return response
        else:
            # Once cookies are gone, sign out. Either SSO or redirection.
            route = self.request.registry.settings[RETURN_ROUTE]
            # Go back to the original page, or the default
            return_url = self.request.params.get('return',
                                                 self.request.route_url(route))

            sso_url = self.request.registry.settings[SSO_URL]
            logout_url = (sso_url + '?url=' + return_url) if \
                self.request.registry.settings[ENABLE_SLO] else return_url

            return HTTPFound(location=logout_url)
开发者ID:,项目名称:,代码行数:30,代码来源:

示例7: handle_get

 def handle_get(self):
     request = self.request
     view = request.view_name
     subpath = request.subpath
     if not view:
         route = self.request.matched_route.name
         if route == 'home':
             self.response = HTTPFound('/frontdoor')
             return
         raise HTTPNotFound()
     elif view in ['login', 'logout']:
         # This breaks GET has no side effects
         if view == 'logout':
             return self.handle_logout({})
         self.response = HTTPFound('/frontdoor')
         return
     elif view == 'frontdoor':
         if not len(subpath):
             template = 'trumpet:templates/webview-app.mako'
             settings = self.get_app_settings()
             basecolor = settings['default.css.basecolor']
             env = dict(appname='frontdoor', basecolor=basecolor)
             content = render(template, env)
             self.response = Response(body=content)
             self.response.encode_content()
         else:
             assetpath = 'trumpet:static/apps/frontdoor'
             asset = os.path.join(assetpath, *subpath)
             self.response = static_asset_response(request, asset)
     else:
         self.response = HTTPNotFound()
开发者ID:nkabir,项目名称:trumpet,代码行数:31,代码来源:frontdoor.py

示例8: item_add

    def item_add(self):
        groupname = self.request.matchdict['groupname']
        groupfile = self.files[groupname]
        group = self.backend(groupname, groupfile)

        schema = group.get_add_schema()
        form = deform.Form(schema, buttons=('submit',))

        response = {"groupname": groupname,
                    "itemname": "new"}
        response["form"] = form.render()

        if 'submit' in self.request.POST and self.request.POST['submit'] == 'submit':
            controls = self.request.POST.items()
            try:
                data = form.validate(controls)
            except deform.ValidationFailure, e:
                response['form'] = e.render()
                return response

            if data['name'] not in self.protected_names[groupname]:
                group.add_item(data)
                response = HTTPFound()
                response.location = self.request.route_url('item',
                                                            groupname=groupname,
                                                            itemname=data['name'])
                return response
            else:
                return HTTPForbidden()
开发者ID:RavenB,项目名称:ninja-sysop,代码行数:29,代码来源:views.py

示例9: lang

def lang(request):
    # Set language
    code = request.matchdict['code']
    # TODO redirect where we came_from
    response = HTTPFound(location='/')
    response.set_cookie('lang', value=code, max_age=31536000) # max_age = year
    return response
开发者ID:tojuhaka,项目名称:easyblog,代码行数:7,代码来源:views.py

示例10: fbauth

def fbauth(request):
    code = request.params['code']
    fb_user = User.fb_user(code)
    user_id = str(fb_user.id)
    response = HTTPFound(location="/")
    response.set_cookie('user_id', value=user_id, max_age=31536000)
    return response
开发者ID:theseansy,项目名称:swoll,代码行数:7,代码来源:login.py

示例11: logout

def logout(request):
    next = request.params.get('next') or request.route_url('index')
    if not authenticated_userid(request):
        return HTTPFound(location=request.route_url('login'))
    headers = forget(request)
    response = HTTPFound(location=next, headers=headers)
    response.set_cookie('csrf_token', value=None)
    return response
开发者ID:aape,项目名称:m4ed,代码行数:8,代码来源:auth.py

示例12: logout_view

def logout_view(request):
    """
        The logout view
    """
    loc = request.route_url('index')
    headers = forget(request)
    response = HTTPFound(location=loc, headers=headers)
    response.delete_cookie("remember_me")
    return response
开发者ID:mike-perdide,项目名称:autonomie,代码行数:9,代码来源:auth.py

示例13: logout

    def logout(self):
        response = HTTPFound(headers=forget(self.request))

        if self.request.referrer and same_origin(
                self.request.referrer, self.request.current_route_url()):
            response.location = self.request.referrer
        else:
            response.location = self.request.route_url(route_name='home')

        return response
开发者ID:universalcore,项目名称:unicore-cms,代码行数:10,代码来源:cms_views.py

示例14: login

def login(request):
    username = request.params.get('username', None)
    password = request.params.get('password', None)
    session = DBSession()
    user = session.query(User).filter(User.username==username).first()
    if user is not None and user.password == password:
        response = HTTPFound('/')
        # totally insecure, TODO in workshop: use auth token or something
        response.set_cookie('user_id', str(user.id), max_age=timedelta(30))
        return response
    return {'username': username}
开发者ID:antoineleclair,项目名称:OpenCode20111201,代码行数:11,代码来源:sessions.py

示例15: do_logout

    def do_logout(self, request, location):
        """ do the logout """
        # convenient method to set Cache-Control and Expires headers
        request.response.cache_expires = 0

        headers = forget(request)
        response = HTTPFound(location=location, headers=headers)
        response.delete_cookie('cis_account', path="/")
        response.cache_control = 'no-cache'

        request.session.pop_flash('token')
        return response
开发者ID:puittenbroek,项目名称:cister.db,代码行数:12,代码来源:login.py


注:本文中的pyramid.httpexceptions.HTTPFound类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。