automatically log open id user in after they've registered.
This commit is contained in:
@@ -153,6 +153,21 @@ namespace CarCareTracker.Controllers
|
|||||||
public IActionResult RegisterOpenIdUser(LoginModel credentials)
|
public IActionResult RegisterOpenIdUser(LoginModel credentials)
|
||||||
{
|
{
|
||||||
var result = _loginLogic.RegisterOpenIdUser(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);
|
return Json(result);
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace CarCareTracker.Logic
|
|||||||
var result = _userData.SaveUserRecord(newUser);
|
var result = _userData.SaveUserRecord(newUser);
|
||||||
if (result)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
$.post('/Login/RegisterOpenIdUser', { userName: userName, token: token, emailAddress: userEmail }, function (data) {
|
$.post('/Login/RegisterOpenIdUser', { userName: userName, token: token, emailAddress: userEmail }, function (data) {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
successToast(data.message);
|
successToast(data.message);
|
||||||
setTimeout(function () { window.location.href = '/Login/Index' }, 500);
|
setTimeout(function () { window.location.href = '/Home' }, 500);
|
||||||
} else {
|
} else {
|
||||||
errorToast(data.message);
|
errorToast(data.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user