示例#1
0
        /// <summary>
        /// Returns errors for Account creation
        /// </summary>
        /// <param name="accountStatus">Account status</param>
        /// <returns>error message</returns>
        private static string ErrorCodeToString(AccountCreateStatus accountStatus)
        {
            // a full list of status codes.
            switch (accountStatus)
            {
            case AccountCreateStatus.InvalidPasswordAnswer:
                return("The password answer provided is invalid. Please check the value and try again.");

            case AccountCreateStatus.InvalidPassword:
                return("The current password is incorrect or the new password is invalid. Please check the value and try again.");

            case AccountCreateStatus.InvalidQuestion:
                return("The password retrieval question provided is invalid. Please check the value and try again.");

            case AccountCreateStatus.InvalidUserName:
                return("The user name provided is invalid. Please check the value and try again.");

            case AccountCreateStatus.PasswordResetDisabled:
                return("Password reset is not allowed at this time.");

            case AccountCreateStatus.PasswordCreateFailed:
                return("There was a problem creating your new password.");

            case AccountCreateStatus.PasswordEmailFailed:
                return("An error has prevented the emailing of your new password. Please try again.");

            case AccountCreateStatus.UserNotYetApproved:
                return("Your account has not been approved yet.");

            case AccountCreateStatus.UserAccountLocked:
                return("Your account has been locked. Please contact the System Administrator to unlock your account.");

            case AccountCreateStatus.UserRejected:
                return("Your credentials were not accepted. Please check you user name and password and try again.");

            default:
                return("An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.");
            }
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                AccountCreateStatus createStatus = AccountManager.CreateUser(model);
                if (createStatus == AccountCreateStatus.Success)
                {
                    MigrateShoppingCart(model.UserName);
                    //bejelentkezés
                    Session[LOGGEDINUSER_SESSION_KEY] = AccountManager.GetAccount(model);
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        private static string ErrorCodeToString(AccountCreateStatus createStatus)
        {
            // See http://go.microsoft.com/fwlink/?LinkID=177550 for
            // a full list of status codes.
            switch (createStatus)
            {
            case AccountCreateStatus.DuplicateUserName:
                return("User name already exists. Please enter a different user name.");

            case AccountCreateStatus.DuplicateEmail:
                return("A user name for that e-mail address already exists. Please enter a different e-mail address.");

            case AccountCreateStatus.InvalidPassword:
                return("The password provided is invalid. Please enter a valid password value.");

            case AccountCreateStatus.InvalidEmail:
                return("The e-mail address provided is invalid. Please check the value and try again.");

            case AccountCreateStatus.InvalidAnswer:
                return("The password retrieval answer provided is invalid. Please check the value and try again.");

            case AccountCreateStatus.InvalidQuestion:
                return("The password retrieval question provided is invalid. Please check the value and try again.");

            case AccountCreateStatus.InvalidUserName:
                return("The user name provided is invalid. Please check the value and try again.");

            case AccountCreateStatus.ProviderError:
                return("The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.");

            case AccountCreateStatus.UserRejected:
                return("The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.");

            default:
                return("An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.");
            }
        }
        /// <summary>
        /// Returns errors for Account creation
        /// </summary>
        /// <param name="accountStatus">Account status</param>
        /// <returns>error message</returns>
        private static string ErrorCodeToString(AccountCreateStatus accountStatus)
        {
            // a full list of status codes.
            switch (accountStatus)
            {
                case AccountCreateStatus.InvalidPasswordAnswer:
                    return "The password answer provided is invalid. Please check the value and try again.";

                case AccountCreateStatus.InvalidPassword:
                    return "The current password is incorrect or the new password is invalid. Please check the value and try again.";

                case AccountCreateStatus.InvalidQuestion:
                    return "The password retrieval question provided is invalid. Please check the value and try again.";

                case AccountCreateStatus.InvalidUserName:
                    return "The user name provided is invalid. Please check the value and try again.";

                case AccountCreateStatus.PasswordResetDisabled:
                    return "Password reset is not allowed at this time.";

                case AccountCreateStatus.PasswordCreateFailed:
                    return "There was a problem creating your new password.";

                case AccountCreateStatus.PasswordEmailFailed:
                    return "An error has prevented the emailing of your new password. Please try again.";

                  case AccountCreateStatus.UserNotYetApproved:
                    return "Your account has not been approved yet.";

                  case AccountCreateStatus.UserAccountLocked:
                    return "Your account has been locked. Please contact the System Administrator to unlock your account.";

                  case AccountCreateStatus.UserRejected:
                    return "Your credentials were not accepted. Please check you user name and password and try again.";

                default:
                    return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
            }
        }