Commit ff1bde4e authored by Clint.Network's avatar Clint.Network

Create Lottery Service and Deposit Modal

parent f2eebcb7
...@@ -15,6 +15,7 @@ using Microsoft.Extensions.Caching.Memory; ...@@ -15,6 +15,7 @@ using Microsoft.Extensions.Caching.Memory;
using NBitcoin; using NBitcoin;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using PaulMiami.AspNetCore.Mvc.Recaptcha;
using QRCoder; using QRCoder;
using Stratis.Guru.Models; using Stratis.Guru.Models;
using Stratis.Guru.Modules; using Stratis.Guru.Modules;
...@@ -69,9 +70,43 @@ namespace Stratis.Guru.Controllers ...@@ -69,9 +70,43 @@ namespace Stratis.Guru.Controllers
[Route("lottery")] [Route("lottery")]
public IActionResult Lottery() public IActionResult Lottery()
{ {
ViewBag.NextDraw = long.Parse(_memoryCache.Get("NextDraw").ToString());
return View(); return View();
} }
[ValidateRecaptcha]
[HttpPost]
[Route("lottery/participate")]
public IActionResult Participate()
{
if (ModelState.IsValid)
{
return RedirectToAction("Participate", new{id="5c1ef60f09f5754c34ba3010"});
}
ViewBag.NextDraw = long.Parse(_memoryCache.Get("NextDraw").ToString());
ViewBag.Participate = true;
return View("Lottery");
}
[HttpGet]
[Route("lottery/participate/{id}")]
public IActionResult Participate(string id)
{
ViewBag.NextDraw = long.Parse(_memoryCache.Get("NextDraw").ToString());
ViewBag.Participate = true;
return View("Lottery");
}
[HttpPost]
[Route("lottery/check-payment/{address}")]
public IActionResult CheckPayment(string address)
{
var pubkey = ExtPubKey.Parse("xpub6Bfq1wKQ64UUzW2HzQ6aZmoxkMYVq6DNifiTU1A1d9UEe16qSGnyqSAbFr42XAMXSXi3kcMXQJseXcgyTGQeDpBvHYt5m1HCH74Q52C4kkZ");
var newAddress = pubkey.Derive(0).Derive(0).PubKey.GetAddress(Network.StratisMain);
Console.WriteLine(newAddress);
return Json(true);
}
[Route("about")] [Route("about")]
public IActionResult About() public IActionResult About()
{ {
......
namespace Stratis.Guru.DependencyInjection
{
public interface IMongoContext
{
}
}
\ No newline at end of file
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace Stratis.Guru.Models
{
public class LotteryDraw
{
[BsonId]
public ObjectId Id { get; set; }
public long DrawDate { get; set; }
public bool Passed { get; set; }
}
}
\ No newline at end of file
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Hosting;
using MongoDB.Bson;
using MongoDB.Driver;
using Stratis.Guru.Models;
namespace Stratis.Guru.Services
{
public class LotteryService : IHostedService, IDisposable
{
private readonly IMemoryCache _memoryCache;
private DateTime _nextDraw;
public LotteryService(IMemoryCache memoryCache)
{
_memoryCache = memoryCache;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
await CalculateNextDrawAsync();
}
private async Task CalculateNextDrawAsync()
{
DateTime today = DateTime.Today;
int daysUntilFriday = ((int)DayOfWeek.Friday - (int)today.DayOfWeek + 7) % 7;
_nextDraw = today.AddDays(daysUntilFriday);
var nextDrawTimestamp = ((DateTimeOffset)_nextDraw).ToUnixTimeSeconds();
#region use DI
var client = new MongoClient("mongodb://localhost:27017");
var database = client.GetDatabase("stratis-guru");
var collection = database.GetCollection<LotteryDraw>("draws");
if(!collection.Find(x => x.DrawDate.Equals(nextDrawTimestamp)).Any())
{
await collection.InsertOneAsync(new LotteryDraw()
{
DrawDate = nextDrawTimestamp,
Passed = false
});
}
#endregion
_memoryCache.Set("NextDraw", nextDrawTimestamp);
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public void Dispose()
{
}
}
}
\ No newline at end of file
...@@ -10,9 +10,11 @@ using Microsoft.AspNetCore.Hosting; ...@@ -10,9 +10,11 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using PaulMiami.AspNetCore.Mvc.Recaptcha;
using Stratis.Guru.Hubs; using Stratis.Guru.Hubs;
using Stratis.Guru.Models; using Stratis.Guru.Models;
using Stratis.Guru.Modules; using Stratis.Guru.Modules;
...@@ -41,6 +43,12 @@ namespace Stratis.Guru ...@@ -41,6 +43,12 @@ namespace Stratis.Guru
options.CheckConsentNeeded = context => true; options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = None; options.MinimumSameSitePolicy = None;
}); });
services.AddSession(options =>
{
options.Cookie.IsEssential = true;
});
services.Configure<NakoApiSettings>(Configuration.GetSection("NakoApi")); services.Configure<NakoApiSettings>(Configuration.GetSection("NakoApi"));
services.Configure<FixerApiSettings>(Configuration.GetSection("FixerApi")); services.Configure<FixerApiSettings>(Configuration.GetSection("FixerApi"));
...@@ -51,12 +59,19 @@ namespace Stratis.Guru ...@@ -51,12 +59,19 @@ namespace Stratis.Guru
services.AddHostedService<UpdateInfosService>(); services.AddHostedService<UpdateInfosService>();
services.AddHostedService<FixerService>(); services.AddHostedService<FixerService>();
services.AddHostedService<LotteryService>();
services.AddHostedService<VanityService>(); services.AddHostedService<VanityService>();
services.AddLocalization(); services.AddLocalization();
services.AddMvc(); services.AddMvc();
services.AddRecaptcha(new RecaptchaOptions
{
SiteKey = "6LfmOIQUAAAAAIEsH2nG6kEiL-bpLhvm0ibhHnol", //Configuration["Recaptcha:SiteKey"],
SecretKey = "6LfmOIQUAAAAAO06PpD8MmndjrjfBr7x-fgnDt2G" //Configuration["Recaptcha:SecretKey"]
});
services.AddSignalR(); services.AddSignalR();
} }
...@@ -70,9 +85,10 @@ namespace Stratis.Guru ...@@ -70,9 +85,10 @@ namespace Stratis.Guru
{ {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
//app.UseHsts(); //app.UseHsts();
app.UseHttpsRedirection();
} }
//app.UseHttpsRedirection(); app.UseSession();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseCookiePolicy(); app.UseCookiePolicy();
......
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.6.362" /> <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.6.362" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.113" /> <PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.113" />
<PackageReference Include="Microsoft.AspNetCore.App"/> <PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All"/> <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.4"/> <PackageReference Include="mongocsharpdriver" Version="2.7.2" />
<PackageReference Include="NStratis" Version="4.0.0.60"/> <PackageReference Include="NStratis" Version="4.0.0.60" />
<PackageReference Include="QRCoder" Version="1.3.3"/> <PackageReference Include="PaulMiami.AspNetCore.Mvc.Recaptcha" Version="1.2.1" />
<PackageReference Include="RestSharp" Version="106.5.4"/> <PackageReference Include="QRCoder" Version="1.3.3" />
<PackageReference Include="RestSharp" Version="106.5.4" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -5,24 +5,76 @@ ...@@ -5,24 +5,76 @@
@section Style @section Style
{ {
<style> <style>
body { .shadow-inset {
background-image: url(/images/Slider_Landing-1920x650.webp.jpg); background-image: url(/images/Slider_Landing-1920x650.webp.jpg);
} }
.modal-content
{
border-radius: 3px;
}
</style> </style>
} }
<div class="modal fade" id="participate-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form method="post" asp-controller="Home" asp-action="Participate">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-ticket"></i> Buy a Lottery Ticket</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>The <strong>Stratis.Guru</strong> lottery is drawn every week at 8 PM, you can easily participate, get a ticket and play some $STRAT.</p>
<br />
<center>
<recaptcha/>
</center>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-info btn-lg btn-block">Get a Ticket</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="deposit-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-ticket"></i> Buy a Lottery Ticket</h5>
<a asp-controller="Home" asp-action="Lottery" type="button" class="close">
<span aria-hidden="true">&times;</span>
</a>
</div>
<div class="modal-body text-center py-4">
<h2 class="text-dark mb-1">Send Some $STRAT</h2>
<p>Your participation will be considered after 1 confirmation.</p>
<img class="my-4" src="@Url.Action("Qr", "Home", new {value="SfXZxGJWnq3aP8hDmGKWJxJbtbEXYtba86"})" style="width: 250px;" />
<h4>Send to this address: <code>SfXZxGJWnq3aP8hDmGKWJxJbtbEXYtba86</code></h4>
</div>
<div class="modal-footer">
<a asp-controller="Home" asp-action="CheckPayment" data-ajax-method="POST" asp-route-address="SfXZxGJWnq3aP8hDmGKWJxJbtbEXYtba86" data-ajax-success="alert('yeah');" data-ajax-failure="alert('failure');" data-ajax="true" class="btn btn-info btn-lg btn-block"><i class="fa fa-check-circle"></i> Check Payment</a>
</div>
</div>
</div>
</div>
<div class="shadow-inset"></div> <div class="shadow-inset"></div>
<section class="welcome-area pb-4" id="welcome-1"> <section class="welcome-area pb-4" id="welcome-1">
<div class="header-token"> <div class="header-token">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 align-self-center text-center"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 align-self-center text-center">
<h1 class="m-0">The Next <strong>Stratis</strong> Lottery Draw in:</h1> <h1 class="m-0">The Next <strong>Stratis.Guru</strong> Lottery Draw in:</h1>
<h1 class="align-middle"> <h1 class="mb-3 align-middle">
<span class="align-middle display-1 font-weight-bold" id="amount"> <span class="align-middle display-1 font-weight-bold" id="amount">
<span id="clock"></span> <span id="clock"></span>
</span> </span>
</h1> </h1>
<a asp-controller="BlockExplorer" asp-action="Index" class="btn-secondary-box"><i class="fa fa-ticket"></i> Buy a lottery ticket</a> <h2 class="mb-5">Actual Jackpot: @(257.89.ToString("C"))</h2>
<button data-toggle="modal" data-target="#participate-modal" class="btn-secondary-box"><i class="fa fa-ticket"></i> Buy a lottery ticket</button>
<button data-toggle="modal" data-target="#players-modal" class="btn-secondary-box"><i class="fa fa-user-o"></i> See Players</button>
</div> </div>
</div> </div>
</div> </div>
...@@ -30,11 +82,18 @@ ...@@ -30,11 +82,18 @@
</section> </section>
@section Scripts @section Scripts
{ {
<script src="/npm/jquery-countdown/dist/jquery.countdown.min.js"></script> <recaptcha-script/>
<script src="~/lib/jquery-countdown/dist/jquery.countdown.min.js"></script>
<script src="~/lib/jquery-ajax-unobtrusive/dist/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('#clock').countdown('2020/10/10', function(event) { @if(ViewBag.Participate == true)
$(this).html(event.strftime('%Hh %Mm %Ss')); {
<text>$("#deposit-modal").modal({backdrop: 'static', keyboard: false});</text>
}
$('#clock').countdown('@((DateTimeOffset.FromUnixTimeSeconds((long)ViewBag.NextDraw)).ToString("yyyy/MM/dd HH:mm:ss"))', function(event) {
$(this).html(event.strftime('%D days %Hh %Mm %Ss'));
}); });
}) })
</script> </script>
......
...@@ -41,10 +41,10 @@ ...@@ -41,10 +41,10 @@
</a> </a>
<ul class="nav"> <ul class="nav">
<li class="@(Context.Request.Path.Equals(Url.Action("Index", "Home")) ? "active":"")"><a asp-action="Index" asp-controller="Home"><i class="fa fa-home"></i> HOME</a></li> <li class="@(Context.Request.Path.Equals(Url.Action("Index", "Home")) ? "active":"")"><a asp-action="Index" asp-controller="Home"><i class="fa fa-home"></i> HOME</a></li>
@*<li class="@(Context.Request.Path.Equals(Url.Action("Lottery", "Home")) ? "active":"")"><a asp-action="Lottery" asp-controller="Home"><i class="fa fa-trophy"></i> LOTTERY</a></li>*@ <li class="@(Context.Request.Path.Equals(Url.Action("Lottery", "Home")) ? "active":"")"><a asp-action="Lottery" asp-controller="Home"><i class="fa fa-trophy"></i> LOTTERY</a></li>
<li class="@(Context.Request.Path.Equals(Url.Action("Index", "BlockExplorer")) ? "active":"")"><a asp-action="Index" asp-controller="BlockExplorer"><i class="fa fa-cube"></i> BLOCK EXPLORER</a></li> <li class="@(Context.Request.Path.Equals(Url.Action("Index", "BlockExplorer")) ? "active":"")"><a asp-action="Index" asp-controller="BlockExplorer"><i class="fa fa-cube"></i> BLOCK EXPLORER</a></li>
<li class="@(Context.Request.Path.Equals(Url.Action("Vanity", "Home")) ? "active":"")"><a asp-action="Vanity" asp-controller="Home"><i class="fa fa-at"></i> VANITY</a></li> <li class="@(Context.Request.Path.Equals(Url.Action("Vanity", "Home")) ? "active":"")"><a asp-action="Vanity" asp-controller="Home"><i class="fa fa-at"></i> VANITY</a></li>
<li class="@(Context.Request.Path.Equals(Url.Action("Generator", "Home")) ? "active":"")"><a asp-action="Generator" asp-controller="Home"><i class="fa fa-qrcode"></i> ADDRESS GENERATOR</a></li> <li class="@(Context.Request.Path.Equals(Url.Action("Generator", "Home")) ? "active":"")"><a asp-action="Generator" asp-controller="Home"><i class="fa fa-qrcode"></i> GENERATOR</a></li>
<li class="@(Context.Request.Path.Equals(Url.Action("Documentation", "Home")) ? "active":"")"><a asp-action="Documentation" asp-controller="Home"><i class="fa fa-book"></i> API</a></li> <li class="@(Context.Request.Path.Equals(Url.Action("Documentation", "Home")) ? "active":"")"><a asp-action="Documentation" asp-controller="Home"><i class="fa fa-book"></i> API</a></li>
<li class="@(Context.Request.Path.Equals(Url.Action("About", "Home")) ? "active":"")"><a asp-action="About" asp-controller="Home"><i class="fa fa-info-circle"></i> ABOUT</a></li> <li class="@(Context.Request.Path.Equals(Url.Action("About", "Home")) ? "active":"")"><a asp-action="About" asp-controller="Home"><i class="fa fa-info-circle"></i> ABOUT</a></li>
</ul> </ul>
......
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
@using Stratis.Guru.Models @using Stratis.Guru.Models
@using System.Globalization @using System.Globalization
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, PaulMiami.AspNetCore.Mvc.Recaptcha
\ No newline at end of file
...@@ -6,10 +6,6 @@ ...@@ -6,10 +6,6 @@
"library": "bootstrap@4.1.3", "library": "bootstrap@4.1.3",
"destination": "wwwroot\\lib\\bootstrap" "destination": "wwwroot\\lib\\bootstrap"
}, },
{
"library": "jquery-countdown@2.2.0",
"destination": "wwwroot\\lib\\jquery-countdown"
},
{ {
"library": "nprogress@0.2.0", "library": "nprogress@0.2.0",
"destination": "wwwroot\\lib\\nprogress" "destination": "wwwroot\\lib\\nprogress"
...@@ -17,6 +13,14 @@ ...@@ -17,6 +13,14 @@
{ {
"library": "@aspnet/signalr@1.1.0", "library": "@aspnet/signalr@1.1.0",
"destination": "wwwroot\\lib\\@aspnet/signalr" "destination": "wwwroot\\lib\\@aspnet/signalr"
},
{
"library": "jquery-countdown@2.2.0",
"destination": "wwwroot\\lib\\jquery-countdown"
},
{
"library": "jquery-ajax-unobtrusive@3.2.6",
"destination": "wwwroot\\lib\\jquery-ajax-unobtrusive"
} }
] ]
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment