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


Python Response.set_cookie方法代码示例

本文整理汇总了Python中pyramid.response.Response.set_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python Response.set_cookie方法的具体用法?Python Response.set_cookie怎么用?Python Response.set_cookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.response.Response的用法示例。


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

示例1: login_post

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def login_post(request):  # tested
    next = request.params.get('next') or request.route_url('home')
    login = request.POST.get('login', '')
    password = request.POST.get('password', '')
    # print(login)
    log.debug(login)
    user = DBSession.query(User).filter_by(login=login).first()
    if user and user.check_password(password):
        client = Client(user_id=user.id)
        user.clients.append(client)
        DBSession.add(client)
        DBSession.flush()
        headers = remember(request, principal=client.id)
        response = Response()
        response.headers = headers
        locale_id = user.default_locale_id
        if not locale_id:
            locale_id = 1
        response.set_cookie(key='locale_id', value=str(locale_id))
        response.set_cookie(key='client_id', value=str(client.id))
        headers = remember(request, principal=client.id)
        # return HTTPFound(location=next, headers=response.headers)
        return HTTPOk(headers=response.headers, json_body={})
        # return {}
    return HTTPUnauthorized(location=request.route_url('login'))
开发者ID:AlexanderYAPPO,项目名称:lingvodoc,代码行数:27,代码来源:user_and_login.py

示例2: signin

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def signin(request):
    req = request.json_body
    login = req['login']
    password = req['password']
    # login = request.POST.get('login', '')
    # password = request.POST.get('password', '')

    user = DBSession.query(User).filter_by(login=login).first()
    if user and user.check_password(password):
        client = Client(user_id=user.id)
        user.clients.append(client)
        DBSession.add(client)
        DBSession.flush()
        headers = remember(request, principal=client.id)
        response = Response()
        response.headers = headers
        locale_id = user.default_locale_id
        if not locale_id:
            locale_id = 1
        response.set_cookie(key='locale_id', value=str(locale_id))
        response.set_cookie(key='client_id', value=str(client.id))
        result = dict()
        result['client_id'] = client.id
        request.response.status = HTTPOk.code
        # request.response.headers = headers
        # return response
        return HTTPOk(headers=response.headers, json_body=result)
        # return result
    return HTTPUnauthorized(location=request.route_url('login'))
开发者ID:AlexanderYAPPO,项目名称:lingvodoc,代码行数:31,代码来源:user_and_login.py

示例3: login_cheat

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def login_cheat(request):  # TODO: test
    next = request.params.get('next') or request.route_url('dashboard')
    login = request.json_body.get('login', '')
    passwordhash = request.json_body.get('passwordhash', '')
    log.debug("Logging in with cheat method:" + login)
    user = DBSession.query(User).filter_by(login=login).first()
    if user and user.password.hash == passwordhash:
        log.debug("Login successful")
        client = Client(user_id=user.id)
        user.clients.append(client)
        DBSession.add(client)
        DBSession.flush()
        headers = remember(request, principal=client.id)
        response = Response()
        response.headers = headers
        locale_id = user.default_locale_id
        if not locale_id:
            locale_id = 1
        response.set_cookie(key='locale_id', value=str(locale_id))
        response.set_cookie(key='client_id', value=str(client.id))
        headers = remember(request, principal=client.id)
        return response

    log.debug("Login unsuccessful for " + login)
    return HTTPUnauthorized(location=request.route_url('login'))
开发者ID:AlexanderYAPPO,项目名称:lingvodoc,代码行数:27,代码来源:user_and_login.py

示例4: set_locale_cookie

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
    def set_locale_cookie(self):
        response = Response()
        language = self.request.matchdict.get('language') or \
            self.request.GET.get('language')

        if language:
            response.set_cookie('_LOCALE_', value=language, max_age=31536000)

        return HTTPFound(location='/', headers=response.headers)
开发者ID:universalcore,项目名称:unicore-cms,代码行数:11,代码来源:cms_views.py

示例5: set_locale_cookie

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def set_locale_cookie(request):
    if request.GET['language']:
        language = request.GET['language']
        if not language in LOCALES:
            language = request.registry.settings.default_locale_name
        response = Response()
        response.set_cookie('_LOCALE_', value=language, max_age=31536000)
        target_url = request.route_url('home', _query={'welcomepage':'off'})
    return HTTPFound(location = target_url, headers = response.headers)
开发者ID:kwaltr,项目名称:vkviewer,代码行数:11,代码来源:SetLocaleCookie.py

示例6: set_locale_cookie

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def set_locale_cookie(request):
    if request.GET['language']:
        language = request.GET['language']
        response = Response()
        response.set_cookie('_LOCALE_',
                            value=language,
                            max_age=31536000)  # max_age = year
    return HTTPFound(location=request.environ['HTTP_REFERER'],
                     headers=response.headers)
