public ActionResult DoLogin(AccountPostViewModel account)
        {
            var service = new AuthenticationService();
            var status  = service.GetUserValidity(new Account
            {
                UserName = account.Name,
                Password = account.Pwd
            });

            switch (status)
            {
            case UserStatus.AuthenticatedAdmin:
                Session["IsAdmin"] = true;
                break;

            case UserStatus.AuthentucatedUser:
                Session["IsAdmin"] = false;
                break;

            case UserStatus.NonAuthenticatedUser:
                break;

            default:
                ModelState.AddModelError("AddError", "Invalid Username or password!");
                return(View("Login"));
            }
            FormsAuthentication.SetAuthCookie(account.Name, false);
            return(RedirectToAction("Index", "User"));
        }
        public ActionResult Index(AccountPostViewModel model)
        {
            var customer = HttpContext.GetCustomer();

            if (!ModelState.IsValid)
            {
                return(RedirectToAction(ActionNames.Index));
            }

            if (!Customer.NewEmailPassesDuplicationRules(model.Account.Email, customer.CustomerID))
            {
                ModelState.AddModelError("Account.Email", StringResourceProvider.GetString("createaccount_process.aspx.1"));
                return(RedirectToAction(ActionNames.Index));
            }

            // The account editor only updates the password if one was specified or if the customer has not yet registered.
            if (!customer.IsRegistered || !string.IsNullOrEmpty(model.Account.Password))
            {
                switch (ControllerHelper.ValidateAccountPassword(customer, model.Account.Password, model.Account.PasswordConfirmation))
                {
                case AccountControllerHelper.PasswordValidationResult.DoesNotMatch:
                    ModelState.AddModelError("Account.PasswordConfirmation", StringResourceProvider.GetString("account.aspx.68"));
                    return(RedirectToAction(ActionNames.Index));

                case AccountControllerHelper.PasswordValidationResult.NotStrong:
                    ModelState.AddModelError("Account.Password", StringResourceProvider.GetString("account.aspx.69"));
                    return(RedirectToAction(ActionNames.Index));

                case AccountControllerHelper.PasswordValidationResult.SameAsCurrent:
                    ModelState.AddModelError("Account.Password", StringResourceProvider.GetString("signin.aspx.30"));
                    return(RedirectToAction(ActionNames.Index));

                case AccountControllerHelper.PasswordValidationResult.SameAsPrevious:
                    ModelState.AddModelError("Account.Password", string.Format(StringResourceProvider.GetString("signin.aspx.31"), Settings.NumberOfPreviouslyUsedPasswords));
                    return(RedirectToAction(ActionNames.Index));

                default:
                case AccountControllerHelper.PasswordValidationResult.Ok:
                    break;
                }
            }

            var vatRegistationValidationResult = ControllerHelper.ValidateVatRegistrationId(model.Account, customer);

            if (!vatRegistationValidationResult.Ok)
            {
                NoticeProvider.PushNotice(
                    StringResourceProvider.GetString(
                        vatRegistationValidationResult.Message
                        ?? "account.aspx.91"),
                    NoticeType.Failure);

                return(RedirectToAction(ActionNames.Index));
            }

            ControllerHelper.UpdateAccount(model.Account, customer);
            NoticeProvider.PushNotice(StringResourceProvider.GetString("account.aspx.2"), NoticeType.Success);
            return(RedirectToAction(ActionNames.Index));
        }
Пример #3
0
        public ActionResult Index(AccountPostViewModel model)
        {
            var customer = HttpContext.GetCustomer();

            if (!ModelState.IsValid)
            {
                return(RedirectToAction(ActionNames.Index));
            }

            if (!Customer.NewEmailPassesDuplicationRules(model.Account.Email, customer.CustomerID))
            {
                ModelState.AddModelError("Account.Email", "That EMail Address is Already Used By Another Customer");
                return(RedirectToAction(ActionNames.Index));
            }

            // The account editor only updates the password if one was specified or if the customer has not yet registered.
            if (!customer.IsRegistered || !string.IsNullOrEmpty(model.Account.Password))
            {
                switch (ControllerHelper.ValidateAccountPassword(customer, model.Account.Password, model.Account.PasswordConfirmation))
                {
                case AccountControllerHelper.PasswordValidationResult.DoesNotMatch:
                    ModelState.AddModelError("Account.PasswordConfirmation", "The new passwords do not match!");
                    return(RedirectToAction(ActionNames.Index));

                case AccountControllerHelper.PasswordValidationResult.NotStrong:
                    ModelState.AddModelError("Account.Password", "The new password you created is not a strong password. Please make sure that your password is at least 8 characters long and includes at least one upper case character, one lower case character, one number, and one \"symbol\" character (e.g. ?,&,#,$,%,etc).");
                    return(RedirectToAction(ActionNames.Index));

                case AccountControllerHelper.PasswordValidationResult.SameAsCurrent:
                    ModelState.AddModelError("Account.Password", "The new password cannot be the same as the old password.");
                    return(RedirectToAction(ActionNames.Index));

                case AccountControllerHelper.PasswordValidationResult.SameAsPrevious:
                    ModelState.AddModelError("Account.Password", string.Format("The new password has been previously used.  Please select a password that has not been used in {0} previous uses.", Settings.NumberOfPreviouslyUsedPasswords));
                    return(RedirectToAction(ActionNames.Index));

                default:
                case AccountControllerHelper.PasswordValidationResult.Ok:
                    break;
                }
            }

            var vatRegistationValidationResult = ControllerHelper.ValidateVatRegistrationId(model.Account, customer);

            if (!vatRegistationValidationResult.Ok)
            {
                NoticeProvider.PushNotice(
                    AppLogic.GetString(
                        vatRegistationValidationResult.Message
                        ?? "account.aspx.91"),
                    NoticeType.Failure);

                return(RedirectToAction(ActionNames.Index));
            }

            ControllerHelper.UpdateAccount(model.Account, customer);
            NoticeProvider.PushNotice("Your account has been updated.", NoticeType.Success);
            return(RedirectToAction(ActionNames.Index));
        }