Skip to content

Commit

Permalink
Merge pull request #47 from PinchPayments/update-web-sample
Browse files Browse the repository at this point in the history
Updated the SDK sample app to work again
  • Loading branch information
dkarzon authored Dec 15, 2023
2 parents b02a277 + ab2f09f commit b742ae0
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 75 deletions.
25 changes: 11 additions & 14 deletions src/Pinch.SDK.WebSample/Pinch.SDK.WebSample.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<UserSecretsId>aspnet5-Pinch.SDK.WebSample-035714b9-1391-452f-876c-de29839a80c8</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Pinch.SDK\Pinch.SDK.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.18" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.12" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Seq" Version="6.0.0" />
</ItemGroup>

<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<Exec Command="npm install" />
Expand All @@ -22,12 +27,4 @@
<Exec Command="gulp min" />
</Target>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\lib\" />
</ItemGroup>

</Project>
28 changes: 23 additions & 5 deletions src/Pinch.SDK.WebSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,36 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;

namespace Pinch.SDK.WebSample
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
.Build();

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.Extensions.Localization", LogEventLevel.Warning)
.ReadFrom.Configuration(configuration)
.CreateLogger();

var host = Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.Build();

host.Run();
Expand Down
22 changes: 4 additions & 18 deletions src/Pinch.SDK.WebSample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://localhost:44389/",
"sslPort": 44389
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"Hosting:Environment": "Development"
}
},
"web": {
"commandName": "web",
"commandName": "Project",
"environmentVariables": {
"Hosting:Environment": "Development"
}
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
26 changes: 10 additions & 16 deletions src/Pinch.SDK.WebSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@
using Pinch.SDK.WebSample.Services;
using Microsoft.EntityFrameworkCore;
using Pinch.SDK.WebSample.Helpers;
using Microsoft.Extensions.Hosting;

namespace Pinch.SDK.WebSample
{
public class Startup
{
public Startup(IHostingEnvironment env)
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
.AddEnvironmentVariables();

Configuration = builder.Build();
Configuration = configuration;
}

public IConfigurationRoot Configuration { get; set; }
public IConfiguration Configuration { get; set; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
Expand All @@ -54,16 +55,11 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
Expand All @@ -86,17 +82,15 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF

app.UseStaticFiles();

app.UseIdentity();

// To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715

app.UseSession();

app.UseMvc(routes =>
app.UseRouting();

app.UseEndpoints(endpoints =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapDefaultControllerRoute();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.AspNetCore.Identity;

namespace Pinch.SDK.WebSample.ViewModels.Manage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
<form asp-controller="Account" asp-action="ExternalLoginConfirmation" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
<h4>Association Form</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}

<p class="text-info">
You've successfully authenticated with <strong>@ViewData["LoginProvider"]</strong>.
Expand Down
15 changes: 9 additions & 6 deletions src/Pinch.SDK.WebSample/Views/Account/Login.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@using System.Collections.Generic
@using Microsoft.AspNet.Http
@using Microsoft.AspNet.Http.Authentication
@model LoginViewModel
@inject SignInManager<ApplicationUser> SignInManager

Expand All @@ -15,7 +13,12 @@
<form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
<h4>Use a local account to log in.</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}
<div class="form-group">
<label asp-for="Email" class="col-md-2 control-label"></label>
<div class="col-md-10">
Expand Down Expand Up @@ -57,8 +60,8 @@
<h4>Use another service to log in.</h4>
<hr />
@{
var loginProviders = SignInManager.GetExternalAuthenticationSchemes().ToList();
if (loginProviders.Count == 0)
var loginProviders = await SignInManager.GetExternalAuthenticationSchemesAsync();
if (loginProviders.Count() == 0)
{
<div>
<p>
Expand All @@ -74,7 +77,7 @@
<p>
@foreach (var provider in loginProviders)
{
<button type="submit" class="btn btn-default" name="provider" value="@provider.AuthenticationScheme" title="Log in using your @provider.DisplayName account">@provider.AuthenticationScheme</button>
<button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.Name</button>
}
</p>
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/Pinch.SDK.WebSample/Views/Account/Register.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<form asp-controller="Account" asp-action="Register" method="post" class="form-horizontal" role="form">
<h4>Create a new account.</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}
<div class="form-group">
<label asp-for="Email" class="col-md-2 control-label"></label>
<div class="col-md-10">
Expand Down
7 changes: 6 additions & 1 deletion src/Pinch.SDK.WebSample/Views/Account/ResetPassword.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<form asp-controller="Account" asp-action="ResetPassword" method="post" class="form-horizontal" role="form">
<h4>Reset your password.</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}
<input asp-for="Code" type="hidden" />
<div class="form-group">
<label asp-for="Email" class="col-md-2 control-label"></label>
Expand Down
7 changes: 6 additions & 1 deletion src/Pinch.SDK.WebSample/Views/Account/VerifyCode.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
<h2>@ViewData["Title"].</h2>

<form asp-controller="Account" asp-action="VerifyCode" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}
<input asp-for="Provider" type="hidden" />
<input asp-for="RememberMe" type="hidden" />
<h4>@ViewData["Status"]</h4>
Expand Down
7 changes: 6 additions & 1 deletion src/Pinch.SDK.WebSample/Views/Manage/AddPhoneNumber.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
<form asp-controller="Manage" asp-action="AddPhoneNumber" method="post" class="form-horizontal" role="form">
<h4>Add a phone number.</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}
<div class="form-group">
<label asp-for="PhoneNumber" class="col-md-2 control-label"></label>
<div class="col-md-10">
Expand Down
7 changes: 6 additions & 1 deletion src/Pinch.SDK.WebSample/Views/Manage/ChangePassword.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<form asp-controller="Manage" asp-action="ChangePassword" method="post" class="form-horizontal" role="form">
<h4>Change Password Form</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}
<div class="form-group">
<label asp-for="OldPassword" class="col-md-2 control-label"></label>
<div class="col-md-10">
Expand Down
3 changes: 1 addition & 2 deletions src/Pinch.SDK.WebSample/Views/Manage/ManageLogins.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@model ManageLoginsViewModel
@using Microsoft.AspNet.Http.Authentication
@{
ViewData["Title"] = "Manage your external logins";
}
Expand Down Expand Up @@ -46,7 +45,7 @@
<p>
@foreach (var provider in Model.OtherLogins)
{
<button type="submit" class="btn btn-default" name="provider" value="@provider.AuthenticationScheme" title="Log in using your @provider.DisplayName account">@provider.AuthenticationScheme</button>
<button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.Name</button>
}
</p>
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/Pinch.SDK.WebSample/Views/Manage/SetPassword.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
<form asp-controller="Manage" asp-action="SetPassword" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
<h4>Set your password</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}
<div class="form-group">
<label asp-for="NewPassword" class="col-md-2 control-label"></label>
<div class="col-md-10">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
<h4>Add a phone number.</h4>
<h5>@ViewData["Status"]</h5>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
{
<div class="text-danger">
@Html.ValidationSummary(false, "")
</div>
}
<div class="form-group">
<label asp-for="Code" class="col-md-2 control-label"></label>
<div class="col-md-10">
Expand Down
22 changes: 20 additions & 2 deletions src/Pinch.SDK.WebSample/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
},
"Pinch": {
"SecretKey": "sk_test_...",
"PublishableKey": "pk_test_...",
"PublishableKey": "pk_test_...",
"MerchantId": "mch_...",
"ApplicationId": "app_...",
"IsLive": false
"IsLive": false
},
"Logging": {
"IncludeScopes": false,
Expand All @@ -18,5 +18,23 @@
"System": "Information",
"Microsoft": "Information"
}
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Seq" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{
"Name": "Seq",
"Args": {
"serverUrl": "http://localhost:5341",
"apiKey": ""
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "Pinch.SDK.WebSample"
}
}
}
Loading

0 comments on commit b742ae0

Please sign in to comment.