mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-12 02:08:32 +01:00
Redirect first run to register, redirect unlogged to login
This commit is contained in:
parent
5650b8560d
commit
55dd8da284
10 changed files with 65 additions and 15 deletions
|
@ -18,7 +18,7 @@ namespace BTCPayServer.Tests
|
||||||
[Trait("Selenium", "Selenium")]
|
[Trait("Selenium", "Selenium")]
|
||||||
public class CheckoutUITests
|
public class CheckoutUITests
|
||||||
{
|
{
|
||||||
public const int TestTimeout = 60_000;
|
public const int TestTimeout = TestUtils.TestTimeout;
|
||||||
public CheckoutUITests(ITestOutputHelper helper)
|
public CheckoutUITests(ITestOutputHelper helper)
|
||||||
{
|
{
|
||||||
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
|
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
|
||||||
|
@ -32,6 +32,7 @@ namespace BTCPayServer.Tests
|
||||||
using (var s = SeleniumTester.Create())
|
using (var s = SeleniumTester.Create())
|
||||||
{
|
{
|
||||||
await s.StartAsync();
|
await s.StartAsync();
|
||||||
|
s.GoToRegister();
|
||||||
s.RegisterNewUser();
|
s.RegisterNewUser();
|
||||||
var store = s.CreateNewStore();
|
var store = s.CreateNewStore();
|
||||||
s.AddDerivationScheme("BTC");
|
s.AddDerivationScheme("BTC");
|
||||||
|
@ -80,6 +81,7 @@ namespace BTCPayServer.Tests
|
||||||
using (var s = SeleniumTester.Create())
|
using (var s = SeleniumTester.Create())
|
||||||
{
|
{
|
||||||
await s.StartAsync();
|
await s.StartAsync();
|
||||||
|
s.GoToRegister();
|
||||||
s.RegisterNewUser();
|
s.RegisterNewUser();
|
||||||
var store = s.CreateNewStore();
|
var store = s.CreateNewStore();
|
||||||
s.AddDerivationScheme("BTC");
|
s.AddDerivationScheme("BTC");
|
||||||
|
@ -109,6 +111,7 @@ namespace BTCPayServer.Tests
|
||||||
using (var s = SeleniumTester.Create())
|
using (var s = SeleniumTester.Create())
|
||||||
{
|
{
|
||||||
await s.StartAsync();
|
await s.StartAsync();
|
||||||
|
s.GoToRegister();
|
||||||
s.RegisterNewUser();
|
s.RegisterNewUser();
|
||||||
var store = s.CreateNewStore();
|
var store = s.CreateNewStore();
|
||||||
s.AddDerivationScheme("BTC");
|
s.AddDerivationScheme("BTC");
|
||||||
|
@ -152,6 +155,7 @@ namespace BTCPayServer.Tests
|
||||||
using (var s = SeleniumTester.Create())
|
using (var s = SeleniumTester.Create())
|
||||||
{
|
{
|
||||||
await s.StartAsync();
|
await s.StartAsync();
|
||||||
|
s.GoToRegister();
|
||||||
s.RegisterNewUser();
|
s.RegisterNewUser();
|
||||||
var store = s.CreateNewStore();
|
var store = s.CreateNewStore();
|
||||||
s.AddInternalLightningNode("BTC");
|
s.AddInternalLightningNode("BTC");
|
||||||
|
|
|
@ -28,8 +28,11 @@ namespace BTCPayServer.Tests
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assert.NotEmpty(driver.FindElements(By.ClassName("navbar-brand")));
|
Assert.NotEmpty(driver.FindElements(By.ClassName("navbar-brand")));
|
||||||
foreach (var dangerAlert in driver.FindElements(By.ClassName("alert-danger")))
|
if (driver.PageSource.Contains("alert-danger"))
|
||||||
Assert.False(dangerAlert.Displayed, "No alert should be displayed");
|
{
|
||||||
|
foreach (var dangerAlert in driver.FindElements(By.ClassName("alert-danger")))
|
||||||
|
Assert.False(dangerAlert.Displayed, "No alert should be displayed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,7 +66,7 @@ namespace BTCPayServer.Tests
|
||||||
Logs.Tester.LogInformation("Selenium: Browsing to " + Server.PayTester.ServerUri);
|
Logs.Tester.LogInformation("Selenium: Browsing to " + Server.PayTester.ServerUri);
|
||||||
Logs.Tester.LogInformation($"Selenium: Resolution {Driver.Manage().Window.Size}");
|
Logs.Tester.LogInformation($"Selenium: Resolution {Driver.Manage().Window.Size}");
|
||||||
Driver.Manage().Timeouts().ImplicitWait = ImplicitWait;
|
Driver.Manage().Timeouts().ImplicitWait = ImplicitWait;
|
||||||
Driver.Navigate().GoToUrl(Server.PayTester.ServerUri);
|
GoToRegister();
|
||||||
Driver.AssertNoError();
|
Driver.AssertNoError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +76,13 @@ namespace BTCPayServer.Tests
|
||||||
return Server.PayTester.ServerUri.AbsoluteUri.WithoutEndingSlash() + relativeLink.WithStartingSlash();
|
return Server.PayTester.ServerUri.AbsoluteUri.WithoutEndingSlash() + relativeLink.WithStartingSlash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void GoToRegister()
|
||||||
|
{
|
||||||
|
Driver.Navigate().GoToUrl(this.Link("/Account/Register"));
|
||||||
|
}
|
||||||
public string RegisterNewUser(bool isAdmin = false)
|
public string RegisterNewUser(bool isAdmin = false)
|
||||||
{
|
{
|
||||||
var usr = RandomUtils.GetUInt256().ToString().Substring(64 - 20) + "@a.com";
|
var usr = RandomUtils.GetUInt256().ToString().Substring(64 - 20) + "@a.com";
|
||||||
Driver.FindElement(By.Id("Register")).Click();
|
|
||||||
Driver.FindElement(By.Id("Email")).SendKeys(usr);
|
Driver.FindElement(By.Id("Email")).SendKeys(usr);
|
||||||
Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
||||||
Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("123456");
|
Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("123456");
|
||||||
|
|
|
@ -46,8 +46,7 @@ namespace BTCPayServer.Tests
|
||||||
var email = s.RegisterNewUser();
|
var email = s.RegisterNewUser();
|
||||||
s.Driver.FindElement(By.Id("Logout")).Click();
|
s.Driver.FindElement(By.Id("Logout")).Click();
|
||||||
s.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
s.Driver.FindElement(By.Id("Login")).Click();
|
Assert.Contains("Account/Login", s.Driver.Url);
|
||||||
s.Driver.AssertNoError();
|
|
||||||
|
|
||||||
s.Driver.Navigate().GoToUrl(s.Link("/invoices"));
|
s.Driver.Navigate().GoToUrl(s.Link("/invoices"));
|
||||||
Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url);
|
Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url);
|
||||||
|
@ -76,7 +75,6 @@ namespace BTCPayServer.Tests
|
||||||
s.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
|
|
||||||
//Log In With New Password
|
//Log In With New Password
|
||||||
s.Driver.FindElement(By.Id("Login")).Click();
|
|
||||||
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
||||||
s.Driver.FindElement(By.Id("Password")).SendKeys("abc???");
|
s.Driver.FindElement(By.Id("Password")).SendKeys("abc???");
|
||||||
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
||||||
|
@ -91,7 +89,6 @@ namespace BTCPayServer.Tests
|
||||||
|
|
||||||
static void LogIn(SeleniumTester s, string email)
|
static void LogIn(SeleniumTester s, string email)
|
||||||
{
|
{
|
||||||
s.Driver.FindElement(By.Id("Login")).Click();
|
|
||||||
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
||||||
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
||||||
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
||||||
|
@ -208,7 +205,7 @@ namespace BTCPayServer.Tests
|
||||||
Assert.Contains("ReturnUrl", s.Driver.Url);
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
||||||
Assert.Contains("ReturnUrl", s.Driver.Url);
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
s.Driver.Navigate().GoToUrl(s.Link("/"));
|
s.GoToRegister();
|
||||||
// When logged we should not be able to access store and invoice details
|
// When logged we should not be able to access store and invoice details
|
||||||
var bob = s.RegisterNewUser();
|
var bob = s.RegisterNewUser();
|
||||||
s.Driver.Navigate().GoToUrl(storeUrl);
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
||||||
|
@ -252,7 +249,7 @@ namespace BTCPayServer.Tests
|
||||||
await s.StartAsync();
|
await s.StartAsync();
|
||||||
s.Driver.Navigate().GoToUrl(s.Link("/api-access-request"));
|
s.Driver.Navigate().GoToUrl(s.Link("/api-access-request"));
|
||||||
Assert.Contains("ReturnUrl", s.Driver.Url);
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
s.Driver.Navigate().GoToUrl(s.Link("/"));
|
s.GoToRegister();
|
||||||
var alice = s.RegisterNewUser();
|
var alice = s.RegisterNewUser();
|
||||||
var store = s.CreateNewStore().storeName;
|
var store = s.CreateNewStore().storeName;
|
||||||
s.AddDerivationScheme();
|
s.AddDerivationScheme();
|
||||||
|
|
|
@ -398,7 +398,9 @@ namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
await _RoleManager.CreateAsync(new IdentityRole(Roles.ServerAdmin));
|
await _RoleManager.CreateAsync(new IdentityRole(Roles.ServerAdmin));
|
||||||
await _userManager.AddToRoleAsync(user, Roles.ServerAdmin);
|
await _userManager.AddToRoleAsync(user, Roles.ServerAdmin);
|
||||||
|
var settings = await _SettingsRepository.GetSettingAsync<ThemeSettings>();
|
||||||
|
settings.FirstRun = false;
|
||||||
|
await _SettingsRepository.UpdateSetting<ThemeSettings>(settings);
|
||||||
if(_Options.DisableRegistration)
|
if(_Options.DisableRegistration)
|
||||||
{
|
{
|
||||||
// Once the admin user has been created lock subsequent user registrations (needs to be disabled for unit tests that require multiple users).
|
// Once the admin user has been created lock subsequent user registrations (needs to be disabled for unit tests that require multiple users).
|
||||||
|
|
|
@ -12,6 +12,8 @@ using Newtonsoft.Json;
|
||||||
using BTCPayServer.Services;
|
using BTCPayServer.Services;
|
||||||
using BTCPayServer.HostedServices;
|
using BTCPayServer.HostedServices;
|
||||||
using BTCPayServer.Services.Apps;
|
using BTCPayServer.Services.Apps;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using BTCPayServer.Data;
|
||||||
|
|
||||||
namespace BTCPayServer.Controllers
|
namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
|
@ -20,11 +22,15 @@ namespace BTCPayServer.Controllers
|
||||||
private readonly CssThemeManager _cachedServerSettings;
|
private readonly CssThemeManager _cachedServerSettings;
|
||||||
|
|
||||||
public IHttpClientFactory HttpClientFactory { get; }
|
public IHttpClientFactory HttpClientFactory { get; }
|
||||||
|
SignInManager<ApplicationUser> SignInManager { get; }
|
||||||
|
|
||||||
public HomeController(IHttpClientFactory httpClientFactory, CssThemeManager cachedServerSettings)
|
public HomeController(IHttpClientFactory httpClientFactory,
|
||||||
|
CssThemeManager cachedServerSettings,
|
||||||
|
SignInManager<ApplicationUser> signInManager)
|
||||||
{
|
{
|
||||||
HttpClientFactory = httpClientFactory;
|
HttpClientFactory = httpClientFactory;
|
||||||
_cachedServerSettings = cachedServerSettings;
|
_cachedServerSettings = cachedServerSettings;
|
||||||
|
SignInManager = signInManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ViewResult> GoToApp(string appId, AppType? appType)
|
private async Task<ViewResult> GoToApp(string appId, AppType? appType)
|
||||||
|
@ -71,14 +77,26 @@ namespace BTCPayServer.Controllers
|
||||||
|
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
|
if (_cachedServerSettings.FirstRun)
|
||||||
|
{
|
||||||
|
return RedirectToAction(nameof(AccountController.Register), "Account");
|
||||||
|
}
|
||||||
var matchedDomainMapping = _cachedServerSettings.DomainToAppMapping.FirstOrDefault(item =>
|
var matchedDomainMapping = _cachedServerSettings.DomainToAppMapping.FirstOrDefault(item =>
|
||||||
item.Domain.Equals(Request.Host.Host, StringComparison.InvariantCultureIgnoreCase));
|
item.Domain.Equals(Request.Host.Host, StringComparison.InvariantCultureIgnoreCase));
|
||||||
if (matchedDomainMapping != null)
|
if (matchedDomainMapping != null)
|
||||||
{
|
{
|
||||||
return await GoToApp(matchedDomainMapping.AppId, matchedDomainMapping.AppType) ?? View("Home");
|
return await GoToApp(matchedDomainMapping.AppId, matchedDomainMapping.AppType) ?? GoToHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
return await GoToApp(_cachedServerSettings.RootAppId, _cachedServerSettings.RootAppType) ?? View("Home");
|
return await GoToApp(_cachedServerSettings.RootAppId, _cachedServerSettings.RootAppType) ?? GoToHome();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IActionResult GoToHome()
|
||||||
|
{
|
||||||
|
if (SignInManager.IsSignedIn(User))
|
||||||
|
return View("Home");
|
||||||
|
else
|
||||||
|
return RedirectToAction(nameof(AccountController.Login), "Account");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("translate")]
|
[Route("translate")]
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace BTCPayServer.HostedServices
|
||||||
_creativeStartUri = "/vendor/bootstrap4-creativestart/creative.css?v=" + DateTime.Now.Ticks;
|
_creativeStartUri = "/vendor/bootstrap4-creativestart/creative.css?v=" + DateTime.Now.Ticks;
|
||||||
else
|
else
|
||||||
_creativeStartUri = data.CreativeStartCssUri;
|
_creativeStartUri = data.CreativeStartCssUri;
|
||||||
|
FirstRun = data.FirstRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _bootstrapUri;
|
private string _bootstrapUri;
|
||||||
|
@ -52,6 +53,8 @@ namespace BTCPayServer.HostedServices
|
||||||
public AppType? RootAppType { get; set; }
|
public AppType? RootAppType { get; set; }
|
||||||
public string RootAppId { get; set; }
|
public string RootAppId { get; set; }
|
||||||
|
|
||||||
|
public bool FirstRun { get; set; }
|
||||||
|
|
||||||
public List<PoliciesSettings.DomainToAppMappingItem> DomainToAppMapping { get; set; } = new List<PoliciesSettings.DomainToAppMappingItem>();
|
public List<PoliciesSettings.DomainToAppMappingItem> DomainToAppMapping { get; set; } = new List<PoliciesSettings.DomainToAppMappingItem>();
|
||||||
|
|
||||||
internal void Update(PoliciesSettings data)
|
internal void Update(PoliciesSettings data)
|
||||||
|
|
|
@ -10,6 +10,7 @@ using BTCPayServer.Services.Stores;
|
||||||
using BTCPayServer.Logging;
|
using BTCPayServer.Logging;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
|
||||||
namespace BTCPayServer
|
namespace BTCPayServer
|
||||||
{
|
{
|
||||||
|
@ -19,16 +20,19 @@ namespace BTCPayServer
|
||||||
private StoreRepository _StoreRepository;
|
private StoreRepository _StoreRepository;
|
||||||
private BTCPayNetworkProvider _NetworkProvider;
|
private BTCPayNetworkProvider _NetworkProvider;
|
||||||
private SettingsRepository _Settings;
|
private SettingsRepository _Settings;
|
||||||
|
private readonly UserManager<ApplicationUser> _userManager;
|
||||||
public MigrationStartupTask(
|
public MigrationStartupTask(
|
||||||
BTCPayNetworkProvider networkProvider,
|
BTCPayNetworkProvider networkProvider,
|
||||||
StoreRepository storeRepository,
|
StoreRepository storeRepository,
|
||||||
ApplicationDbContextFactory dbContextFactory,
|
ApplicationDbContextFactory dbContextFactory,
|
||||||
|
UserManager<ApplicationUser> userManager,
|
||||||
SettingsRepository settingsRepository)
|
SettingsRepository settingsRepository)
|
||||||
{
|
{
|
||||||
_DBContextFactory = dbContextFactory;
|
_DBContextFactory = dbContextFactory;
|
||||||
_StoreRepository = storeRepository;
|
_StoreRepository = storeRepository;
|
||||||
_NetworkProvider = networkProvider;
|
_NetworkProvider = networkProvider;
|
||||||
_Settings = settingsRepository;
|
_Settings = settingsRepository;
|
||||||
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
public async Task ExecuteAsync(CancellationToken cancellationToken = default)
|
public async Task ExecuteAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
@ -72,6 +76,15 @@ namespace BTCPayServer
|
||||||
settings.ConvertWalletKeyPathRoots = true;
|
settings.ConvertWalletKeyPathRoots = true;
|
||||||
await _Settings.UpdateSetting(settings);
|
await _Settings.UpdateSetting(settings);
|
||||||
}
|
}
|
||||||
|
if (!settings.CheckedFirstRun)
|
||||||
|
{
|
||||||
|
var themeSettings = await _Settings.GetSettingAsync<ThemeSettings>() ?? new ThemeSettings();
|
||||||
|
var admin = await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin);
|
||||||
|
themeSettings.FirstRun = admin.Count == 0;
|
||||||
|
await _Settings.UpdateSetting(themeSettings);
|
||||||
|
settings.CheckedFirstRun = true;
|
||||||
|
await _Settings.UpdateSetting(settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace BTCPayServer.Services
|
||||||
public bool ConvertNetworkFeeProperty { get; set; }
|
public bool ConvertNetworkFeeProperty { get; set; }
|
||||||
public bool ConvertCrowdfundOldSettings { get; set; }
|
public bool ConvertCrowdfundOldSettings { get; set; }
|
||||||
public bool ConvertWalletKeyPathRoots { get; set; }
|
public bool ConvertWalletKeyPathRoots { get; set; }
|
||||||
|
public bool CheckedFirstRun { get; set; }
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
|
@ -16,5 +16,11 @@ namespace BTCPayServer.Services
|
||||||
|
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
||||||
public string CreativeStartCssUri { get; set; }
|
public string CreativeStartCssUri { get; set; }
|
||||||
|
public bool FirstRun { get; set; }
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
// no logs
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue