public ActionResult CreateCharity(string id, string password)
        {
            var encryptor = new Encryptor();
            password = encryptor.Encrypt(password);

            var charity = new Charity
                {
                    CharityId = id,
                    Password = password,
                    Address1 = "__",
                    Address2 = "__",
                    City = "__",
                    State = "__",
                    PostalCode = "__",
                    Essay = "__",
                    Email = "__",
                    FirstName = "__",
                    IsSearchable = false,
                    LastName = "__",
                    OrganizationName = "charity" + id,
                    Phone = "__",
                    Website = "__",
                    YearsService = 0
                };

            _charityRepository.Add(charity);

            return Json(new { awesome = "clearly true" });
        }
        public ActionResult New(CharityContainerViewModel vm)
        {
            vm.Charity.CharityId = LoggedInUser.CharityId;

            if (string.IsNullOrWhiteSpace(vm.Charity.Password))
            {
                ModelState.AddModelError("Charity.Password", "You must select a password");
            }

            if (ModelState.IsValid)
            {
                var encryptor = new Encryptor();
                vm.Charity.Password = encryptor.Encrypt(vm.Charity.Password);
                var result = _charityUpdater.Update(vm.Charity, vm.SelectedSkills, vm.SelectedAreas);

                switch (result)
                {
                    case UpdateResult.Successful:
                        return RedirectTo.Search.BoardMembers();
                    case UpdateResult.ItemAlreadyExists:
                        ModelState.AddModelError("OrganizationName", "An organization with that name already exists.");
                        break;
                }
            }

            vm.SelectedSkills = Enum.GetValues(typeof(Skill)).OfType<Skill>().ToList();
            vm.SelectedAreas = Enum.GetValues(typeof(ServiceArea)).OfType<ServiceArea>().ToList();
            vm.CurrentAreas = new List<ServiceAreaEntity>();
            vm.CurrentSkills = new List<SkillEntity>();

            return View(vm);
        }
예제 #3
0
        private void performEncryptionTestWithSchemaCheck(string functionName, string plaintext, string password, Schema schemaVersion)
        {
            Encryptor cryptor = new Encryptor();
            string encryptedB64 = cryptor.Encrypt(plaintext, password, schemaVersion);
            byte[] encrypted = Convert.FromBase64String(encryptedB64);

            Schema actualSchemaVersion = (Schema)encrypted[0];
            this.reportSuccess(functionName, actualSchemaVersion == schemaVersion);
        }
예제 #4
0
        private void performEncryptionTestWithExplicitSchema(string functionName, string plaintext, string password, Schema schemaVersion)
        {
            Encryptor cryptor = new Encryptor();
            string encrypted = cryptor.Encrypt(plaintext, password, schemaVersion);

            this.reportSuccess(functionName, encrypted != "" && encrypted != plaintext);
        }
예제 #5
0
        private void performEncryptionTest(string functionName, string plaintext, string password)
        {
            Encryptor cryptor = new Encryptor();
            string encrypted = cryptor.Encrypt(plaintext, password);

            this.reportSuccess(functionName, encrypted != "" && encrypted != plaintext);
        }
예제 #6
0
        private void testCannotUseWithUnsupportedSchemaVersions()
        {
            Encryptor encryptor = new Encryptor();
            string encryptedB64 = encryptor.Encrypt(TestStrings.SAMPLE_PLAINTEXT, TestStrings.SAMPLE_PASSWORD_A);

            byte[] encrypted = Convert.FromBase64String(encryptedB64);
            encrypted[0] = 0x03;
            string encryptedV3 = Convert.ToBase64String(encrypted);

            Decryptor decryptor = new Decryptor();
            string decrypted = decryptor.Decrypt(encryptedV3, TestStrings.SAMPLE_PASSWORD_A);

            this.reportSuccess(MethodBase.GetCurrentMethod().Name, decrypted == "");
        }
