def oauth_callback_full_access(request):
logger = request.app.logger
bot = request.app.bot
params = parse_qs(request.query_string)
callback_key = params.get('key', [''])[0]
session_key = params.get('session_key')[0]
try:
session = StartSession.get({'oauth_data.callback_key': callback_key})
user = User.get({'id': session.id})
except ModelNotFound as e:
logger.error(e, exc_info=1)
return web.HTTPForbidden()
if not params.get('oauth_verifier'):
logger.info('User declined full access =(')
bot.send_message(
user.telegram_chat_id,
'We are sorry, but you deny read/update access??',
{'hide_keyboard': True}
)
return web.HTTPFound(bot.url)
if session.key != session_key:
text = 'Session is expired. Please, send /start command to create \
new session'
bot.send_message(user.telegram_chat_id, text)
return web.HTTPFound(bot.url)
try:
oauth_verifier = params['oauth_verifier'][0]
config_data = config['evernote']['full_access']
future = asyncio.ensure_future(
bot.evernote.get_access_token(config_data, session.oauth_data,
oauth_verifier)
)
future.add_done_callback(
functools.partial(switch_to_one_note_mode, bot, user.id)
)
except TokenRequestDenied as e:
logger.error(e, exc_info=1)
bot.send_message(
user.telegram_chat_id,
'We are sorry, but we have some problems with Evernote connection.\
Please try again later',
{'hide_keyboard': True}
)
except Exception as e:
logger.fatal(e, exc_info=1)
bot.send_message(user.telegram_chat_id, 'Oops. Unknown error',
{'hide_keyboard': True})
text = 'From now this bot in "One note" mode'
bot.send_message(user.telegram_chat_id, text,
{'hide_keyboard': True})
return web.HTTPFound(bot.url)
评论列表
文章目录