public async Task <ActionResult> ResetPassword(PageViewModel <ResetPasswordViewModel> uploadModel)
        {
            var metadata = new Models.PageMetadata
            {
                Title = Localize("Identity.Account.ResetPassword.Title")
            };

            var message     = ConcatenateContactAdmin("General.Error");
            var messageType = MessageType.Error;

            if (ModelState.IsValid)
            {
                var accountResult = await _accountManager.ResetPasswordAsync(uploadModel.Data);

                if (accountResult.Success)
                {
                    message     = Localize("Identity.Account.ResetPassword.Success.Message");
                    messageType = MessageType.Info;

                    if (HttpContext.User.Identity?.IsAuthenticated == false)
                    {
                        var signInAppendix = ResHelper.GetStringFormat("Identity.Account.ResetPassword.Success.SignInAppendix", Url.Action(nameof(SignIn)));
                        message = message.Insert(message.Length, $" {signInAppendix}");
                    }
                }
            }

            return(View("UserMessage", GetPageViewModel(metadata, uploadModel.Data, message, false, true, messageType)));
        }
        // GET: /Account/ConfirmUser
        public async Task <ActionResult> ConfirmUser(int?userId, string token)
        {
            var metadata = new Models.PageMetadata
            {
                Title = ErrorTitle
            };

            var message      = ConcatenateContactAdmin("General.Error");
            var displayAsRaw = false;
            var messageType  = MessageType.Error;

            if (userId.HasValue)
            {
                var accountResult = await _accountManager.ConfirmUserAsync(userId.Value, token);

                switch (accountResult.ResultState)
                {
                case ConfirmUserResultState.EmailNotConfirmed:
                    message = Localize("Identity.Account.ConfirmUser.ConfirmationFailure.Message");
                    break;

                case ConfirmUserResultState.UserConfirmed:
                    metadata.Title = Localize("Identity.Account.ConfirmUser.Success.Title");
                    message        = ResHelper.GetStringFormat("Identity.Account.ConfirmUser.Success.Message", Url.Action(nameof(SignIn)));
                    displayAsRaw   = true;
                    messageType    = MessageType.Info;
                    break;
                }
            }

            return(View("UserMessage", GetPageViewModel(metadata, message, false, displayAsRaw, messageType)));
        }
        // GET: /Account/ResetPassword
        public async Task <ActionResult> ResetPassword(int?userId, string token)
        {
            var metadata = new Models.PageMetadata();
            var message  = ConcatenateContactAdmin("Identity.Account.ResetPassword.Failure.Message");

            if (userId.HasValue && !string.IsNullOrEmpty(token))
            {
                var accountResult = await _accountManager.VerifyResetPasswordTokenAsync(userId.Value, token);

                if (accountResult.Success)
                {
                    metadata.Title = Localize("Identity.Account.ResetPassword.Title");

                    return(View(GetPageViewModel(metadata, accountResult.Data)));
                }
                else
                {
                    message = ConcatenateContactAdmin("Identity.Account.InvalidToken.Message");
                }
            }

            metadata.Title = Localize("General.Error");

            return(View("UserMessage", GetPageViewModel(metadata, message: message, displayMessage: false, messageType: MessageType.Error)));
        }
        // GET: /Account/Signin
        public ActionResult SignIn()
        {
            var metadata = new Models.PageMetadata
            {
                Title = Localize("Identity.Account.SignIn.Title")
            };

            return(View(GetPageViewModel(metadata, new SignInViewModel())));
        }
        /// <summary>
        /// Displays an invalid sign-in attempt message.
        /// </summary>
        /// <param name="uploadModel">Sign-in model taken from the user.</param>
        /// <returns>The user message.</returns>
        private ActionResult InvalidAttempt(PageViewModel <SignInViewModel> uploadModel)
        {
            var metadata = new Models.PageMetadata
            {
                Title = Localize("Identity.Account.SignIn.Title")
            };

            ModelState.AddModelError(string.Empty, Localize("Identity.Account.InvalidAttempt"));

            return(View(GetPageViewModel(metadata, uploadModel.Data)));
        }
        // GET: /Account/ForgotPassword
        public ActionResult ForgotPassword()
        {
            var metadata = new Models.PageMetadata
            {
                Title = Localize("Identity.Account.ResetPassword.Title")
            };

            var model = new ForgotPasswordViewModel();

            model.ResetPasswordController = "Account";
            model.ResetPasswordAction     = nameof(ResetPassword);

            return(View(GetPageViewModel(metadata, model)));
        }
        // GET: /Account/Register
        public ActionResult Register()
        {
            var model = new RegisterViewModel();

            model.PasswordConfirmationViewModel.ConfirmationAction = nameof(ConfirmUser);

            var metadata = new Models.PageMetadata
            {
                Title = Localize("Identity.Account.Register.Title")
            };

            var viewModel = GetPageViewModel(metadata, model);

            return(View(viewModel));
        }
        public async Task <ActionResult> Register(PageViewModel <RegisterViewModel> uploadModel)
        {
            if (ModelState.IsValid)
            {
                var emailConfirmedRegistration = IdentityOptions?.EmailConfirmedRegistration ?? default;
                var accountResult = await _accountManager.RegisterAsync(uploadModel.Data, emailConfirmedRegistration, Request);

                if (accountResult.ResultState == RegisterResultState.InvalidInput)
                {
                    AddIdentityErrors(accountResult);

                    return(InvalidInput(uploadModel));
                }

                string title       = ErrorTitle;
                var    message     = ConcatenateContactAdmin("Identity.Account.Register.Failure.Message");
                var    messageType = MessageType.Error;

                if (emailConfirmedRegistration)
                {
                    if (accountResult.ResultState == RegisterResultState.EmailSent)
                    {
                        title       = Localize("Identity.Account.Register.ConfirmedSuccess.Title");
                        message     = Localize("Identity.Account.Register.ConfirmedSuccess.Message");
                        messageType = MessageType.Info;
                    }
                }
                else if (accountResult.Success)
                {
                    title       = Localize("Identity.Account.Register.DirectSuccess.Title");
                    message     = Localize("Identity.Account.Register.DirectSuccess.Message");
                    messageType = MessageType.Info;
                }

                var metadata = new Models.PageMetadata
                {
                    Title = title
                };

                var messageViewModel = GetPageViewModel(metadata, message, false, false, messageType);

                return(View("UserMessage", messageViewModel));
            }

            return(InvalidInput(uploadModel));
        }
        public async Task <ActionResult> SignOut()
        {
            var metadata = new Models.PageMetadata
            {
                Title = Localize("General.Error")
            };

            var accountResult = await _accountManager.SignOutAsync();

            if (accountResult.Success)
            {
                return(RedirectToLocal(GetHomeUrl()));
            }

            var message = ConcatenateContactAdmin("Identity.Account.SignOut.Failure.Message");

            return(View("UserMessage", GetPageViewModel(metadata, message: message, messageType: MessageType.Error)));
        }
        public async Task <ActionResult> ForgotPassword(PageViewModel <ForgotPasswordViewModel> uploadModel)
        {
            var metadata = new Models.PageMetadata();

            if (ModelState.IsValid)
            {
                // All of the result states should be treated equal (to prevent enumeration attacks), hence discarding the result entirely.
                _ = await _accountManager.ForgotPasswordAsync(uploadModel.Data, Request);

                metadata.Title = Localize("Identity.Account.CheckEmailResetPassword.Title");
                var message = Localize("Identity.Account.CheckEmailResetPassword.Message");

                return(View("UserMessage", GetPageViewModel(metadata, message: message, displayMessage: false, messageType: MessageType.Info)));
            }

            metadata.Title = Localize("Identity.Account.ResetPassword.Title");

            return(View(GetPageViewModel(metadata, uploadModel.Data)));
        }
        protected ActionResult InvalidInput <TUploadViewModel>(
            PageViewModel <TUploadViewModel> uploadModel)
            where TUploadViewModel : class, new()
        {
            var metadata = new Models.PageMetadata
            {
                Title = Localize("General.InvalidInput.Title")
            };

            var viewModel = GetPageViewModel(
                metadata,
                uploadModel.Data,
                Localize("General.InvalidInput.Message"),
                true,
                false,
                MessageType.Error);

            return(View(viewModel));
        }