Exemple #1
0
        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());
        }
Exemple #2
0
        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());
        }
Exemple #3
0
        public void TellPublicAboutVisibleElections()
        {
            var list = new PublicElectionLister().RefreshAndGetListOfAvailableElections();

            CoreHub.Clients.Group(HubNameForPublic).ElectionsListUpdated(list);
        }