Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DanDude0 committed Feb 22, 2024
2 parents 7893425 + 33eb822 commit 41586b4
Show file tree
Hide file tree
Showing 45 changed files with 7,467 additions and 3,730 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build --configuration Release
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ packages
bin
obj
PublishProfiles
appsettings.json
logs
22 changes: 12 additions & 10 deletions MilwaukeeMakerspaceApi/App.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
29 changes: 29 additions & 0 deletions MilwaukeeMakerspaceApi/AuthorizingHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Authentication.OAuth;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System;

namespace Mms.Api
{
public class AuthorizingHandler : DelegatingHandler
{
private readonly OAuthOptions _options;
public AuthorizingHandler(HttpMessageHandler inner, OAuthOptions options)
: base(inner)
{
_options = options;
}

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.RequestUri == new Uri(_options.TokenEndpoint)) {
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(_options.ClientId + ":" + _options.ClientSecret));

request.Headers.Add("Authorization", $"Basic {credentials}");
}
return base.SendAsync(request, cancellationToken);
}
}
}
55 changes: 55 additions & 0 deletions MilwaukeeMakerspaceApi/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.AspNetCore.Authentication;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;

namespace Mvc.Client.Controllers;

[ApiExplorerSettings(IgnoreApi = true)]
public class AuthenticationController : Controller
{
[HttpGet("/login")]
[HttpPost("/login")]
public IActionResult SignIn()
{
// Instruct the middleware corresponding to the requested external identity
// provider to redirect the user agent to its own authorization endpoint.
// Note: the authenticationScheme parameter must match the value configured in Startup.cs
return Challenge(new AuthenticationProperties { RedirectUri = "/" }, "WildApricot");
}

[HttpGet("/logout")]
[HttpPost("/logout")]
public IActionResult SignOutCurrentUser()
{
// Instruct the cookies middleware to delete the local cookie created
// when the user agent is redirected from the external identity provider
// after a successful authentication flow (e.g Google or Facebook).
return SignOut(new AuthenticationProperties { RedirectUri = "/" },
CookieAuthenticationDefaults.AuthenticationScheme);
}

private static async Task<AuthenticationScheme[]> GetExternalProvidersAsync(HttpContext context)
{
ArgumentNullException.ThrowIfNull(context);

var schemes = context.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>();

return (from scheme in await schemes.GetAllSchemesAsync()
where !string.IsNullOrEmpty(scheme.DisplayName)
select scheme).ToArray();
}

private static async Task<bool> IsProviderSupportedAsync(HttpContext context, string provider)
{
ArgumentNullException.ThrowIfNull(context);

return (from scheme in await GetExternalProvidersAsync(context)
where string.Equals(scheme.Name, provider, StringComparison.OrdinalIgnoreCase)
select scheme).Any();
}
}
4 changes: 3 additions & 1 deletion MilwaukeeMakerspaceApi/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace Mms.Api.Controllers
{
[ApiExplorerSettings(IgnoreApi = true)]

public class HomeController : Controller
{
public IActionResult Index()
Expand Down
2 changes: 2 additions & 0 deletions MilwaukeeMakerspaceApi/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Mms.Api.Controllers
{
[ApiExplorerSettings(IgnoreApi = true)]

public class InfoController : Controller
{
public IActionResult Service()
Expand Down
32 changes: 2 additions & 30 deletions MilwaukeeMakerspaceApi/Controllers/InvoiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Mms.Api.Controllers
{
[ApiExplorerSettings(IgnoreApi = true)]

public class InvoiceController : Controller
{
[HttpGet]
Expand All @@ -22,37 +24,7 @@ public IActionResult MvInvoice(int id)

return View(invoice);
}
/*
[STAThread]
[HttpGet]
[Route("mvinvoice/{id}.pdf")]
public async Task<IActionResult> MvPdfInvoice(int id)
{
var invoice = GetMakersVillageInvoice(id);
var html = await this.RenderViewAsync("mvinvoice", invoice);

var converter = new SynchronizedConverter(new PdfTools());
var document = new HtmlToPdfDocument {
GlobalSettings = {
ColorMode = ColorMode.Grayscale,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.Letter,
},
Objects = {
new ObjectSettings() {
PagesCount = true,
HtmlContent = html,
},
},
};
var pdf = converter.Convert(document);
return new FileContentResult(pdf, "application/pdf");
}
*/
private MakersVillageInvoice GetMakersVillageInvoice(int id)
{
using var db = new BillingDatabase();
Expand Down
52 changes: 27 additions & 25 deletions MilwaukeeMakerspaceApi/Controllers/MmsTreasurerReportController.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Mms.Api;
using Mms.Api.Models;
using Mms.Database;
using Newtonsoft.Json;

namespace Mms.Api.Controllers
{
public class MmsTreasurerReportController : Controller
{
[HttpGet]
[Route("mmstreasurerreport/{month}")]
public IActionResult MmsTreasurerReport(string month)
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Mms.Api;
using Mms.Api.Models;
using Mms.Database;
using Newtonsoft.Json;

namespace Mms.Api.Controllers
{
[ApiExplorerSettings(IgnoreApi = true)]

public class MmsTreasurerReportController : Controller
{
[HttpGet]
[Route("mmstreasurerreport/{month}")]
public IActionResult MmsTreasurerReport(string month)
{
var date = DateTime.ParseExact(month, "yyyy-MM", null);

var model = new TreasurerReport();
Expand All @@ -34,7 +36,7 @@ public IActionResult MmsTreasurerReport(string month)
membershipHistory[i].Net = membershipHistory[i].Total - membershipHistory[i - 1].Total;
}

membershipHistory.RemoveAt(1);
membershipHistory.RemoveAt(0);

model.MembershipHistory = membershipHistory;

Expand All @@ -48,7 +50,7 @@ public IActionResult MmsTreasurerReport(string month)
model.LastMonthIncome = lastMonth.Income;
model.LastMonthSpending = lastMonth.Spending;
model.LastMonthNetTotal = lastMonth.Income - lastMonth.Spending;


var last12 = db.Single<FlowResult>("SELECT SUM(income) AS 'Income', SUM(spending+fees) AS 'Spending' FROM bank_statement WHERE `time` >= @0 AND `time` < @1", date.AddMonths(-12), date);

model.LastYearIncome = last12.Income;
Expand Down Expand Up @@ -89,7 +91,7 @@ public IActionResult MmsTreasurerReport(string month)
WHERE `time` >= @0 AND `time` < @1", date.AddMonths(-12), date);

model.LastYearNetGeneralFunds = model.LastYearNetTotal - model.LastYearNetAreaFunds;


return View(model);
}
public class FlowResult
Expand All @@ -98,5 +100,5 @@ public class FlowResult
public decimal Spending { get; set; }
public decimal Balance { get; set; }
}
}
}
}
}
Loading

0 comments on commit 41586b4

Please sign in to comment.