mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 22:25:28 +01:00
Fix email sending on registration crash (#1454)
This commit is contained in:
parent
841cf61c92
commit
d47e225dce
6 changed files with 12 additions and 12 deletions
|
@ -463,7 +463,7 @@ namespace BTCPayServer.Controllers
|
||||||
|
|
||||||
_eventAggregator.Publish(new UserRegisteredEvent()
|
_eventAggregator.Publish(new UserRegisteredEvent()
|
||||||
{
|
{
|
||||||
Request = Request,
|
RequestUri = Request.GetAbsoluteRootUri(),
|
||||||
User = user,
|
User = user,
|
||||||
Admin = RegisteredAdmin
|
Admin = RegisteredAdmin
|
||||||
});
|
});
|
||||||
|
|
|
@ -148,7 +148,7 @@ namespace BTCPayServer.Controllers.GreenField
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_eventAggregator.Publish(new UserRegisteredEvent() {Request = Request, User = user, Admin = request.IsAdministrator is true });
|
_eventAggregator.Publish(new UserRegisteredEvent() {RequestUri = Request.GetAbsoluteRootUri(), User = user, Admin = request.IsAdministrator is true });
|
||||||
return CreatedAtAction(string.Empty, user);
|
return CreatedAtAction(string.Empty, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ namespace BTCPayServer.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
var callbackUrl = _linkGenerator.EmailConfirmationLink(user.Id, code, Request.Scheme, Request.HttpContext);
|
var callbackUrl = _linkGenerator.EmailConfirmationLink(user.Id, code, Request.Scheme, Request.Host, Request.PathBase);
|
||||||
var email = user.Email;
|
var email = user.Email;
|
||||||
_EmailSenderFactory.GetEmailSender().SendEmailConfirmation(email, callbackUrl);
|
_EmailSenderFactory.GetEmailSender().SendEmailConfirmation(email, callbackUrl);
|
||||||
TempData[WellKnownTempData.SuccessMessage] = "Verification email sent. Please check your email.";
|
TempData[WellKnownTempData.SuccessMessage] = "Verification email sent. Please check your email.";
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
@ -6,7 +7,7 @@ namespace BTCPayServer.Events
|
||||||
public class UserRegisteredEvent
|
public class UserRegisteredEvent
|
||||||
{
|
{
|
||||||
public ApplicationUser User { get; set; }
|
public ApplicationUser User { get; set; }
|
||||||
public HttpRequest Request { get; set; }
|
|
||||||
public bool Admin { get; set; }
|
public bool Admin { get; set; }
|
||||||
|
public Uri RequestUri { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using BTCPayServer.Controllers;
|
using BTCPayServer.Controllers;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
@ -10,10 +7,10 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
{
|
{
|
||||||
public static class UrlHelperExtensions
|
public static class UrlHelperExtensions
|
||||||
{
|
{
|
||||||
public static string EmailConfirmationLink(this LinkGenerator urlHelper, string userId, string code, string scheme, HttpContext context)
|
public static string EmailConfirmationLink(this LinkGenerator urlHelper, string userId, string code, string scheme, HostString host, string pathbase)
|
||||||
{
|
{
|
||||||
return urlHelper.GetUriByAction(context, nameof(AccountController.ConfirmEmail), "Account",
|
return urlHelper.GetUriByAction( nameof(AccountController.ConfirmEmail), "Account",
|
||||||
new {userId, code}, scheme);
|
new {userId, code}, scheme, host, pathbase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ResetPasswordCallbackLink(this IUrlHelper urlHelper, string userId, string code, string scheme)
|
public static string ResetPasswordCallbackLink(this IUrlHelper urlHelper, string userId, string code, string scheme)
|
||||||
|
|
|
@ -5,6 +5,7 @@ using BTCPayServer.Events;
|
||||||
using BTCPayServer.Logging;
|
using BTCPayServer.Logging;
|
||||||
using BTCPayServer.Services;
|
using BTCPayServer.Services;
|
||||||
using BTCPayServer.Services.Mails;
|
using BTCPayServer.Services.Mails;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
|
@ -40,8 +41,9 @@ namespace BTCPayServer.HostedServices
|
||||||
Logs.PayServer.LogInformation($"A new user just registered {userRegisteredEvent.User.Email} {(userRegisteredEvent.Admin ? "(admin)" : "")}");
|
Logs.PayServer.LogInformation($"A new user just registered {userRegisteredEvent.User.Email} {(userRegisteredEvent.Admin ? "(admin)" : "")}");
|
||||||
if (!userRegisteredEvent.User.EmailConfirmed && userRegisteredEvent.User.RequiresEmailConfirmation)
|
if (!userRegisteredEvent.User.EmailConfirmed && userRegisteredEvent.User.RequiresEmailConfirmation)
|
||||||
{
|
{
|
||||||
|
|
||||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(userRegisteredEvent.User);
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(userRegisteredEvent.User);
|
||||||
var callbackUrl = _generator.EmailConfirmationLink(userRegisteredEvent.User.Id, code, userRegisteredEvent.Request.Scheme, userRegisteredEvent.Request.HttpContext);
|
var callbackUrl = _generator.EmailConfirmationLink(userRegisteredEvent.User.Id, code, userRegisteredEvent.RequestUri.Scheme, new HostString(userRegisteredEvent.RequestUri.Host, userRegisteredEvent.RequestUri.Port), userRegisteredEvent.RequestUri.PathAndQuery);
|
||||||
|
|
||||||
_emailSenderFactory.GetEmailSender()
|
_emailSenderFactory.GetEmailSender()
|
||||||
.SendEmailConfirmation(userRegisteredEvent.User.Email, callbackUrl);
|
.SendEmailConfirmation(userRegisteredEvent.User.Email, callbackUrl);
|
||||||
|
|
Loading…
Add table
Reference in a new issue