public IActionResult SignIn() { try { if (HttpContext.Request.Cookies.TryGetValue("sessionId", out string sessionId)) { _session = _dataAccessor.GetSessionData(sessionId); if (_session == null) { //remove the associated cookie Response.Cookies.Delete("sessionId"); throw new InvalidCredentialsException(); } UserPageModel secretMatch = buildUserPageModelFromDB(_session.User); if (string.IsNullOrEmpty(secretMatch.TheirSecretMatch)) { return(RedirectToAction("GetMatch")); } return(View("UserPage", secretMatch)); } return(View("SignIn", new AuthenticatedUser())); } catch (InvalidCredentialsException) { return(View("InvalidCredentials")); } catch (UnregisteredUserException) { return(View("InvalidCredentials")); } catch (Exception) { return(View("Error")); } }
public IActionResult SignIn(AuthenticatedUser authUser) { try { //get a new session for this user _session = _dataAccessor.GetSession(authUser.Username, authUser.Password); if (_session == null) { throw new InvalidCredentialsException(); } //store the cookie Response.Cookies.Append("sessionId", _session.SessionId); UserPageModel secretMatch = buildUserPageModelFromDB(authUser.Username); if (string.IsNullOrEmpty(secretMatch.TheirSecretMatch)) { return(RedirectToAction("GetMatch")); } return(View("UserPage", secretMatch)); } catch (InvalidCredentialsException) { return(View("InvalidCredentials")); } catch (UnregisteredUserException) { return(View("InvalidCredentials")); } catch (Exception) { return(View("Error")); } }
public IActionResult Register(RegisterUser registration) { bool.TryParse(_dataAccessor.GetSettingValue("AllowRegistration"), out bool allowRegister); if (!allowRegister) { return(View("SignIn", new AuthenticatedUser())); } if (!string.Equals(registration.ChosenPassword, registration.VerifyPassword, StringComparison.Ordinal)) { return(View("PasswordsNotMatch")); } if (_dataAccessor.AccountAlreadyRegistered(registration.NameToRegister)) { return(View("AlreadyRegistered", registration)); } _dataAccessor.RegisterAccount(registration.NameToRegister, registration.ChosenPassword); //get a new session for this user DataAccess.Models.ISession session = _dataAccessor.GetSession(registration.NameToRegister, registration.ChosenPassword); if (session == null) { throw new InvalidCredentialsException(); } //store the cookie Response.Cookies.Append("sessionId", session.SessionId); return(RedirectToAction("GetMatch")); }
private bool verifySessionCookie() { if (HttpContext.Request.Cookies.TryGetValue("sessionId", out string sessionId)) { _session = _dataAccessor.GetSessionData(sessionId); return(_session != null); } return(false); }