From cf4f797420e321ec30c3924b00b78f3b606fa3f1 Mon Sep 17 00:00:00 2001 From: Mootfrost Date: Thu, 17 Apr 2025 23:14:03 +0300 Subject: [PATCH] Add logout, appearance fixes --- app/__init__.py | 16 +++++++++++++++- app/callback_listener.py | 2 +- app/static/authorize_spotify.html | 21 ++++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 44fc32c..a200abb 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -19,7 +19,7 @@ import urllib.parse from mutagen.id3 import ID3, APIC import logging from cachetools import LRUCache -from sqlalchemy import select, update +from sqlalchemy import select, update, delete import jwt @@ -105,6 +105,20 @@ async def set_default(e: events.CallbackQuery.Event): await e.respond("Default service updated") +@client.on(events.NewMessage(pattern='/logout')) +async def confirm_logout(e: events.NewMessage.Event): + await e.respond('This action will delete all your data. Continue?', buttons=[Button.inline('Yes', 'confirm_logout')]) + + +@client.on(events.CallbackQuery(pattern='confirm_logout')) +async def logout(e: events.CallbackQuery.Event): + async with get_session_context() as session: + await session.execute( + delete(User).where(User.id == e.sender_id) + ) + await e.respond('Logged out successfully. Use /start to continue using the bot') + + async def fetch_file(url) -> bytes: async with aiohttp.ClientSession() as session: async with session.get(url) as response: diff --git a/app/callback_listener.py b/app/callback_listener.py index 99b0ea8..fa9f31c 100644 --- a/app/callback_listener.py +++ b/app/callback_listener.py @@ -125,7 +125,7 @@ async def spotify_callback( user = User(id=data['tg_id'], spotify_auth=creds, default="spotify") session.add(user) reply = "Account linked!" - if user.spotify_auth: + if user.ymusic_auth: reply += second_provider_notification await client.send_message(data['tg_id'], reply) return FileResponse("app/static/success.html", media_type="text/html") diff --git a/app/static/authorize_spotify.html b/app/static/authorize_spotify.html index d0c00bb..16c3862 100644 --- a/app/static/authorize_spotify.html +++ b/app/static/authorize_spotify.html @@ -75,7 +75,14 @@
  1. Visit Spotify Developer Dashboard
  2. Log in and create an app
  3. -
  4. Fill any name and description. Set redirect url to: {{ redirect_url }}
  5. +
  6. Fill any name and description
  7. +
  8. + Set redirect url to: + + {{ redirect_url }} + + (click to copy) +
  9. Copy your Client ID and Client Secret
@@ -87,6 +94,12 @@ + +
+ + How we use this data + +
+