Redirect to Stores page if creating invoice before creating a store

This commit is contained in:
NicolasDorier 2017-09-15 13:49:36 +09:00
parent efcda9a45e
commit d86e8695a0
4 changed files with 35 additions and 4 deletions

View File

@ -75,7 +75,7 @@ namespace BTCPayServer.Tests
ExplorerClient = new NBXplorer.ExplorerClient(Node.Network, new Uri($"http://127.0.0.1:{port}/"));
CookieFile = Path.Combine(launcher2.CurrentDirectory, ".cookie");
File.Create(CookieFile).Close(); //Will be wipedout when the client starts
ExplorerClient.SetCookieFile(CookieFile);
ExplorerClient.SetCookieAuth(CookieFile);
try
{
var cancellationSource = new CancellationTokenSource(10000);

View File

@ -14,7 +14,7 @@
<PackageReference Include="NBitcoin" Version="4.0.0.38" />
<PackageReference Include="NBitpayClient" Version="1.0.0.6" />
<PackageReference Include="DBreeze" Version="1.87.0" />
<PackageReference Include="NBXplorer.Client" Version="1.0.0.9" />
<PackageReference Include="NBXplorer.Client" Version="1.0.0.12" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.0.11" />
</ItemGroup>

View File

@ -127,7 +127,13 @@ namespace BTCPayServer.Controllers
[BitpayAPIConstraint(false)]
public async Task<IActionResult> CreateInvoice()
{
return View(new CreateInvoiceModel() { Stores = await GetStores(GetUserId()) });
var stores = await GetStores(GetUserId());
if(stores.Count() == 0)
{
StatusMessage = "Error: You need to create at least one store before creating a transaction";
return RedirectToAction(nameof(StoresController.ListStores), "Stores");
}
return View(new CreateInvoiceModel() { Stores = stores });
}
[HttpPost]

View File

@ -11,6 +11,8 @@ using System.Linq;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Collections;
namespace BTCPayServer
{
@ -23,7 +25,9 @@ namespace BTCPayServer
try
{
var conf = new BTCPayServerOptions();
conf.LoadArgs(new TextFileConfiguration(args));
var arguments = new TextFileConfiguration(args);
arguments = LoadEnvironmentVariables(arguments);
conf.LoadArgs(arguments);
host = new WebHostBuilder()
.AddPayServer(conf)
@ -61,6 +65,27 @@ namespace BTCPayServer
}
}
private static TextFileConfiguration LoadEnvironmentVariables(TextFileConfiguration args)
{
var variables = Environment.GetEnvironmentVariables();
List<string> values = new List<string>();
foreach(DictionaryEntry variable in variables)
{
var key = (string)variable.Key;
var value = (string)variable.Value;
if(key.StartsWith("APPSETTING_", StringComparison.Ordinal))
{
key = key.Substring("APPSETTING_".Length);
values.Add("-" + key);
values.Add(value);
}
}
TextFileConfiguration envConfig = new TextFileConfiguration(values.ToArray());
args.MergeInto(envConfig, true);
return envConfig;
}
public static void OpenBrowser(string url)
{
try