2017-09-13 08:47:34 +02:00
|
|
|
|
using BTCPayServer.Authentication;
|
2017-09-22 18:31:29 +02:00
|
|
|
|
using BTCPayServer.Configuration;
|
2017-09-27 08:16:30 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2017-09-13 08:47:34 +02:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2017-09-22 18:31:29 +02:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2017-09-13 08:47:34 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
|
{
|
|
|
|
|
public static class Extensions
|
|
|
|
|
{
|
2017-09-27 08:16:30 +02:00
|
|
|
|
public static string WithTrailingSlash(this string str)
|
|
|
|
|
{
|
|
|
|
|
if(str.EndsWith("/"))
|
|
|
|
|
return str;
|
|
|
|
|
return str + "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetAbsoluteRoot(this HttpRequest request)
|
|
|
|
|
{
|
|
|
|
|
return string.Concat(
|
|
|
|
|
request.Scheme,
|
|
|
|
|
"://",
|
|
|
|
|
request.Host.ToUriComponent(),
|
|
|
|
|
request.PathBase.ToUriComponent());
|
|
|
|
|
}
|
2017-09-22 18:31:29 +02:00
|
|
|
|
|
|
|
|
|
public static IServiceCollection ConfigureBTCPayServer(this IServiceCollection services, IConfiguration conf)
|
|
|
|
|
{
|
|
|
|
|
services.Configure<BTCPayServerOptions>(o =>
|
|
|
|
|
{
|
|
|
|
|
o.LoadArgs(conf);
|
|
|
|
|
});
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-13 08:47:34 +02:00
|
|
|
|
public static BitIdentity GetBitIdentity(this Controller controller)
|
|
|
|
|
{
|
|
|
|
|
if(!(controller.User.Identity is BitIdentity))
|
|
|
|
|
throw new UnauthorizedAccessException("no-bitid");
|
|
|
|
|
return (BitIdentity)controller.User.Identity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|