开发者ID:ddellaquila,项目名称:pyramid_i18n_howto,代码行数:11,代码来源:i18n.py

示例7: verify

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def verify(request):
    code = request.matchdict['code']
    print(code)
    data = itsden_signat.loads(code)
    print(data)
    _bundle = DBSession.query(Bundle).filter_by(id=data['bundle_id']).first()
    response = Response()
    response.set_cookie(u'{}'.format(data['bundle_id']),
                        value=code, max_age=u'{}'.format(int(time.time()-_bundle.date_end.timestamp()) * -1 ))
    return HTTPFound(location=request.route_url('index'), headers=response.headers)
开发者ID:PashaShulga,项目名称:webapp,代码行数:12,代码来源:views.py

示例8: set_locale_cookie

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def set_locale_cookie(request):
    if request.matchdict.get('language'):
        language = request.matchdict.get('language', 'en')
        response = Response()
        response.set_cookie('_LOCALE_',
                            value=language,
                            max_age=31536000)  # max_age = year
    location = request.route_url('home')
    return HTTPFound(location=location,
                     headers=response.headers)
开发者ID:suryakencana,项目名称:garasu_i18n,代码行数:12,代码来源:__init__.py

示例9: set_language

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def set_language(request):
    if request.POST:
        local_name = negotiate_locale_name(request)
        resp = Response()
        resp.headers = {'Location': request.referrer}
        resp.status = '302'
        resp.set_cookie('language', local_name)
        return resp
    else:
        return HTTPInternalServerError()
开发者ID:fabiobatalha,项目名称:CouchDB-Web,代码行数:12,代码来源:views.py

示例10: set_locale_cookie

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def set_locale_cookie(request):
    _clear_filters(request)
    if request.params.get('language'):
        language = request.params.get('language')
        response = Response()
        response.set_cookie('_LOCALE_',
                            value=language,
                            max_age=31536000)  # max_age = year
    return HTTPFound(location=request.environ.get('HTTP_REFERER', '/'),
                     headers=response.headers)
开发者ID:paweldudzinski,项目名称:paul_wolf_guitars,代码行数:12,代码来源:home.py

示例11: auth

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def auth(request):
    # Key and Token
    api_key = request.POST.get('api_key')
    access_token = request.POST.get('access_token')

    response = Response(content_type='application/json')
    response.set_cookie('api_key', api_key, max_age=31536000)
    response.set_cookie('access_token', access_token, max_age=31536000)
    response.body = json.dumps({'hello': 'world'})
    return response
开发者ID:rjduffner,项目名称:SMLocationTrends,代码行数:12,代码来源:auth.py

示例12: set_locale_cookie

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def set_locale_cookie(request):
    if request.params.get('language'):
        language = request.params.get('language')
        response = Response()
        response.set_cookie(
            '_LOCALE_',
            value=language,
            max_age=YEAR)
    return HTTPFound(
        location=request.environ.get('HTTP_REFERER', '/'),
        headers=response.headers)
开发者ID:paweldudzinski,项目名称:alchemist,代码行数:13,代码来源:views.py

示例13: signUp

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def signUp(request):
    userName = request.params['userName']
    password = request.params['password']

    if(userExists(userName)):
        return Response(status = 401, body = "User name is already taken")

    addUser(userName, password)
    result = Response(status = 200)
    result.set_cookie('sessionData', userCookieString(userName), max_age=60*24*365*4)
    return result 
开发者ID:Harikiranvuyyuru,项目名称:PS4M,代码行数:13,代码来源:main.py

示例14: login_success

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def login_success(request):
    creds = request.json_body
    userid = verify(request.registry._get_settings()['users'], creds)
    if userid:
        headers = remember(request, userid)
        toReturn = Response(
            'Logged in as User %s' % userid,
            headers=headers
            )
        toReturn.set_cookie('username', userid)
        return toReturn
    else:
        return Response('Login Attempt Failed for User %s' % (creds['username']))
开发者ID:mwwilson,项目名称:vHack,代码行数:15,代码来源:views.py

示例15: signup

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import set_cookie [as 别名]
def signup(request):
    creds = request.json_body
    users = request.registry._get_settings()['users']
    users[creds['username']] = {'password':creds['password']}
    userid = creds['username']
    headers = remember(request, userid)
    toReturn = Response(
        'Account for User %s Created' % userid,
        headers=headers
        )
    toReturn.set_cookie('username', userid)
    request.registry._get_settings()['users'][userid] = {'password': creds['password'],
                                                         'tasks'   : {}}
    return toReturn
开发者ID:mwwilson,项目名称:vHack,代码行数:16,代码来源:views.py


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