本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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.");
}
示例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);
}
示例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"]);
}
示例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");
}
示例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");
});
}
示例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);
}
示例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 });
}
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}