|
41 | 41 | margin-left: 20px; |
42 | 42 | } |
43 | 43 | #settings-btn { |
44 | | - margin-left: 10px; |
| 44 | + margin-left: auto; |
45 | 45 | margin-top: 20px; |
46 | 46 | margin-bottom: 20px; |
47 | 47 | background-color: #666; |
|
59 | 59 | #settings-btn:hover { |
60 | 60 | background-color: #555; |
61 | 61 | } |
| 62 | + #auth-section { |
| 63 | + float: right; |
| 64 | + margin-right: 20px; |
| 65 | + display: flex; |
| 66 | + align-items: center; |
| 67 | + font-size: 14px; |
| 68 | + } |
| 69 | + #login-btn { |
| 70 | + background-color: #4c84af; |
| 71 | + border: none; |
| 72 | + color: white; |
| 73 | + padding: 12px 16px; |
| 74 | + text-align: center; |
| 75 | + text-decoration: none; |
| 76 | + display: inline-block; |
| 77 | + font-size: 14px; |
| 78 | + cursor: pointer; |
| 79 | + } |
| 80 | + #login-btn:hover { |
| 81 | + background-color: #3a6a8a; |
| 82 | + } |
| 83 | + #user-info { |
| 84 | + color: #333; |
| 85 | + } |
| 86 | + #logout-link { |
| 87 | + color: #666; |
| 88 | + text-decoration: underline; |
| 89 | + cursor: pointer; |
| 90 | + margin-left: 5px; |
| 91 | + } |
| 92 | + #logout-link:hover { |
| 93 | + color: #333; |
| 94 | + } |
62 | 95 | #unselect-all { |
63 | 96 | margin-left: 20px; |
64 | 97 | cursor: pointer; |
|
389 | 422 |
|
390 | 423 | let currentSettings = { ...DEFAULT_SETTINGS }; |
391 | 424 |
|
| 425 | + // Authentication functionality |
| 426 | + async function updateAuthUI() { |
| 427 | + try { |
| 428 | + if (typeof puter === 'undefined' || !puter.auth) { |
| 429 | + // Puter not loaded yet, show login button |
| 430 | + $('#login-btn').show(); |
| 431 | + $('#user-info').hide(); |
| 432 | + return; |
| 433 | + } |
| 434 | + |
| 435 | + const isSignedIn = await puter.auth.isSignedIn(); |
| 436 | + |
| 437 | + if (isSignedIn) { |
| 438 | + let user = await puter.auth.getUser(); |
| 439 | + // User is signed in, show username and logout option |
| 440 | + $('#login-btn').hide(); |
| 441 | + $('#user-info').show(); |
| 442 | + |
| 443 | + // Get user info - for now we'll use a placeholder |
| 444 | + // In a real app, you might want to get the actual username from puter |
| 445 | + $('#username').text(user.username); // You may need to get actual username from puter API |
| 446 | + } else { |
| 447 | + // User is not signed in, show login button |
| 448 | + $('#login-btn').show(); |
| 449 | + $('#user-info').hide(); |
| 450 | + } |
| 451 | + } catch (error) { |
| 452 | + console.error('Error checking auth state:', error); |
| 453 | + // If there's an error, default to showing login button |
| 454 | + $('#login-btn').show(); |
| 455 | + $('#user-info').hide(); |
| 456 | + } |
| 457 | + } |
| 458 | + |
392 | 459 | // Load settings from localStorage or use defaults |
393 | 460 | function loadSettings() { |
394 | 461 | const saved = localStorage.getItem('puter-test-settings'); |
|
439 | 506 | if (typeof puter !== 'undefined' && puter.setAPIOrigin) { |
440 | 507 | puter.setAPIOrigin(currentSettings.apiOrigin); |
441 | 508 | } |
| 509 | + |
| 510 | + // Update auth UI after puter is loaded |
| 511 | + await updateAuthUI(); |
442 | 512 | } catch (error) { |
443 | 513 | console.error('Failed to load Puter.js:', error); |
444 | 514 | alert('Failed to load Puter.js. Please check the URL in settings.'); |
|
961 | 1031 | // Initialize the counter display |
962 | 1032 | updateMasterCheckboxState(); |
963 | 1033 |
|
| 1034 | + // Login functionality |
| 1035 | + $('#login-btn').click(async () => { |
| 1036 | + try { |
| 1037 | + $('#login-btn').prop('disabled', true); |
| 1038 | + await puter.auth.signIn(); |
| 1039 | + await updateAuthUI(); |
| 1040 | + } catch (error) { |
| 1041 | + console.error('Login error:', error); |
| 1042 | + alert('Login failed. Please try again.'); |
| 1043 | + } finally { |
| 1044 | + $('#login-btn').prop('disabled', false); |
| 1045 | + } |
| 1046 | + }); |
| 1047 | + |
| 1048 | + // Logout functionality |
| 1049 | + $('#logout-link').click(async () => { |
| 1050 | + try { |
| 1051 | + await puter.auth.signOut(); |
| 1052 | + await updateAuthUI(); |
| 1053 | + } catch (error) { |
| 1054 | + console.error('Logout error:', error); |
| 1055 | + alert('Logout failed. Please try again.'); |
| 1056 | + } |
| 1057 | + }); |
| 1058 | + |
| 1059 | + // Initialize auth UI after puter is loaded |
| 1060 | + updateAuthUI(); |
| 1061 | + |
964 | 1062 | // Settings modal functionality |
965 | 1063 | $('#settings-btn').click(() => { |
966 | 1064 | // Populate modal with current settings |
|
1014 | 1112 | <input type="checkbox" id="master-checkbox" checked style="margin-right: 5px; transform: scale(1.2);"> |
1015 | 1113 | </label> |
1016 | 1114 | <span id="test-counter"></span> |
1017 | | - <div style="flex: 1;"> |
| 1115 | + <div style="flex: 1; display: flex; align-items: center;"> |
1018 | 1116 | <button id="run-tests" style="margin-right: 10px;">Run Tests</button> |
1019 | 1117 | <span id="reset-results" style="margin-right: 20px; cursor: pointer; color: #666; text-decoration: underline; font-size: 14px;">Reset results</span> |
1020 | 1118 | <button id="settings-btn">Settings</button> |
| 1119 | + <div id="auth-section"> |
| 1120 | + <button id="login-btn" style="display: none;">Login</button> |
| 1121 | + <div id="user-info" style="display: none;"> |
| 1122 | + <span id="username"></span> |
| 1123 | + <span id="logout-link">(logout)</span> |
| 1124 | + </div> |
| 1125 | + </div> |
1021 | 1126 | </div> |
1022 | 1127 | </nav> |
1023 | 1128 |
|
|
0 commit comments