Added some minor tweaks, and set up the EmployeeController to be usable by a frontend to see how well all this works so far.
This commit is contained in:
@@ -20,9 +20,8 @@ namespace SecureCore.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
if (HttpContext.Request.Cookies.ContainsKey("Session"))
|
||||
if (SessionManager.IsSessionTokenValid(HttpContext.Request.Cookies["Session"], connectionString))
|
||||
return Ok("Logged in\n");
|
||||
if (SessionManager.IsSessionTokenValid(HttpContext))
|
||||
return Ok("Logged in\n");
|
||||
|
||||
//Verify that the username provided is valid, i.e. no whitespace, special characters, etc.
|
||||
var result = UserDataService.IsUsernameValid(info.Username);
|
||||
@@ -47,7 +46,7 @@ namespace SecureCore.Controllers
|
||||
|
||||
SessionManager.Login(info.Username, sessionToken, cookieOptions.Expires.Value.UtcDateTime, agent, ip, connectionString);
|
||||
|
||||
HttpContext.Response.Cookies.Append("Session", sessionToken, cookieOptions);
|
||||
HttpContext.Response.Cookies.Append(SessionManager.SessionCookieName, sessionToken, cookieOptions);
|
||||
|
||||
return Ok($"Logged in success{Environment.NewLine}");
|
||||
}
|
||||
@@ -89,7 +88,7 @@ namespace SecureCore.Controllers
|
||||
|
||||
var i = UserDataService.RegisterNewUser(info.Username, info.Email, hash, salt, sessionToken, cookieOptions.Expires.Value.UtcDateTime, agent, ip, connectionString);
|
||||
|
||||
HttpContext.Response.Cookies.Append("Session", sessionToken, cookieOptions);
|
||||
HttpContext.Response.Cookies.Append(SessionManager.SessionCookieName, sessionToken, cookieOptions);
|
||||
|
||||
return Ok($"New User ID: {i}");
|
||||
}
|
||||
@@ -109,14 +108,14 @@ namespace SecureCore.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
SessionManager.Logout(HttpContext.Request.Cookies["Session"], connectionString);
|
||||
SessionManager.Logout(HttpContext.Request.Cookies[SessionManager.SessionCookieName], connectionString);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//TODO: decide what to do here. If the SQL fails to clear the token from the database, do we want to clear the token cookie?
|
||||
}
|
||||
|
||||
HttpContext.Response.Cookies.Delete("Session");
|
||||
HttpContext.Response.Cookies.Delete(SessionManager.SessionCookieName);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user