当前位置: 首页>>代码示例>>C#>>正文


C# ChangePasswordViewModel类代码示例

本文整理汇总了C#中ChangePasswordViewModel的典型用法代码示例。如果您正苦于以下问题:C# ChangePasswordViewModel类的具体用法?C# ChangePasswordViewModel怎么用?C# ChangePasswordViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ChangePasswordViewModel类属于命名空间,在下文中一共展示了ChangePasswordViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChangePassword

        public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            var result = await this.UserManager
                .ChangePasswordAsync(
                User.Identity.GetUserId(), 
                model.OldPassword, 
                model.NewPassword);

            if (result.Succeeded)
            {
                var user = await this.UserManager.FindByIdAsync(User.Identity.GetUserId());
                if (user != null)
                {
                    await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                }

                return this.RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
            }

            this.AddErrors(result);
            return this.View(model);
        }
开发者ID:vassildinev,项目名称:ASP.NET-MVC,代码行数:27,代码来源:ManageController.cs

示例2: ChangePassword

        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (model == null) throw new ArgumentNullException("model");

            if (ModelState.IsValid)
            {
                bool changePasswordSucceeded;
                try
                {
                    changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword,
                                                                         model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    TempData["SuccessMessage"] = "Пароль успешно изменен";
                }
                else
                {
                    ModelState.AddModelError("", "Неправильный текущий пароль или недопустимый новый пароль.");
                }
            }
            return View(model);
        }
开发者ID:vitalzhuravkov,项目名称:FileUploader,代码行数:28,代码来源:AccountController.cs

示例3: ChangePassword

        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (this.ModelState.IsValid && this.authentication.ChangePassword(this.authentication.CurrentUserName, model.OldPassword, model.NewPassword))
            {
                return this.RedirectToAction("ChangePassword", new { saveSuccessful = true });
            }

            this.ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");

            return this.View(model);
        }
开发者ID:marijngiesen,项目名称:qoam,代码行数:11,代码来源:AccountController.cs

示例4: ChangePasswordAction_WithValidValuesReturnsRedirectToRoute

        public void ChangePasswordAction_WithValidValuesReturnsRedirectToRoute()
        {
            // Arrange
            var controller = CreateAccountController();
            var changePasswordView = new ChangePasswordViewModel { UserName = "TestUser", OldPassword = "password", NewPassword = "pa33word" };

            // Act
            var result = controller.ChangePassword(changePasswordView);

            // Assert
            Assert.IsInstanceOf<RedirectToRouteResult>(result, "RedirectToRouteResult not returned.");
        }
开发者ID:Emon0407,项目名称:WebConnection,代码行数:12,代码来源:AccountControllerTest.cs

示例5: ChangePasswordAction_ReturnsViewIfFails

        public void ChangePasswordAction_ReturnsViewIfFails()
        {
            // Arrange
            var controller = CreateAccountController();
            var changePasswordView = new ChangePasswordViewModel { UserName = "wrong", OldPassword = "wrong", NewPassword = "pa33word" };

            // Act
            var result = controller.ChangePassword(changePasswordView);
            var viewResult = (ViewResult)result;

            // Assert
            Assert.IsInstanceOf<ViewResult>(result, "ViewResult not returned.");
            Assert.AreSame(changePasswordView, viewResult.ViewData.Model, "User and Model are not the same");
            Assert.AreEqual(false, viewResult.ViewData.ModelState.IsValid);
        }
开发者ID:Emon0407,项目名称:WebConnection,代码行数:15,代码来源:AccountControllerTest.cs

示例6: ChangePasswordAction_WithValidValuesUpdatesPassword

        public void ChangePasswordAction_WithValidValuesUpdatesPassword()
        {
            // Arrange
            var controller = CreateAccountController();

            var user = new LoginViewModel { UserName = "TestUser", Password = "password" };
            var changePasswordView = new ChangePasswordViewModel { UserName = "TestUser", OldPassword = "password", NewPassword = "pa33word" };

            // Act
            var result = controller.ChangePassword(changePasswordView);

            // Assert
            //Assert.IsInstanceOf<RedirectToRouteResult>(result, "Redirect to route not returned.");
            //Assert.AreEqual("Customers", redirectresult.RouteValues["controller"]);
            //Assert.AreEqual("Index", redirectresult.RouteValues["action"]);
        }
开发者ID:Emon0407,项目名称:WebConnection,代码行数:16,代码来源:AccountControllerTest.cs

示例7: ChangePasswordAction_ReturnsViewIfInvalidModelState

        public void ChangePasswordAction_ReturnsViewIfInvalidModelState()
        {
            // Arrange
            var controller = CreateAccountController();
            var changePasswordView = new ChangePasswordViewModel { UserName = "TestUser", OldPassword = "password", NewPassword = "pa33word" };
            controller.ModelState.AddModelError("*", "Invalid model state.");

            // Act
            var result = controller.ChangePassword(changePasswordView);

            // Assert
            Assert.IsInstanceOf<ViewResult>(result, "ViewResult not returned.");

            var viewResult = (ViewResult)result;
            Assert.AreSame(changePasswordView, viewResult.ViewData.Model, "User and Model are not the same");
        }
开发者ID:Emon0407,项目名称:WebConnection,代码行数:16,代码来源:AccountControllerTest.cs

