本文整理汇总了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'))
示例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'))
示例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'))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()
示例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)
示例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
示例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)
示例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
示例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']))
示例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