From ab2f09fc0465f21d290f8eb77e6f8e9eff912919 Mon Sep 17 00:00:00 2001 From: Damian Karzon Date: Thu, 14 Dec 2023 16:22:47 +1000 Subject: [PATCH] Updated the SDK sample app to work again --- .../Pinch.SDK.WebSample.csproj | 25 ++++++++--------- src/Pinch.SDK.WebSample/Program.cs | 28 +++++++++++++++---- .../Properties/launchSettings.json | 22 +++------------ src/Pinch.SDK.WebSample/Startup.cs | 26 +++++++---------- .../Manage/ManageLoginsViewModel.cs | 1 - .../Account/ExternalLoginConfirmation.cshtml | 7 ++++- .../Views/Account/Login.cshtml | 15 ++++++---- .../Views/Account/Register.cshtml | 7 ++++- .../Views/Account/ResetPassword.cshtml | 7 ++++- .../Views/Account/VerifyCode.cshtml | 7 ++++- .../Views/Manage/AddPhoneNumber.cshtml | 7 ++++- .../Views/Manage/ChangePassword.cshtml | 7 ++++- .../Views/Manage/ManageLogins.cshtml | 3 +- .../Views/Manage/SetPassword.cshtml | 7 ++++- .../Views/Manage/VerifyPhoneNumber.cshtml | 7 ++++- src/Pinch.SDK.WebSample/appsettings.json | 22 +++++++++++++-- src/Pinch.SDK.WebSample/web.config | 4 +-- src/Pinch.SDK/Pinch.SDK.csproj | 3 +- 18 files changed, 130 insertions(+), 75 deletions(-) diff --git a/src/Pinch.SDK.WebSample/Pinch.SDK.WebSample.csproj b/src/Pinch.SDK.WebSample/Pinch.SDK.WebSample.csproj index 1c27cef..ac11890 100644 --- a/src/Pinch.SDK.WebSample/Pinch.SDK.WebSample.csproj +++ b/src/Pinch.SDK.WebSample/Pinch.SDK.WebSample.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + net6.0 aspnet5-Pinch.SDK.WebSample-035714b9-1391-452f-876c-de29839a80c8 @@ -9,11 +9,16 @@ - - - - - + + + + + + + + + + @@ -22,12 +27,4 @@ - - - - - - - - diff --git a/src/Pinch.SDK.WebSample/Program.cs b/src/Pinch.SDK.WebSample/Program.cs index 66c7c24..9225382 100644 --- a/src/Pinch.SDK.WebSample/Program.cs +++ b/src/Pinch.SDK.WebSample/Program.cs @@ -4,6 +4,10 @@ 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 { @@ -11,11 +15,25 @@ public class Program { public static void Main(string[] args) { - var host = new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseStartup() + 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(); + }) .Build(); host.Run(); diff --git a/src/Pinch.SDK.WebSample/Properties/launchSettings.json b/src/Pinch.SDK.WebSample/Properties/launchSettings.json index f59670a..8936e22 100644 --- a/src/Pinch.SDK.WebSample/Properties/launchSettings.json +++ b/src/Pinch.SDK.WebSample/Properties/launchSettings.json @@ -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" } } } \ No newline at end of file diff --git a/src/Pinch.SDK.WebSample/Startup.cs b/src/Pinch.SDK.WebSample/Startup.cs index 7a49a03..3b027b8 100644 --- a/src/Pinch.SDK.WebSample/Startup.cs +++ b/src/Pinch.SDK.WebSample/Startup.cs @@ -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) @@ -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 { @@ -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(); }); } } diff --git a/src/Pinch.SDK.WebSample/ViewModels/Manage/ManageLoginsViewModel.cs b/src/Pinch.SDK.WebSample/ViewModels/Manage/ManageLoginsViewModel.cs index 29598c1..b39bfd9 100644 --- a/src/Pinch.SDK.WebSample/ViewModels/Manage/ManageLoginsViewModel.cs +++ b/src/Pinch.SDK.WebSample/ViewModels/Manage/ManageLoginsViewModel.cs @@ -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 diff --git a/src/Pinch.SDK.WebSample/Views/Account/ExternalLoginConfirmation.cshtml b/src/Pinch.SDK.WebSample/Views/Account/ExternalLoginConfirmation.cshtml index 59f9ba8..539aa57 100644 --- a/src/Pinch.SDK.WebSample/Views/Account/ExternalLoginConfirmation.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Account/ExternalLoginConfirmation.cshtml @@ -9,7 +9,12 @@

Association Form


-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }

You've successfully authenticated with @ViewData["LoginProvider"]. diff --git a/src/Pinch.SDK.WebSample/Views/Account/Login.cshtml b/src/Pinch.SDK.WebSample/Views/Account/Login.cshtml index c7155aa..d83a078 100644 --- a/src/Pinch.SDK.WebSample/Views/Account/Login.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Account/Login.cshtml @@ -1,6 +1,4 @@ @using System.Collections.Generic -@using Microsoft.AspNet.Http -@using Microsoft.AspNet.Http.Authentication @model LoginViewModel @inject SignInManager SignInManager @@ -15,7 +13,12 @@

Use a local account to log in.


-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }
@@ -57,8 +60,8 @@

Use another service to log in.


