public JsonResult GrantAccessToGuestTeller(int electionId, string secretCode) { var model = new ElectionModel(); var desiredElection = model.VisibleElections().SingleOrDefault(e => e.C_RowId == electionId && e.ElectionPasscode == secretCode); if (desiredElection == null) { return new { Error = "Sorry, unable to join that election" }.AsJsonResult(); } var fakeUserName = HttpContext.Current.Session.SessionID.Substring(0, 5) + Guid.NewGuid().ToString().Substring(0, 5); FormsAuthentication.SetAuthCookie(fakeUserName, false); UserSession.ProcessLogin(); UserSession.IsGuestTeller = true; model.JoinIntoElection(desiredElection.ElectionGuid); return new { LoggedIn = true }.AsJsonResult(); }
public JsonResult GrantAccessToGuestTeller(Guid electionGuid, string codeToTry, Guid oldComputerGuid) { var electionModel = new ElectionModel(); var passcode = new PublicElectionLister().GetPasscodeIfAvailable(electionGuid); if (passcode == null) { return(new { Error = "Sorry, unknown election id" }.AsJsonResult()); } if (passcode != codeToTry) { return(new { Error = "Sorry, invalid code entered" }.AsJsonResult()); } if (!UserSession.IsLoggedInTeller) { var fakeUserName = "******" + HttpContext.Current.Session.SessionID.Substring(0, 5) + Guid.NewGuid().ToString().Substring(0, 5); // FormsAuthentication.SetAuthCookie(fakeUserName, true); var claims = new List <Claim> { new Claim("UserName", fakeUserName), new Claim("IsGuestTeller", "true"), new Claim("UniqueID", fakeUserName), }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationType); var authenticationProperties = new AuthenticationProperties() { AllowRefresh = true, IsPersistent = false, ExpiresUtc = DateTime.UtcNow.AddDays(7) }; HttpContext.Current.GetOwinContext().Authentication.SignIn(authenticationProperties, identity); UserSession.IsGuestTeller = true; } electionModel.JoinIntoElection(electionGuid, oldComputerGuid); return(new { LoggedIn = true, CompGuid = UserSession.CurrentComputer.ComputerGuid }.AsJsonResult()); }
public JsonResult SelectElection(Guid guid) { var electionModel = new ElectionModel(); if (electionModel.JoinIntoElection(guid)) { return new { Locations = ContextItems.LocationModel.Locations.OrderBy(l => l.SortOrder).Select(l => new { l.Name, l.C_RowId }), Selected = true, ElectionName = UserSession.CurrentElectionName, Pulse = new PulseModel(this).Pulse() }.AsJsonResult(); } return new {Selected = false}.AsJsonResult(); }
public JsonResult GrantAccessToGuestTeller(Guid electionGuid, string codeToTry, Guid oldComputerGuid) { var electionModel = new ElectionModel(); var passcode = new PublicElectionLister().GetPasscodeIfAvailable(electionGuid); if (passcode == null) { return(new { Error = "Sorry, unknown election id" }.AsJsonResult()); } if (passcode != codeToTry) { return(new { Error = "Sorry, invalid code entered" }.AsJsonResult()); } if (!UserSession.IsLoggedIn) { var fakeUserName = HttpContext.Current.Session.SessionID.Substring(0, 5) + Guid.NewGuid().ToString().Substring(0, 5); FormsAuthentication.SetAuthCookie(fakeUserName, true); UserSession.IsGuestTeller = true; } electionModel.JoinIntoElection(electionGuid, oldComputerGuid); return(new { LoggedIn = true, CompGuid = UserSession.CurrentComputer.ComputerGuid }.AsJsonResult()); }