diff --git a/github_trial_reset.py b/github_trial_reset.py new file mode 100644 index 0000000..f75892c --- /dev/null +++ b/github_trial_reset.py @@ -0,0 +1,170 @@ +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 7d96c1b..cf19316 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,12 @@ 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': @@ -369,24 +375,23 @@ def main(): print(f"{Fore.CYAN}{'═' * 50}{Style.RESET_ALL}") return elif choice == "1": - import reset_machine_manual - reset_machine_manual.run(translator) - print_menu() + resetter = MachineIDResetter() + resetter.reset() + print(f"{Fore.GREEN}Machine ID reset complete!{Fore.RESET}") elif choice == "2": - import cursor_register - cursor_register.main(translator) - print_menu() + 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}") elif choice == "3": - import cursor_register_google - cursor_register_google.main(translator) + registration = CursorRegistration() + registration.register() print_menu() elif choice == "4": - import cursor_register_github - cursor_register_github.main(translator) + register_github() print_menu() elif choice == "5": - import cursor_register_manual - cursor_register_manual.main(translator) + register_google() print_menu() elif choice == "6": import quit_cursor