Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions Intersect.Editor/Forms/FrmUploadToServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void LoadSettings()
{
_selectedDirectory = savedDirectory;
txtDirectory.Text = savedDirectory;
btnUpload.Enabled = true;
// Don't enable upload here - let UpdateAuthenticationStatus handle it
}

var rawTokenResponse = Preferences.LoadPreference(nameof(TokenResponse));
Expand Down Expand Up @@ -93,13 +93,17 @@ private void UpdateAuthenticationStatus()

if (_tokenResponse != null)
{
lblStatus.Text = "✓ Authenticated";
lblStatus.Text = "✓ Authenticated - Ready to upload";
btnLogin.Text = "Re-Login";
// Only enable upload if we have authentication AND a directory selected
btnUpload.Enabled = !string.IsNullOrWhiteSpace(_selectedDirectory) && Directory.Exists(_selectedDirectory);
}
else
{
lblStatus.Text = "⚠ Not authenticated - click Login to authenticate";
lblStatus.Text = "⚠ Not authenticated - Please click the Login button below to authenticate";
btnLogin.Text = "Login";
// Disable upload when not authenticated
btnUpload.Enabled = false;
}

// Login button is always visible now
Expand All @@ -108,6 +112,7 @@ private void UpdateAuthenticationStatus()
// Force UI refresh
btnLogin.Refresh();
lblStatus.Refresh();
btnUpload.Refresh();
}

private bool IsTokenExpired(TokenResponse token)
Expand Down Expand Up @@ -330,12 +335,26 @@ private void btnBrowse_Click(object sender, EventArgs e)
{
_selectedDirectory = folderDialog.SelectedPath;
txtDirectory.Text = _selectedDirectory;
btnUpload.Enabled = true;
// Only enable upload if authenticated
btnUpload.Enabled = _tokenResponse != null && !IsTokenExpired(_tokenResponse);
}
}

private async void btnUpload_Click(object sender, EventArgs e)
{
// Check authentication first
if (_tokenResponse == null || IsTokenExpired(_tokenResponse))
{
DarkMessageBox.ShowError(
"You must login before uploading.\n\nPlease click the 'Login' button below to authenticate.",
"Authentication Required",
DarkDialogButton.Ok,
Icon
);
UpdateAuthenticationStatus();
return;
}

if (string.IsNullOrWhiteSpace(txtServerUrl.Text))
{
DarkMessageBox.ShowError(
Expand Down Expand Up @@ -699,12 +718,17 @@ private async Task PerformUpload()
Timeout = TimeSpan.FromMinutes(30)
};

if (_tokenResponse != null)
// Double-check authentication before starting upload
if (_tokenResponse == null || string.IsNullOrWhiteSpace(_tokenResponse.AccessToken))
{
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", _tokenResponse.AccessToken);
throw new Exception(
"Cannot upload without authentication. Please login first."
);
}

httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", _tokenResponse.AccessToken);

const int batchSize = 10;
const int maxRetries = 3;

Expand Down
Loading