Skip to content

Commit

Permalink
修复删除session过程中可能出现的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
kitakamiooi committed Dec 12, 2015
1 parent 755cc60 commit bca4c2b
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions handlers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
class FrontEndHandler:
"""OOI3前端请求处理类。"""

def clear_session(self, session):
if 'api_token' in session:
del session['api_token']
if 'api_starttime' in session:
del session['api_starttime']
if 'world_ip' in session:
del session['world_ip']

@aiohttp_jinja2.template('form.html')
async def form(self, request):
"""展示登录表单。
Expand Down Expand Up @@ -84,9 +92,7 @@ async def normal(self, request):
'starttime': starttime}
return aiohttp_jinja2.render_template('normal.html', request, context)
else:
del session['api_token']
del session['api_starttime']
del session['world_ip']
self.clear_session(session)
return aiohttp.web.HTTPFound('/')

async def kcv(self, request):
Expand All @@ -103,9 +109,7 @@ async def kcv(self, request):
if token and starttime and world_ip:
return aiohttp_jinja2.render_template('kcv.html', request, context={})
else:
del session['api_token']
del session['api_starttime']
del session['world_ip']
self.clear_session(session)
return aiohttp.web.HTTPFound('/')

async def flash(self, request):
Expand All @@ -126,9 +130,7 @@ async def flash(self, request):
'starttime': starttime}
return aiohttp_jinja2.render_template('flash.html', request, context)
else:
del session['api_token']
del session['api_starttime']
del session['world_ip']
self.clear_session(session)
return aiohttp.web.HTTPFound('/')

async def poi(self, request):
Expand All @@ -149,9 +151,7 @@ async def poi(self, request):
'starttime': starttime}
return aiohttp_jinja2.render_template('poi.html', request, context)
else:
del session['api_token']
del session['api_starttime']
del session['world_ip']
self.clear_session(session)
return aiohttp.web.HTTPFound('/')

async def logout(self, request):
Expand All @@ -161,10 +161,5 @@ async def logout(self, request):
:return: aiohttp.web.HTTPFound
"""
session = await get_session(request)
if 'api_token' in session:
del session['api_token']
if 'api_starttime' in session:
del session['api_starttime']
if 'world_ip' in session:
del session['world_ip']
self.clear_session(session)
return aiohttp.web.HTTPFound('/')

0 comments on commit bca4c2b

Please sign in to comment.