diff --git a/ProjectLighthouse/Pages/ExternalAuth/RegisterForm.cshtml.cs b/ProjectLighthouse/Pages/ExternalAuth/RegisterForm.cshtml.cs index de254889..6fb36a90 100644 --- a/ProjectLighthouse/Pages/ExternalAuth/RegisterForm.cshtml.cs +++ b/ProjectLighthouse/Pages/ExternalAuth/RegisterForm.cshtml.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Pages.Layouts; +using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -28,7 +29,20 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth bool userExists = await this.Database.Users.FirstOrDefaultAsync(u => u.Username.ToLower() == username.ToLower()) != null; if (userExists) return this.BadRequest(); - await this.Database.CreateUser(username, HashHelper.BCryptHash(password)); + User user = await this.Database.CreateUser(username, HashHelper.BCryptHash(password)); + + WebToken webToken = new() + { + UserId = user.UserId, + UserToken = HashHelper.GenerateAuthToken(), + }; + + this.Database.WebTokens.Add(webToken); + await this.Database.SaveChangesAsync(); + + this.Response.Cookies.Append("LighthouseToken", webToken.UserToken); + + return this.RedirectToPage(nameof(LandingPage)); } return this.Page();