From 45a6bc8ae21862bff9b0e171a14a0052cb322692 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Tue, 26 Nov 2024 11:23:39 +0100 Subject: [PATCH] Add QR Code with link to invitation email This will help onboarding via the app. --- BTCPayServer/BTCPayServer.csproj | 5 +---- BTCPayServer/Components/QRCode/QRCode.cs | 1 - BTCPayServer/Extensions/EmailSenderExtensions.cs | 12 +++++++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index d2779c668..7d4ef66c5 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -49,7 +49,7 @@ - + @@ -60,9 +60,6 @@ - - - diff --git a/BTCPayServer/Components/QRCode/QRCode.cs b/BTCPayServer/Components/QRCode/QRCode.cs index 13f7d50b0..29ed5ba7c 100644 --- a/BTCPayServer/Components/QRCode/QRCode.cs +++ b/BTCPayServer/Components/QRCode/QRCode.cs @@ -1,5 +1,4 @@ using System; -using System.Drawing; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewComponents; diff --git a/BTCPayServer/Extensions/EmailSenderExtensions.cs b/BTCPayServer/Extensions/EmailSenderExtensions.cs index f0e2367e0..cd5466a82 100644 --- a/BTCPayServer/Extensions/EmailSenderExtensions.cs +++ b/BTCPayServer/Extensions/EmailSenderExtensions.cs @@ -1,6 +1,7 @@ using System.Text.Encodings.Web; using BTCPayServer.Services.Mails; using MimeKit; +using QRCoder; namespace BTCPayServer.Services { @@ -42,7 +43,7 @@ namespace BTCPayServer.Services public static void SendInvitation(this IEmailSender emailSender, MailboxAddress address, string link) { emailSender.SendEmail(address, "Invitation", CreateEmailBody( - $"Please complete your account setup by clicking this link.")); + $"

Please complete your account setup by clicking this link.

You can also use the BTCPay Server app and scan this QR code when connecting:

{GetQrCodeImg(link)}")); } public static void SendNewUserInfo(this IEmailSender emailSender, MailboxAddress address, string newUserInfo, string link) @@ -56,5 +57,14 @@ namespace BTCPayServer.Services emailSender.SendEmail(address, userInfo, CreateEmailBody( $"{userInfo}. You can view the store users here: Store users")); } + + private static string GetQrCodeImg(string data) + { + using var qrGenerator = new QRCodeGenerator(); + using var qrCodeData = qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q); + using var qrCode = new Base64QRCode(qrCodeData); + var base64 = qrCode.GetGraphic(20); + return $"{data}"; + } } }