automatically log open id user in after they've registered.

This commit is contained in:
DESKTOP-T0O5CDB\DESK-555BD 2024-02-16 11:06:49 -07:00
parent f46bbe9963
commit b7158f3bf0
3 changed files with 17 additions and 2 deletions

View File

@ -153,6 +153,21 @@ namespace CarCareTracker.Controllers
public IActionResult RegisterOpenIdUser(LoginModel credentials)
{
var result = _loginLogic.RegisterOpenIdUser(credentials);
if (result.Success)
{
var userData = _loginLogic.ValidateOpenIDUser(new LoginModel() { EmailAddress = credentials.EmailAddress });
if (userData.Id != default)
{
AuthCookie authCookie = new AuthCookie
{
UserData = userData,
ExpiresOn = DateTime.Now.AddDays(1)
};
var serializedCookie = JsonSerializer.Serialize(authCookie);
var encryptedCookie = _dataProtector.Protect(serializedCookie);
Response.Cookies.Append("ACCESS_TOKEN", encryptedCookie, new CookieOptions { Expires = new DateTimeOffset(authCookie.ExpiresOn) });
}
}
return Json(result);
}
[HttpPost]

View File

@ -93,7 +93,7 @@ namespace CarCareTracker.Logic
var result = _userData.SaveUserRecord(newUser);
if (result)
{
return new OperationResponse { Success = true, Message = "You will be redirected to the login page briefly." };
return new OperationResponse { Success = true, Message = "You will be logged in briefly." };
}
else
{

View File

@ -41,7 +41,7 @@
$.post('/Login/RegisterOpenIdUser', { userName: userName, token: token, emailAddress: userEmail }, function (data) {
if (data.success) {
successToast(data.message);
setTimeout(function () { window.location.href = '/Login/Index' }, 500);
setTimeout(function () { window.location.href = '/Home' }, 500);
} else {
errorToast(data.message);
}