From 77f17b9f671a1ab179f4c368873c951ede267859 Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Mon, 5 Jun 2023 11:45:20 -0400 Subject: [PATCH 1/8] support reconnecting and refreshing note content --- Controllers/ApiController.cs | 17 +++++++++++++++++ wwwroot/js/site.js | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 Controllers/ApiController.cs diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs new file mode 100644 index 0000000..2112ea0 --- /dev/null +++ b/Controllers/ApiController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; +using BinaryDad.Notes.Services; + +namespace BinaryDad.Notes.Controllers +{ + public class ApiController : ControllerBase + { + private readonly INoteService noteService; + + public ApiController(INoteService noteService) + { + this.noteService = noteService; + } + + public string Note() => noteService.Get(); + } +} diff --git a/wwwroot/js/site.js b/wwwroot/js/site.js index 6aa913e..febc9f0 100644 --- a/wwwroot/js/site.js +++ b/wwwroot/js/site.js @@ -53,6 +53,15 @@ $(function () { showToast('#update-indicator'); }); + // update content after reconnected + connection.onreconnected(function() { + $.get('api/note', function(content) { + $textarea.val(content); + showToast('#update-indicator'); + console.log('Refreshed after disconnect'); + }); + }); + // set dark mode if (window.location.hash == '#dark') { $('body').addClass('dark'); From df0a36256b8b4dae85d1fc963e734205e60258f6 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 8 Jun 2023 13:45:57 +0000 Subject: [PATCH 2/8] simplified dockerfile --- Dockerfile | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4b5a78d..3ed91c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,13 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /src +COPY . . + +RUN dotnet publish "BinaryDad.Notes.csproj" -c Release -o /app/publish /p:UseAppHost=false FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base WORKDIR /app +COPY --from=build /app/publish . + EXPOSE 80 -EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /src -COPY ["BinaryDad.Notes.csproj", "."] -RUN dotnet restore "./BinaryDad.Notes.csproj" -COPY . . -WORKDIR "/src/." -RUN dotnet build "BinaryDad.Notes.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "BinaryDad.Notes.csproj" -c Release -o /app/publish /p:UseAppHost=false - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "BinaryDad.Notes.dll"] \ No newline at end of file From 1683aa85b7b53971276d85240280b5ec86ce1486 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 9 Jun 2023 10:10:32 -0400 Subject: [PATCH 3/8] remove unused title from login page --- Views/Login/Login.cshtml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Views/Login/Login.cshtml b/Views/Login/Login.cshtml index eb41cc8..21b6c85 100644 --- a/Views/Login/Login.cshtml +++ b/Views/Login/Login.cshtml @@ -1,8 +1,4 @@ -@{ - ViewBag.Title = "Login"; -} - -@Html.ValidationSummary() +@Html.ValidationSummary()
From 013f0c03ac44e9c05d41573f151a4e9e41030a14 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 9 Jun 2023 10:13:52 -0400 Subject: [PATCH 4/8] fix dark on login page --- wwwroot/css/site.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index e4db9cd..f26867a 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -35,7 +35,7 @@ textarea { border-width: 0; } -.dark textarea { +body.dark, body.dark input, body.dark textarea { background-color: #222; color: #ddd; } From b5e590f50a9c8cef6b5ac3553888c5f809801689 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 9 Jun 2023 23:23:33 -0400 Subject: [PATCH 5/8] adjust auth cookie timeout to 12 hours --- Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Program.cs b/Program.cs index c361739..e413b02 100644 --- a/Program.cs +++ b/Program.cs @@ -17,6 +17,7 @@ builder.Services.AddSession(options => builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o => { o.LoginPath = "/login"; + o.Cookie.MaxAge = TimeSpan.FromHours(12); }); var app = builder.Build(); From bf46dac9eb58a67f8fa3efb1342f8a10258efffe Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 21 Jun 2023 10:48:13 -0400 Subject: [PATCH 6/8] don't check for cert on vscode --- .vscode/launch.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1768fa5..60f7113 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,7 +24,8 @@ }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" - } + }, + "checkForDevCert": false }, { "name": ".NET Core Attach", From c34dc876c057f58fa2e874a112eb1cd818d226cc Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 21 Jun 2023 10:48:57 -0400 Subject: [PATCH 7/8] don't need session --- Program.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Program.cs b/Program.cs index e413b02..80018da 100644 --- a/Program.cs +++ b/Program.cs @@ -9,11 +9,6 @@ builder.Services.AddControllersWithViews(); builder.Services.AddSignalR(); builder.Services.AddSingleton(); -builder.Services.AddSession(options => -{ - options.IdleTimeout = TimeSpan.FromMinutes(30); -}); - builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o => { o.LoginPath = "/login"; From c8f3c5225d923e2bc6bc43a2b746588b1fa4976b Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 21 Jun 2023 10:49:13 -0400 Subject: [PATCH 8/8] increase cookie timeout to 3 days --- Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 80018da..f97f485 100644 --- a/Program.cs +++ b/Program.cs @@ -12,7 +12,8 @@ builder.Services.AddSingleton(); builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o => { o.LoginPath = "/login"; - o.Cookie.MaxAge = TimeSpan.FromHours(12); + o.Cookie.Name = "NotesUser"; + o.Cookie.MaxAge = TimeSpan.FromDays(3); }); var app = builder.Build();