@{ - var loginProviders = SignInManager.GetExternalAuthenticationSchemes().ToList(); - if (loginProviders.Count == 0) + var loginProviders = await SignInManager.GetExternalAuthenticationSchemesAsync(); + if (loginProviders.Count() == 0) {

@@ -74,7 +77,7 @@

@foreach (var provider in loginProviders) { - + }

diff --git a/src/Pinch.SDK.WebSample/Views/Account/Register.cshtml b/src/Pinch.SDK.WebSample/Views/Account/Register.cshtml index da86fec..753d1b9 100644 --- a/src/Pinch.SDK.WebSample/Views/Account/Register.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Account/Register.cshtml @@ -8,7 +8,12 @@

Create a new account.


-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }
diff --git a/src/Pinch.SDK.WebSample/Views/Account/ResetPassword.cshtml b/src/Pinch.SDK.WebSample/Views/Account/ResetPassword.cshtml index 7ddf52f..698fab7 100644 --- a/src/Pinch.SDK.WebSample/Views/Account/ResetPassword.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Account/ResetPassword.cshtml @@ -8,7 +8,12 @@

Reset your password.


-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }
diff --git a/src/Pinch.SDK.WebSample/Views/Account/VerifyCode.cshtml b/src/Pinch.SDK.WebSample/Views/Account/VerifyCode.cshtml index af98c78..5a28214 100644 --- a/src/Pinch.SDK.WebSample/Views/Account/VerifyCode.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Account/VerifyCode.cshtml @@ -6,7 +6,12 @@

@ViewData["Title"].

-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }

@ViewData["Status"]

diff --git a/src/Pinch.SDK.WebSample/Views/Manage/AddPhoneNumber.cshtml b/src/Pinch.SDK.WebSample/Views/Manage/AddPhoneNumber.cshtml index daf3bb2..bc907c4 100644 --- a/src/Pinch.SDK.WebSample/Views/Manage/AddPhoneNumber.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Manage/AddPhoneNumber.cshtml @@ -7,7 +7,12 @@

Add a phone number.


-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }
diff --git a/src/Pinch.SDK.WebSample/Views/Manage/ChangePassword.cshtml b/src/Pinch.SDK.WebSample/Views/Manage/ChangePassword.cshtml index ce0e757..714b0e6 100644 --- a/src/Pinch.SDK.WebSample/Views/Manage/ChangePassword.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Manage/ChangePassword.cshtml @@ -8,7 +8,12 @@

Change Password Form


-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }
diff --git a/src/Pinch.SDK.WebSample/Views/Manage/ManageLogins.cshtml b/src/Pinch.SDK.WebSample/Views/Manage/ManageLogins.cshtml index 3a809b2..5d9d56b 100644 --- a/src/Pinch.SDK.WebSample/Views/Manage/ManageLogins.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Manage/ManageLogins.cshtml @@ -1,5 +1,4 @@ @model ManageLoginsViewModel -@using Microsoft.AspNet.Http.Authentication @{ ViewData["Title"] = "Manage your external logins"; } @@ -46,7 +45,7 @@

@foreach (var provider in Model.OtherLogins) { - + }

diff --git a/src/Pinch.SDK.WebSample/Views/Manage/SetPassword.cshtml b/src/Pinch.SDK.WebSample/Views/Manage/SetPassword.cshtml index d7c72a9..89f02f5 100644 --- a/src/Pinch.SDK.WebSample/Views/Manage/SetPassword.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Manage/SetPassword.cshtml @@ -11,7 +11,12 @@

Set your password


-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }
diff --git a/src/Pinch.SDK.WebSample/Views/Manage/VerifyPhoneNumber.cshtml b/src/Pinch.SDK.WebSample/Views/Manage/VerifyPhoneNumber.cshtml index a0e508d..a263943 100644 --- a/src/Pinch.SDK.WebSample/Views/Manage/VerifyPhoneNumber.cshtml +++ b/src/Pinch.SDK.WebSample/Views/Manage/VerifyPhoneNumber.cshtml @@ -10,7 +10,12 @@

Add a phone number.

@ViewData["Status"]

-
+ @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any())) + { +
+ @Html.ValidationSummary(false, "") +
+ }
diff --git a/src/Pinch.SDK.WebSample/appsettings.json b/src/Pinch.SDK.WebSample/appsettings.json index ed0eab6..26997e3 100644 --- a/src/Pinch.SDK.WebSample/appsettings.json +++ b/src/Pinch.SDK.WebSample/appsettings.json @@ -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, @@ -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" + } } } diff --git a/src/Pinch.SDK.WebSample/web.config b/src/Pinch.SDK.WebSample/web.config index e04a039..3053d98 100644 --- a/src/Pinch.SDK.WebSample/web.config +++ b/src/Pinch.SDK.WebSample/web.config @@ -2,8 +2,8 @@ - + - + \ No newline at end of file diff --git a/src/Pinch.SDK/Pinch.SDK.csproj b/src/Pinch.SDK/Pinch.SDK.csproj index 7859f5a..7eed0e4 100644 --- a/src/Pinch.SDK/Pinch.SDK.csproj +++ b/src/Pinch.SDK/Pinch.SDK.csproj @@ -22,7 +22,8 @@ - + +