From fae170ffb9fd77ff5bb6926663188e9e0c4cf890 Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Mon, 6 Jul 2020 14:35:20 +0200 Subject: [PATCH] [twitter] Add column to track twitter oauth verification status --- kibicara/platforms/twitter/model.py | 3 ++- kibicara/platforms/twitter/webapi.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kibicara/platforms/twitter/model.py b/kibicara/platforms/twitter/model.py index e816424..1e38931 100644 --- a/kibicara/platforms/twitter/model.py +++ b/kibicara/platforms/twitter/model.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: 0BSD from kibicara.model import Hood, Mapping -from ormantic import Integer, ForeignKey, Model, Text +from ormantic import Boolean, Integer, ForeignKey, Model, Text class Twitter(Model): @@ -13,6 +13,7 @@ class Twitter(Model): mentions_since_id: Integer(allow_null=True) = None access_token: Text(allow_null=True) = None access_token_secret: Text(allow_null=True) = None + successful_verified: Boolean() = False class Mapping(Mapping): table_name = 'twitterbots' diff --git a/kibicara/platforms/twitter/webapi.py b/kibicara/platforms/twitter/webapi.py index b56b640..7c7e933 100644 --- a/kibicara/platforms/twitter/webapi.py +++ b/kibicara/platforms/twitter/webapi.py @@ -9,6 +9,7 @@ from kibicara.platforms.twitter.model import Twitter from kibicara.webapi.hoods import get_hood from logging import getLogger from sqlite3 import IntegrityError +from ormantic.exceptions import NoMatch from peony.oauth_dance import get_oauth_token, get_access_token @@ -36,6 +37,7 @@ async def twitter_create(response: Response, hood=Depends(get_hood)): callback_uri='http://127.0.0.1:8000/api/twitter/callback', ) if oauth_token['oauth_callback_confirmed'] != 'true': + # TODO delete twitter raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE) await twitter.update( access_token=oauth_token['oauth_token'], @@ -61,9 +63,11 @@ async def twitter_read_callback(oauth_token: str, oauth_verifier: str): await twitter.update( access_token=access_token['oauth_token'], access_token_secret=access_token['oauth_token_secret'], + successful_verified=True, ) spawner.start(twitter) - response.headers['Location'] = '%d' % twitter.id return [] except IntegrityError: raise HTTPException(status_code=status.HTTP_409_CONFLICT) + except NoMatch: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)