Ejemplo n.º 1
0
        public ActionResult Setup(AdministratorSetupModel model, string returnUrl)
        {
            ICardHolderService CardHolderService;

            if (ModelState.IsValid)
            {
                if (model.Password == model.RepeatPassword)
                {
                    if (model.SecondPassword == model.RepeatSecondPassword)
                    {
                        try
                        {
                            CardHolderService = new CardHolderService();
                            CardHolderService.CreateSuperUser(model.UserName, model.Password, model.SecondPassword);
                            return(RedirectToAction("AdministratorLogOn", "Account"));
                        }
                        catch (Exception Ex)
                        {
                            ModelState.AddModelError("", "Error in system initialization:" + Ex.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("RepeatSecondPassword", "The password does not match.");
                    }
                }
                else
                {
                    ModelState.AddModelError("RepeatPassword", "The password does not match.");
                }
            }
            System.Threading.Thread.Sleep(1000);  // force a one second delay for security purposes
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult AddSystemAdmin(AdministratorSetupModel model, string returnUrl)
        {
            ICardHolderService CardHolderService;

            // move tests here to make sure that we handle them better
            if ((model.Password != null) && (model.RepeatPassword != null))
            {
                if (model.Password != model.RepeatPassword)
                {
                    ModelState.AddModelError("RepeatPassword", "The password does not match.");
                }
            }
            if ((model.SecondPassword != null) && (model.RepeatSecondPassword != null))
            {
                if (model.SecondPassword != model.RepeatSecondPassword)
                {
                    ModelState.AddModelError("RepeatSecondPassword", "The password does not match.");
                }
            }
            if (String.IsNullOrEmpty(model.UserName))
            {
                ModelState.AddModelError("UserName", "Value cannot be null or empty.");
            }
            if (String.IsNullOrEmpty(model.Password))
            {
                ModelState.AddModelError("Password", "Value cannot be null or empty.");
            }
            if (String.IsNullOrEmpty(model.SecondPassword))
            {
                ModelState.AddModelError("SecondPassword", "Value cannot be null or empty.");
            }

            MembershipProvider _provider = Membership.Providers["GiftUserMembershipProvider"];

            if (model.UserName != null)
            {
                if (_provider.GetUserNameByEmail(model.UserName + "@system") != "")
                {
                    ModelState.AddModelError("UserName", "UserName@system is already on the system");
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    CardHolderService = new CardHolderService();
                    CardHolderService.CreateSystemAdmin(model.UserName, model.Password, model.SecondPassword);
                    return(RedirectToAction("Index"));
                }
                catch (Exception Ex)
                {
                    ModelState.AddModelError("", Common.StandardExceptionErrorMessage(Ex));
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }