From 55740912734bc31bde3013b497d3b3d07522b3b2 Mon Sep 17 00:00:00 2001 From: Pin Studios Date: Sun, 16 Mar 2025 10:44:40 +0800 Subject: [PATCH] Revert "feat: Add GitHub-based trial reset" --- github_trial_reset.py | 170 ---------------------------------------- main.py | 29 +++---- oauth_auth.py | 4 +- reset_machine_manual.py | 38 +++------ 4 files changed, 27 insertions(+), 214 deletions(-) delete mode 100644 github_trial_reset.py diff --git a/github_trial_reset.py b/github_trial_reset.py deleted file mode 100644 index f75892c..0000000 --- a/github_trial_reset.py +++ /dev/null @@ -1,170 +0,0 @@ -import os -import time -from colorama import init, Fore -from DrissionPage import ChromiumPage -from cursor_auth import CursorAuth -from utils import MachineIDResetter -import keyring - -# Initialize colorama -init() - -# Emoji constants -CHECK_MARK = "✓" -CROSS_MARK = "❌" - -def get_saved_credentials(): - """Retrieve saved GitHub credentials from keyring.""" - try: - email = keyring.get_password("cursor-github", "email") - password = keyring.get_password("cursor-github", "password") - return email, password - except Exception: - return None, None - -def save_credentials(email, password): - """Save GitHub credentials to keyring.""" - try: - keyring.set_password("cursor-github", "email", email) - keyring.set_password("cursor-github", "password", password) - return True - except Exception: - return False - -def extract_auth_data(page, github_email=None): - """Extract authentication data from the page.""" - print(f"\n{Fore.CYAN}Checking cookies...{Fore.RESET}") - cookies = page.get_cookies() - print(f"Found {len(cookies)} cookies") - - for cookie in cookies: - print(f"Cookie: {cookie['name']} = {cookie['value'][:10]}...") - - auth_token = None - cursor_email = None - - # Try to get token from cookies with different separators - for cookie in cookies: - if cookie['name'] == 'WorkosCursorSessionToken': - value = cookie['value'] - if '::' in value: - auth_token = value.split('::')[1] - elif '%3A%3A' in value: - auth_token = value.split('%3A%3A')[1] - if auth_token: - print(f"{CHECK_MARK} Found auth token: {auth_token[:10]}...") - break - - # Try to get token from localStorage if not found in cookies - if not auth_token: - try: - local_storage = page.get_local_storage() - if 'WorkosCursorSessionToken' in local_storage: - value = local_storage['WorkosCursorSessionToken'] - if '::' in value: - auth_token = value.split('::')[1] - elif '%3A%3A' in value: - auth_token = value.split('%3A%3A')[1] - if auth_token: - print(f"{CHECK_MARK} Found auth token in localStorage: {auth_token[:10]}...") - except Exception as e: - print(f"{CROSS_MARK} Error accessing localStorage: {str(e)}") - - # Get cursor_email from cookies or use github_email as fallback - for cookie in cookies: - if cookie['name'] == 'cursor_email': - cursor_email = cookie['value'] - print(f"{CHECK_MARK} Found cursor_email: {cursor_email}") - break - - if not cursor_email and github_email: - cursor_email = github_email - print(f"{CHECK_MARK} Using GitHub email as fallback: {cursor_email}") - - if not auth_token or not cursor_email: - missing = [] - if not auth_token: - missing.append("auth_token") - if not cursor_email: - missing.append("cursor_email") - print(f"{CROSS_MARK} Could not extract: {', '.join(missing)}") - return None, None - - return auth_token, cursor_email - -def reset_trial(translator=None): - """Reset trial using GitHub authentication.""" - print(f"\n{Fore.CYAN}Starting GitHub trial reset...{Fore.RESET}") - - # Initialize browser - page = ChromiumPage() - - try: - # Get saved credentials - email, password = get_saved_credentials() - - if not email or not password: - print(f"{Fore.YELLOW}Please enter your GitHub credentials:{Fore.RESET}") - email = input("Email: ") - password = input("Password: ") - - # Save credentials if user wants - save = input("Save credentials for next time? (y/n): ").lower() == 'y' - if save: - if save_credentials(email, password): - print(f"{CHECK_MARK} Credentials saved successfully") - else: - print(f"{CROSS_MARK} Failed to save credentials") - - # Navigate to GitHub login - print(f"\n{Fore.CYAN}Navigating to GitHub login...{Fore.RESET}") - page.get('https://github.com/login') - - # Fill in login form - page.ele('input[name="login"]').input(email) - page.ele('input[name="password"]').input(password) - page.ele('input[name="commit"]').click() - - # Wait for login to complete - time.sleep(2) - - # Check if login was successful - if 'login' in page.url: - print(f"{CROSS_MARK} Login failed. Please check your credentials.") - return False - - print(f"{CHECK_MARK} Successfully logged in to GitHub") - - # Extract authentication data - auth_token, cursor_email = extract_auth_data(page, email) - if not auth_token or not cursor_email: - print(f"{CROSS_MARK} Could not extract authentication data") - return False - - # Initialize CursorAuth and save authentication data - cursor_auth = CursorAuth() - cursor_auth.set_access_token(auth_token) - cursor_auth.set_refresh_token(auth_token) # Using same token for both - cursor_auth.set_email(cursor_email) - - if not cursor_auth.verify_and_save(): - print(f"{CROSS_MARK} Failed to save authentication data") - return False - - print(f"{CHECK_MARK} Successfully saved authentication data") - - # Reset machine ID - print(f"\n{Fore.CYAN}Resetting machine ID...{Fore.RESET}") - resetter = MachineIDResetter() - resetter.reset() - print(f"{CHECK_MARK} Machine ID reset complete") - - print(f"\n{Fore.GREEN}Trial reset complete! You can now launch Cursor.{Fore.RESET}") - return True - - except Exception as e: - print(f"{CROSS_MARK} An error occurred: {str(e)}") - return False - - finally: - page.quit() \ No newline at end of file diff --git a/main.py b/main.py index cf19316..7d96c1b 100644 --- a/main.py +++ b/main.py @@ -10,12 +10,6 @@ import platform import requests import subprocess from config import get_config -import time -from cursor_register import CursorRegistration -from cursor_register_github import main as register_github -from cursor_register_google import main as register_google -from github_trial_reset import reset_trial as github_reset_trial -from utils import MachineIDResetter # Only import windll on Windows systems if platform.system() == 'Windows': @@ -375,23 +369,24 @@ def main(): print(f"{Fore.CYAN}{'═' * 50}{Style.RESET_ALL}") return elif choice == "1": - resetter = MachineIDResetter() - resetter.reset() - print(f"{Fore.GREEN}Machine ID reset complete!{Fore.RESET}") + import reset_machine_manual + reset_machine_manual.run(translator) + print_menu() elif choice == "2": - if github_reset_trial(): - print(f"{Fore.GREEN}GitHub trial reset completed successfully!{Fore.RESET}") - else: - print(f"{Fore.RED}GitHub trial reset failed.{Fore.RESET}") + import cursor_register + cursor_register.main(translator) + print_menu() elif choice == "3": - registration = CursorRegistration() - registration.register() + import cursor_register_google + cursor_register_google.main(translator) print_menu() elif choice == "4": - register_github() + import cursor_register_github + cursor_register_github.main(translator) print_menu() elif choice == "5": - register_google() + import cursor_register_manual + cursor_register_manual.main(translator) print_menu() elif choice == "6": import quit_cursor diff --git a/oauth_auth.py b/oauth_auth.py index 618a3e2..b917a33 100644 --- a/oauth_auth.py +++ b/oauth_auth.py @@ -610,8 +610,8 @@ class OAuthHandler: print(f"{Fore.CYAN}{EMOJI['INFO']} Redirecting to authenticator.cursor.sh...{Style.RESET_ALL}") # Explicitly navigate to the authentication page - self.browser.get("https://authenticator.cursor.sh/sign-up") - time.sleep(get_random_wait_time(self.config, 'page_load_wait')) + #self.browser.get("https://authenticator.cursor.sh/sign-up") + # time.sleep(get_random_wait_time(self.config, 'page_load_wait')) # Call handle_google_auth again to repeat the entire process print(f"{Fore.CYAN}{EMOJI['INFO']} Starting new Google authentication...{Style.RESET_ALL}") diff --git a/reset_machine_manual.py b/reset_machine_manual.py index 7083412..0fb8a4a 100644 --- a/reset_machine_manual.py +++ b/reset_machine_manual.py @@ -14,7 +14,6 @@ import configparser from new_signup import get_user_documents_path import traceback from config import get_config -from github_trial_reset import reset_trial as github_reset_trial # Initialize colorama init() @@ -692,30 +691,19 @@ class MachineIDResetter: return False def run(translator=None): - """Main function to run the reset process""" - try: - print(f"\n{Fore.CYAN}{EMOJI['RESET']} {translator.get('reset.starting_reset') if translator else 'Starting reset process...'}{Style.RESET_ALL}") - - # First, try GitHub trial reset - print(f"\n{Fore.CYAN}{EMOJI['INFO']} Attempting GitHub trial reset...{Style.RESET_ALL}") - if github_reset_trial(translator): - print(f"{Fore.GREEN}{EMOJI['SUCCESS']} GitHub trial reset completed successfully!{Style.RESET_ALL}") - else: - print(f"{Fore.YELLOW}{EMOJI['INFO']} GitHub trial reset failed, falling back to manual reset...{Style.RESET_ALL}") - - # Then proceed with manual reset - resetter = MachineIDResetter(translator) - if resetter.reset(): - print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {translator.get('reset.completed_successfully') if translator else 'Reset completed successfully!'}{Style.RESET_ALL}") - else: - print(f"{Fore.RED}{EMOJI['ERROR']} {translator.get('reset.failed') if translator else 'Reset failed!'}{Style.RESET_ALL}") - - except Exception as e: - print(f"{Fore.RED}{EMOJI['ERROR']} {translator.get('reset.error_occurred', error=str(e)) if translator else f'An error occurred: {str(e)}'}{Style.RESET_ALL}") - print(f"{Fore.YELLOW}{EMOJI['INFO']} {translator.get('reset.stack_trace')}: {traceback.format_exc()}{Style.RESET_ALL}") + config = get_config(translator) + if not config: return False - - return True + print(f"\n{Fore.CYAN}{'='*50}{Style.RESET_ALL}") + print(f"{Fore.CYAN}{EMOJI['RESET']} {translator.get('reset.title')}{Style.RESET_ALL}") + print(f"{Fore.CYAN}{'='*50}{Style.RESET_ALL}") + + resetter = MachineIDResetter(translator) # Correctly pass translator + resetter.reset_machine_ids() + + print(f"\n{Fore.CYAN}{'='*50}{Style.RESET_ALL}") + input(f"{EMOJI['INFO']} {translator.get('reset.press_enter')}...") if __name__ == "__main__": - run() \ No newline at end of file + from main import translator as main_translator + run(main_translator) \ No newline at end of file