mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
initial commit
This commit is contained in:
77
BTCPayServer/Controllers/AppsController.Crowdsale.cs
Normal file
77
BTCPayServer/Controllers/AppsController.Crowdsale.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using BTCPayServer.Models.AppViewModels;
|
||||||
|
using BTCPayServer.Services.Apps;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BTCPayServer.Controllers
|
||||||
|
{
|
||||||
|
public partial class AppsController
|
||||||
|
{
|
||||||
|
public class CrowdfundSettings
|
||||||
|
{
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public bool Enabled { get; set; }
|
||||||
|
|
||||||
|
public DateTime? StartDate { get; set; }
|
||||||
|
public DateTime? EndDate { get; set; }
|
||||||
|
|
||||||
|
public string TargetCurrency { get; set; }
|
||||||
|
public decimal? TargetAmount { get; set; }
|
||||||
|
|
||||||
|
public bool EnforceTargetAmount { get; set; }
|
||||||
|
public string CustomCSSLink { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{appId}/settings/crowdfund")]
|
||||||
|
public async Task<IActionResult> UpdateCrowdfund(string appId)
|
||||||
|
{
|
||||||
|
var app = await GetOwnedApp(appId, AppType.Crowdfund);
|
||||||
|
if (app == null)
|
||||||
|
return NotFound();
|
||||||
|
var settings = app.GetSettings<CrowdfundSettings>();
|
||||||
|
var vm = new UpdateCrowdfundViewModel()
|
||||||
|
{
|
||||||
|
Title = settings.Title,
|
||||||
|
Enabled = settings.Enabled,
|
||||||
|
EnforceTargetAmount = settings.EnforceTargetAmount,
|
||||||
|
StartDate = settings.StartDate,
|
||||||
|
TargetCurrency = settings.TargetCurrency,
|
||||||
|
Description = settings.Description,
|
||||||
|
EndDate = settings.EndDate,
|
||||||
|
TargetAmount = settings.TargetAmount,
|
||||||
|
CustomCSSLink = settings.CustomCSSLink
|
||||||
|
};
|
||||||
|
return View(vm);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
[Route("{appId}/settings/crowdfund")]
|
||||||
|
public async Task<IActionResult> UpdatePointOfSale(string appId, UpdateCrowdfundViewModel vm)
|
||||||
|
{
|
||||||
|
if (_AppsHelper.GetCurrencyData(vm.TargetCurrency, false) == null)
|
||||||
|
ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency");
|
||||||
|
|
||||||
|
var app = await GetOwnedApp(appId, AppType.Crowdfund);
|
||||||
|
if (app == null)
|
||||||
|
return NotFound();
|
||||||
|
app.SetSettings(new CrowdfundSettings()
|
||||||
|
{
|
||||||
|
Title = vm.Title,
|
||||||
|
Enabled = vm.Enabled,
|
||||||
|
EnforceTargetAmount = vm.EnforceTargetAmount,
|
||||||
|
StartDate = vm.StartDate,
|
||||||
|
TargetCurrency = vm.TargetCurrency,
|
||||||
|
Description = vm.Description,
|
||||||
|
EndDate = vm.EndDate,
|
||||||
|
TargetAmount = vm.TargetAmount,
|
||||||
|
CustomCSSLink = vm.CustomCSSLink
|
||||||
|
});
|
||||||
|
await UpdateAppSettings(app);
|
||||||
|
StatusMessage = "App updated";
|
||||||
|
return RedirectToAction(nameof(ListApps));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -68,6 +68,27 @@ namespace BTCPayServer.Controllers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("/apps/{appId}/crowdfund")]
|
||||||
|
[XFrameOptionsAttribute(null)]
|
||||||
|
public async Task<IActionResult> ViewCrowdfund(string appId)
|
||||||
|
{
|
||||||
|
var app = await _AppsHelper.GetApp(appId, AppType.Crowdfund);
|
||||||
|
if (app == null)
|
||||||
|
return NotFound();
|
||||||
|
var settings = app.GetSettings<CrowdfundSettings>();
|
||||||
|
var currency = _AppsHelper.GetCurrencyData(settings.TargetCurrency, false);
|
||||||
|
double step = currency == null ? 1 : Math.Pow(10, -(currency.Divisibility));
|
||||||
|
|
||||||
|
var numberFormatInfo = _AppsHelper.Currencies.GetNumberFormatInfo(currency.Code) ?? _AppsHelper.Currencies.GetNumberFormatInfo("USD");
|
||||||
|
return View(new ViewCrowdfundViewModel()
|
||||||
|
{
|
||||||
|
Title = settings.Title,
|
||||||
|
CustomCSSLink = settings.CustomCSSLink
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("/apps/{appId}/pos")]
|
[Route("/apps/{appId}/pos")]
|
||||||
[IgnoreAntiforgeryToken]
|
[IgnoreAntiforgeryToken]
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace BTCPayServer.Models.AppViewModels
|
||||||
|
{
|
||||||
|
public class UpdateCrowdfundViewModel
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
[MaxLength(30)]
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public bool Enabled { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public DateTime? StartDate { get; set; }
|
||||||
|
public DateTime? EndDate { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(5)]
|
||||||
|
[Display(Name = "The primary currency used for targets and stats")]
|
||||||
|
public string TargetCurrency { get; set; }
|
||||||
|
|
||||||
|
[Display(Name = "Set a Target amount ")]
|
||||||
|
public decimal? TargetAmount { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[Display(Name = "Do not allow additional contributions after target has been reached")]
|
||||||
|
public bool EnforceTargetAmount { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(500)]
|
||||||
|
[Display(Name = "Custom bootstrap CSS file")]
|
||||||
|
public string CustomCSSLink { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Models.AppViewModels
|
namespace BTCPayServer.Models.AppViewModels
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BTCPayServer.Models.AppViewModels
|
||||||
|
{
|
||||||
|
public class ViewCrowdfundViewModel
|
||||||
|
{
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string CustomCSSLink { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ namespace BTCPayServer.Services.Apps
|
|||||||
{
|
{
|
||||||
public enum AppType
|
public enum AppType
|
||||||
{
|
{
|
||||||
PointOfSale
|
PointOfSale,
|
||||||
|
Crowdfund
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
83
BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml
Normal file
83
BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
@model UpdateCrowdfundViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Update Crowdfund";
|
||||||
|
}
|
||||||
|
<section>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 text-center">
|
||||||
|
<h2 class="section-heading">@ViewData["Title"]</h2>
|
||||||
|
<hr class="primary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 text-center">
|
||||||
|
<partial name="_StatusMessage" for="@TempData["TempDataProperty-StatusMessage"]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<form method="post">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Title" class="control-label"></label>*
|
||||||
|
<input asp-for="Title" class="form-control" />
|
||||||
|
<span asp-validation-for="Title" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Description" class="control-label"></label>*
|
||||||
|
<textarea asp-for="Description" rows="20" cols="40" class="form-control"></textarea>
|
||||||
|
<span asp-validation-for="Description" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="CustomCSSLink" class="control-label"></label>
|
||||||
|
<a href="https://docs.btcpayserver.org/development/theme#bootstrap-themes" target="_blank"><span class="fa fa-question-circle-o" title="More information..."></span></a>
|
||||||
|
<input asp-for="CustomCSSLink" class="form-control" />
|
||||||
|
<span asp-validation-for="CustomCSSLink" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Enabled"></label>
|
||||||
|
<input asp-for="Enabled" type="checkbox" class="form-check"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="EnforceTargetAmount"></label>
|
||||||
|
<input asp-for="EnforceTargetAmount" type="checkbox" class="form-check"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="StartDate" class="control-label"></label>*
|
||||||
|
<input asp-for="StartDate" class="form-control" />
|
||||||
|
<span asp-validation-for="StartDate" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="EndDate" class="control-label"></label>*
|
||||||
|
<input asp-for="EndDate" class="form-control" />
|
||||||
|
<span asp-validation-for="EndDate" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="TargetCurrency" class="control-label"></label>*
|
||||||
|
<input asp-for="TargetCurrency" class="form-control" />
|
||||||
|
<span asp-validation-for="TargetCurrency" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="TargetAmount" class="control-label"></label>*
|
||||||
|
<input asp-for="TargetAmount" class="form-control" />
|
||||||
|
<span asp-validation-for="TargetAmount" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="submit" class="btn btn-primary" value="Save Settings" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<a asp-action="ListApps">Back to the app list</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<link rel="stylesheet" href="~/vendor/highlightjs/default.min.css">
|
||||||
|
<script src="~/vendor/highlightjs/highlight.min.js"></script>
|
||||||
|
<script>hljs.initHighlightingOnLoad();</script>
|
||||||
|
}
|
||||||
|
|
||||||
28
BTCPayServer/Views/AppsPublic/ViewCrowdfund.cshtml
Normal file
28
BTCPayServer/Views/AppsPublic/ViewCrowdfund.cshtml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
|
||||||
|
@inject BTCPayServer.HostedServices.CssThemeManager themeManager
|
||||||
|
|
||||||
|
@model BTCPayServer.Models.AppViewModels.ViewCrowdfundViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = Model.Title;
|
||||||
|
Layout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html class="h-100">
|
||||||
|
<head>
|
||||||
|
<title>@Model.Title</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<link href="@this.Context.Request.GetAbsoluteUri(themeManager.BootstrapUri)" rel="stylesheet" />
|
||||||
|
@if (Model.CustomCSSLink != null)
|
||||||
|
{
|
||||||
|
<link href="@Model.CustomCSSLink" rel="stylesheet" />
|
||||||
|
}
|
||||||
|
<link href="~/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body class="h-100">
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user