示例8: Password

        public async Task<IActionResult> Password(ChangePasswordViewModel viewModel)
        {
            if (!ModelState.IsValid)
                return RedirectToAction("Password");

            return await _userService.SetNewPasswordAsync(UserId, viewModel.ActualPassword, viewModel.NewPassword)
                .Execute(
                    onSuccess: () =>
                    {
                        Notify(FlashNotificationType.Success, "Password has been changed.");
                        return RedirectToAction("Index");
                    },
                    onFailure: ex =>
                    {
                        Notify(FlashNotificationType.Error, ex.Message);
                        return RedirectToAction("Password");
                    });
        }
开发者ID:thecorrado,项目名称:Warden,代码行数:18,代码来源:SettingsController.cs

示例9: ChangePassword

        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            model.UserName = User.Identity.Name;

            if (ModelState.IsValid)
            {
                if (MembershipService.ChangePassword(model.UserName, model.OldPassword, model.NewPassword))
                {
                    return RedirectToAction("ChangePasswordSuccess");
                }

                ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return View(model);
        }
开发者ID:Emon0407,项目名称:WebConnection,代码行数:18,代码来源:AccountController.cs

示例10: ChangePassword

        public JsonResult ChangePassword(ChangePasswordViewModel changePasswordView)
        {
            if (!ModelState.IsValid)
            {
                return Json(new { Success = false, Message = Resources.ValidationFailed });
            }

            var command = new ChangePasswordCommand(UserInfo.Id, changePasswordView.CurrentPassword, changePasswordView.NewPassword);
            var result = ExecuteCommand(command);

            if (result)
            {
                TempData[ViewDataKeys.Message] = new SuccessMessage(Resources.PasswordChangeSuccess);

                return Json(new { Success = true });
            }
            else
            {
                return Json(new { Success = false, Message = Resources.IncorrectCurrentPassword });
            }
        }
开发者ID:techsavy,项目名称:AtYourService,代码行数:21,代码来源:AccountsController.cs

示例11: ChangePassword

        public async Task<ActionResult> ChangePassword(ChangePasswordViewModel changePasswordViewModel)
        {
            if (!ModelState.IsValid)
                return View(changePasswordViewModel);

            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId<int>(), changePasswordViewModel.CurrentPassword, changePasswordViewModel.NewPassword);
            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId<int>());
                if (user != null)
                {
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    TempData["Message"] = ActionMessage.ChangePasswordSuccess;
                }
                return RedirectToAction("changepassword", "action");
            }
            AddErrors(result);

            return View(changePasswordViewModel);
        }
开发者ID:thieunq92,项目名称:orientalsails.v2013.mvc,代码行数:21,代码来源:ActionController.cs

示例12: ChangePassword

        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var request = new ChangePasswordRequest
                {
                    UserName = "???",
                    OldPassword = model.OldPassword,
                    NewPassword = model.NewPassword
                };

                var response = this.accountService.ChangePassword(request);
                if (response.Status == StatusCode.OK)
                {
                    this.TempData["SuccessMessage"] = "You have successfully changed your password.";
                    return this.RedirectToAction("Index");
                }
                else
                {
                    this.ViewBag.DisplaySummary = "yes";
                    this.ModelState.AddModelError(string.Empty, "Your old password has not been recognised. Please try again.");
                }
            }

            return this.View();
        }
开发者ID:porl88,项目名称:Website-MVC,代码行数:26,代码来源:AccountController.cs

示例13: ChangePassword

 public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     IdentityResult result = await _userManager.ChangePasswordAsync(User.Identity.GetUserId2<ObjectId>()
         , model.OldPassword, model.NewPassword);
     if (result.Succeeded)
     {
         var user = await _userManager.FindByIdAsync(User.Identity.GetUserId2<ObjectId>());
         if (user != null)
         {
             await SignInAsync(user, isPersistent: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
     }
     AddErrors(result);
     return View(model);
 }
开发者ID:RodionKulin,项目名称:ContentManagementBackend,代码行数:20,代码来源:ManageController.cs

示例14: ChangePassword

        public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            string strError = string.Empty;
            try
            {
                if (ModelState.IsValid)
                {
                    await ParseUser.RequestPasswordResetAsync(model.Email);
                    model.Message =  Strings.GetLocalizedString(Strings.ChangePasswordSuccessMessage);
                    model.IsSuccess = true;
                    model.CaptchaOK = true;
                }
                else
                {
                    model.CaptchaOK = false;
                }
            }
            catch (Exception ex)
            {
                strError = ex.ToString();
                model.IsSuccess = false;
            }

            if (!string.IsNullOrEmpty(strError))
            {
                await ParseLogger.Log("Change Password", strError);
                model.Message = MyMentorResources.validationChangePasswordError;
                return View(model);
            }
            return View(model);
        }
开发者ID:natan1957,项目名称:mymentor-portal,代码行数:31,代码来源:AccountController.cs

示例15: ChangePassword

        public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            var result = await this.UserManager.ChangePasswordAsync(this.User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
            if (result.Succeeded)
            {
                var user = await this.UserManager.FindByIdAsync(this.User.Identity.GetUserId());
                if (user != null)
                {
                    await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                }

                this.AddToastMessage("Congratulations", "Your password has been changed.", ToastType.Success);
                return this.RedirectToAction<HomeController>(c => c.Index());
            }

            this.AddErrors(result);
            return this.View(model);
        }
开发者ID:TomaNikolov,项目名称:EventSystem,代码行数:23,代码来源:ManageController.cs


注:本文中的ChangePasswordViewModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。