Skip to content
Closed
Show file tree
Hide file tree
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
75 changes: 69 additions & 6 deletions CulinaryCommandApp/Components/Pages/Users/UserList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ else
disabled="@(!priv)">
Delete
</button>
@if (!u.IsActive)
{
<button type="button"
class="btn btn-sm btn-outline-primary"
disabled="@(_resendingId == u.Id)"
@onclick="() => ResendInvite(u.Id)"
@onclick:stopPropagation="true"
@onclick:preventDefault="true">
@(_resendingId == u.Id ? "Sending..." : "Resend Invite")
</button>
}
</div>

</div>
Expand Down Expand Up @@ -188,6 +199,10 @@ else
private string? _toast;
private CancellationTokenSource? _toastCts;
private Dictionary<int, string> _locNamesById = new();
private int? _resendingId;
private string? _error;
private readonly SemaphoreSlim _loadGate = new(1, 1);
private bool _disposed;


protected override async Task OnInitializedAsync()
Expand Down Expand Up @@ -218,7 +233,7 @@ else

LocationState.OnChange += RefreshUsers;

await LoadUsersAsync();
await LoadUsersSafeAsync();
}

private void UpdatePriv()
Expand All @@ -244,15 +259,31 @@ else

private void RefreshUsers()
{
_ = InvokeAsync(async () =>
// run on the Blazor sync context, but DO NOT start overlapping DB calls
_ = InvokeAsync(RefreshUsersAsync);
}

private async Task RefreshUsersAsync()
{
await LoadUsersSafeAsync();
if (!_disposed) StateHasChanged();
}

private async Task LoadUsersSafeAsync()
{
await _loadGate.WaitAsync();
try
{
await LoadUsersAsync();

_locNamesById = LocationState.ManagedLocations
.Where(l => l != null)
.ToDictionary(l => l.Id, l => l.Name);

StateHasChanged();
});
}
finally
{
_loadGate.Release();
}
}


Expand All @@ -264,7 +295,7 @@ else
if (!priv) return;

await Users.DeleteUserAsync(id);
await LoadUsersAsync();
await LoadUsersSafeAsync();
await InvokeAsync(StateHasChanged);
}

Expand All @@ -289,9 +320,11 @@ else

public void Dispose()
{
_disposed = true;
LocationState.OnChange -= RefreshUsers;
_toastCts?.Cancel();
_toastCts?.Dispose();
_loadGate.Dispose();
}

private async Task CopyInvite(string url)
Expand Down Expand Up @@ -352,4 +385,34 @@ else
_ => "bg-dark"
};
}

private async Task ResendInvite(int userId)
{
_error = null;
_resendingId = userId;

try
{
var ctx = await UserCtx.GetAsync();
if (ctx?.User is null)
throw new InvalidOperationException("Not authenticated.");

await Users.ResendInviteAsync(userId, ctx.User.Id);

// refresh list so new token appears + pending stays accurate
await LoadUsersSafeAsync();

ShowToast("Invite resent!");
}
catch (Exception ex)
{
_error = ex.Message;
ShowToast("Invite resend failed");
}
finally
{
_resendingId = null;
StateHasChanged();
}
}
}
1 change: 1 addition & 0 deletions CulinaryCommandApp/CulinaryCommand.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.3.22" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Google.GenAI" Version="0.13.1" />
<PackageReference Include="MailKit" Version="4.15.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.3.9" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
Expand Down
42 changes: 36 additions & 6 deletions CulinaryCommandApp/Services/EmailSender.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
using MailKit.Net.Smtp;
using MailKit.Security;
using Microsoft.Extensions.Configuration;
using MimeKit;

namespace CulinaryCommand.Services
{
public class EmailSender : IEmailSender
{
private readonly IConfiguration _config;

public EmailSender(IConfiguration config)
{
_config = config;
}

public async Task SendEmailAsync(string toEmail, string subject, string body)
{
// TODO: Replace with real SMTP or SendGrid logic
Console.WriteLine("=== EMAIL SENT ===");
Console.WriteLine($"To: {toEmail}");
Console.WriteLine($"Subject: {subject}");
Console.WriteLine(body);
var from = _config["Email:From"];
var host = _config["Email:SmtpHost"];
var portStr = _config["Email:SmtpPort"];
var user = _config["Email:SmtpUser"];
var pass = _config["Email:SmtpPass"];

if (string.IsNullOrWhiteSpace(from) ||
string.IsNullOrWhiteSpace(host) ||
string.IsNullOrWhiteSpace(user) ||
string.IsNullOrWhiteSpace(pass))
throw new InvalidOperationException("Email SMTP configuration is missing.");

var port = int.TryParse(portStr, out var p) ? p : 587;

var msg = new MimeMessage();
msg.From.Add(MailboxAddress.Parse(from));
msg.To.Add(MailboxAddress.Parse(toEmail));
msg.Subject = subject;
msg.Body = new BodyBuilder { HtmlBody = body }.ToMessageBody();

await Task.CompletedTask;
using var client = new SmtpClient();
await client.ConnectAsync(host, port, SecureSocketOptions.StartTls);
await client.AuthenticateAsync(user, pass);
await client.SendAsync(msg);
await client.DisconnectAsync(true);
}
}
}
Loading
Loading