From b165d5a2ce4577d7ae8edfba072d50ede4013228 Mon Sep 17 00:00:00 2001 From: jvyden Date: Mon, 7 Feb 2022 16:20:15 -0500 Subject: [PATCH] Add 7 day cookie length Closes #149 --- ProjectLighthouse/Pages/LoginForm.cshtml.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse/Pages/LoginForm.cshtml.cs b/ProjectLighthouse/Pages/LoginForm.cshtml.cs index 7ceb63d3..f2a7ff64 100644 --- a/ProjectLighthouse/Pages/LoginForm.cshtml.cs +++ b/ProjectLighthouse/Pages/LoginForm.cshtml.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.Threading.Tasks; using JetBrains.Annotations; using Kettu; @@ -7,6 +8,7 @@ using LBPUnion.ProjectLighthouse.Helpers.Extensions; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -71,7 +73,15 @@ public class LoginForm : BaseLayout this.Database.WebTokens.Add(webToken); await this.Database.SaveChangesAsync(); - this.Response.Cookies.Append("LighthouseToken", webToken.UserToken); + this.Response.Cookies.Append + ( + "LighthouseToken", + webToken.UserToken, + new CookieOptions + { + Expires = DateTimeOffset.Now.AddDays(7), + } + ); Logger.Log($"User {user.Username} (id: {user.UserId}) successfully logged in on web", LoggerLevelLogin.Instance);