diff options
author | clarkzjw <[email protected]> | 2023-02-23 00:13:47 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-23 12:07:32 -0800 |
commit | 770cd0ec5eb556d912bd9d200b2da76c7e3bd7c8 (patch) | |
tree | 11cc26af821ea2b7e97c623aedfe51c487559f0e | |
parent | 5402e3a2e9df24a883e2e20dfae6c92f11b8d499 (diff) | |
download | swarm2fediverse-770cd0ec5eb556d912bd9d200b2da76c7e3bd7c8.tar.gz |
bot: fix login flow
-rw-r--r-- | callback.py | 3 | ||||
-rw-r--r-- | dbstore/peewee_store.py | 17 |
2 files changed, 19 insertions, 1 deletions
diff --git a/callback.py b/callback.py index 23b814b..d968523 100644 --- a/callback.py +++ b/callback.py | |||
@@ -97,10 +97,11 @@ async def callback_generate_fedi_login_url(update: Update, context: ContextTypes | |||
97 | scopes=BOT_SCOPE, | 97 | scopes=BOT_SCOPE, |
98 | state=state) | 98 | state=state) |
99 | 99 | ||
100 | await update.message.reply_text(PROMPT_FEDI_LOGIN, | 100 | msg = await update.message.reply_text(PROMPT_FEDI_LOGIN, |
101 | reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Login", url=oauth_url)]]), | 101 | reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Login", url=oauth_url)]]), |
102 | parse_mode=ParseMode.MARKDOWN) | 102 | parse_mode=ParseMode.MARKDOWN) |
103 | 103 | ||
104 | context.user_data[PROMPT_FEDI_LOGIN] = msg.message_id | ||
104 | return FEDI_LOGIN | 105 | return FEDI_LOGIN |
105 | 106 | ||
106 | 107 | ||
diff --git a/dbstore/peewee_store.py b/dbstore/peewee_store.py index 89e4b4b..3d37140 100644 --- a/dbstore/peewee_store.py +++ b/dbstore/peewee_store.py | |||
@@ -24,6 +24,23 @@ class User(BaseModel): | |||
24 | toot_visibility = CharField(max_length=128, default=TOOT_VISIBILITY_PRIVATE) | 24 | toot_visibility = CharField(max_length=128, default=TOOT_VISIBILITY_PRIVATE) |
25 | 25 | ||
26 | 26 | ||
27 | def get_user_by_state(state: str) -> dict: | ||
28 | with db.connection_context(): | ||
29 | try: | ||
30 | user = User.get(User.state == state) | ||
31 | return { | ||
32 | "telegram_user_id": user.telegram_user_id, | ||
33 | "access_key": user.access_key, | ||
34 | "home_instance": user.home_instance, | ||
35 | "state": user.state, | ||
36 | "client_id": user.client_id, | ||
37 | "client_secret": user.client_secret, | ||
38 | "toot_visibility": user.toot_visibility, | ||
39 | } | ||
40 | except DoesNotExist: | ||
41 | return {} | ||
42 | |||
43 | |||
27 | class Location(BaseModel): | 44 | class Location(BaseModel): |
28 | fsq_id = CharField(unique=True, primary_key=True) | 45 | fsq_id = CharField(unique=True, primary_key=True) |
29 | name = CharField(max_length=128) | 46 | name = CharField(max_length=128) |