mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-05 11:28:39 +00:00
Log in user after registering
This commit is contained in:
parent
f005aca48c
commit
bb742cfbbc
1 changed files with 15 additions and 1 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue