Log in user after registering

This commit is contained in:
jvyden 2021-11-20 02:35:50 -05:00
commit bb742cfbbc
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -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();