예제 #7
0
        private void performSymmetricTestWithExplicitSchema(string functionName, string plaintext, string password, Schema schemaVersion)
        {
            Encryptor encryptor = new Encryptor();
            string encryptedB64 = encryptor.Encrypt(plaintext, password, schemaVersion);

            Decryptor decryptor = new Decryptor();
            string decrypted = decryptor.Decrypt(encryptedB64, password);

            this.reportSuccess(functionName, decrypted == plaintext);
        }
예제 #8
0
        private void performSymmetricTest(string functionName, string plaintext, string password)
        {
            Encryptor encryptor = new Encryptor();
            string encryptedB64 = encryptor.Encrypt(plaintext, password);

            Decryptor decryptor = new Decryptor();
            string decrypted = decryptor.Decrypt(encryptedB64, password);

            this.reportSuccess(functionName, decrypted == plaintext);
        }
        public ActionResult Edit(CharityContainerViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var charity = vm.Charity;
                charity.CharityId = LoggedInUser.CharityId;

                var encryptor = new Encryptor();
                charity.Password = encryptor.Encrypt(charity.Password);
                var result = _charityUpdater.Update(charity, vm.SelectedSkills, vm.SelectedAreas);

                switch (result)
                {
                    case UpdateResult.Successful:
                        return RedirectTo.Search.BoardMembers();
                    case UpdateResult.ItemAlreadyExists:
                        ModelState.AddModelError("OrganizationName", "An organization with that name already exists.");
                        break;
                }
            }

            return View(vm);
        }
        public ActionResult Login(LoginViewModel vm)
        {
            var encryptor = new Encryptor();
            if (!String.IsNullOrEmpty(vm.BoardPassword))
                vm.BoardPassword = encryptor.Encrypt(vm.BoardPassword);
            if (!String.IsNullOrWhiteSpace(vm.CharityPassword))
                vm.CharityPassword = encryptor.Encrypt(vm.CharityPassword);

            if (ModelState.IsValid)
            {
                ActionResult result = null;
                string ticket = null;

                if (vm.Type == "board")
                {
                    var boardMemberId = _boardMemberRepository.ValidateLogin(vm.BoardEmail, vm.BoardPassword);

                    if (!boardMemberId.HasValue)
                    {
                        ModelState.AddModelError("BoardPassword", "Invalid login.");
                        return View(vm);
                    }

                    ticket = _formsAuth.SignIn(vm.BoardEmail, UserAuthenticationType.Board, string.Empty, boardMemberId);

                    var boardMember = _boardMemberRepository.GetBoardMember(boardMemberId.Value);

                    if (boardMemberId == null)
                    {
                        result = RedirectTo.BoardMember.New();
                    }
                    else
                    {
                        result = RedirectTo.Search.NonProfits();
                    }
                }
                else
                {
                    var charityId = _charityRepository.ValidateLogin(vm.CharityUsername, vm.CharityPassword);

                    if (string.IsNullOrWhiteSpace(charityId))
                    {
                        ModelState.AddModelError("CharityPassword", "Invalid login.");
                        return View(vm);
                    }

                    if (vm.CharityUsername == "61903")
                        ticket = _formsAuth.SignIn(vm.CharityUsername, UserAuthenticationType.UberMegaSuperUltraUser, charityId, null);
                    else
                        ticket = _formsAuth.SignIn(vm.CharityUsername, UserAuthenticationType.Charity, charityId, null);

                    var charity = _charityRepository.GetSpecificCharity(x => x.CharityId == charityId);

                    if (charity == null)
                        result = RedirectTo.NonProfit.New();
                    else
                    {
                        result = RedirectTo.Search.BoardMembers();
                    }
                }

                var cookie = new HttpCookie(FormsAuthFacade.COOKIE_NAME, ticket);
                cookie.Expires = DateTime.Now.AddDays(30);
                Response.Cookies.Add(cookie);
                return result;
            }

            return View(vm);
        }