本文整理汇总了C#中ChangePasswordModel类的典型用法代码示例。如果您正苦于以下问题:C# ChangePasswordModel类的具体用法?C# ChangePasswordModel怎么用?C# ChangePasswordModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChangePasswordModel类属于命名空间,在下文中一共展示了ChangePasswordModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangePassword
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (!ModelState.IsValid)
return View(model);
servicoAutorizacao.AlterarSenha(User.Identity.Name, model.OldPassword, model.NewPassword);
return RedirectToAction("ChangePasswordSuccess");
}
示例2: ChangePassword
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
// ChangePassword iniciará una excepción en lugar de
// devolver false en determinados escenarios de error.
bool changePasswordSucceeded;
try
{
MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
changePasswordSucceeded = currentUser.ChangePassword(EncodePassword(model.OldPassword), EncodePassword(model.NewPassword));
}
catch (Exception)
{
changePasswordSucceeded = false;
}
if (changePasswordSucceeded)
{
return RedirectToAction("ChangePasswordSuccess");
}
else
{
ModelState.AddModelError("", "La contraseña actual es incorrecta o la nueva contraseña no es válida.");
}
}
// Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
return View(model);
}
示例3: ChangePassword
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
var status = _userService.ChangePassword(UserProfile.Current, model.OldPassword, model.NewPassword);
switch (status)
{
case ChangePasswordStatus.Success:
TempData.AddSuccessMessage(status.GetDescription());
return RedirectToAction("Index", "Home");
case ChangePasswordStatus.InvalidPassword:
ModelState.AddModelError(string.Empty, status.GetDescription());
break;
case ChangePasswordStatus.Failure:
ModelState.AddModelError(string.Empty, status.GetDescription());
break;
}
}
ViewBag.PasswordLength = _membershipSetings.MinimumPasswordLength;
return View(model);
}
示例4: ChangePassword
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid) {
// ChangePassword는 특정 실패 시나리오에서 false를 반환하지 않고
// 예외를 throw합니다.
bool changePasswordSucceeded;
try {
MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
}
catch (Exception) {
changePasswordSucceeded = false;
}
if (changePasswordSucceeded) {
return RedirectToAction("ChangePasswordSuccess");
}
else {
ModelState.AddModelError("", "현재 암호가 정확하지 않거나 새 암호가 잘못되었습니다.");
}
}
// 이 경우 오류가 발생한 것이므로 폼을 다시 표시하십시오.
return View(model);
}
示例5: ChangePassword
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
// ChangePassword will throw an exception rather
// than return false in certain failure scenarios.
bool changePasswordSucceeded;
try
{
MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
}
catch (Exception)
{
changePasswordSucceeded = false;
}
if (changePasswordSucceeded)
{
return RedirectToAction("ChangePasswordSuccess");
}
else
{
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例6: ChangePassword
public ActionResult ChangePassword()
{
var model = new ChangePasswordModel();
model.Username = User.Identity.Name;
var user = context.Accounts.FirstOrDefault(x => x.Username.Contains(model.Username));
model.Email = user.Email;
return View(model);
}
示例7: TestChangePassword
public void TestChangePassword()
{
string testUserName = "TestUserName";
string testOldPassword = "TestOldPassword";
string testNewPassword = "TestNewPassword";
var changePasswordModel = new ChangePasswordModel
{
OldPassword = testOldPassword,
NewPassword = testNewPassword
};
var accountController = new AccountController();
//Stub HttpContext
var stubHttpContext = new StubHttpContextBase();
//Setup ControllerContext so AccountController will use our stubHttpContext
accountController.ControllerContext = new ControllerContext(stubHttpContext,
new RouteData(), accountController);
//Stub IPrincipal
var principal = new StubIPrincipal();
principal.IdentityGet = () =>
{
var identity = new StubIIdentity { NameGet = () => testUserName };
return identity;
};
stubHttpContext.UserGet = () => principal;
RedirectToRouteResult redirectToRouteResult;
//Scope the detours we're creating
using (ShimsContext.Create())
{
ShimMembership.GetUserStringBoolean = (identityName, userIsOnline) =>
{
Assert.AreEqual(testUserName, identityName);
Assert.AreEqual(true, userIsOnline);
var memberShipUser = new ShimMembershipUser();
//Sets up a detour for MemberShipUser.ChangePassword to our mocked implementation
memberShipUser.ChangePasswordStringString = (oldPassword, newPassword) =>
{
Assert.AreEqual(testOldPassword, oldPassword);
Assert.AreEqual(testNewPassword, newPassword);
return true;
};
return memberShipUser;
};
var actionResult = accountController.ChangePassword(changePasswordModel);
Assert.IsInstanceOf(typeof(RedirectToRouteResult), actionResult);
redirectToRouteResult = actionResult as RedirectToRouteResult;
}
Assert.NotNull(redirectToRouteResult);
Assert.AreEqual("ChangePasswordSuccess", redirectToRouteResult.RouteValues["Action"]);
}
示例8: ChangePassword
public HttpResponseMessage ChangePassword(ChangePasswordModel model)
{
model.UserID = User.UserID;
ActionOutput output = _userManager.ChangePassword(model);
return Request.CreateResponse<ApiActionOutput>(new ApiActionOutput
{
Status = output.Status,
Message = output.Message
});
}
示例9: ChangePassword
public void ChangePassword(ChangePasswordModel changePasswordModel)
{
var db = GetDbContext();
var user = GetCurrentUser();
user.Password = EncryptPassword(changePasswordModel.NewPassword);
db.SubmitChanges();
SendEmail("[email protected]", user.Email, "Iudico Notification", "Your passord has been changed.");
}
示例10: ChangePassword
public ActionResult ChangePassword(int id)
{
User user = userService.GetUserById(id);
ChangePasswordModel model = new ChangePasswordModel()
{
User = user
};
return this.View("ChangePassword", model);
}
示例11: ChangePassword
public ActionResult ChangePassword(string key)
{
var model = new ChangePasswordModel(key);
if (model.Key != null)
{
return View(model);
}
return RedirectToAction("Login", new { returnUrl = "/" });
}
示例12: ChangePassword
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
bool changePasswordSucceeded = true;
try
{
if (ModelState.IsValid && model.OldPassword != null)
{
int id = ((Session)Session["Session"]).UserID;
User oldUser = db.Users.Single(u => u.UserID == id);
string source = model.OldPassword;
using (MD5 md5Hash = MD5.Create())
{
Encryptor enc = new Encryptor();
string hash = enc.GetMd5Hash(md5Hash, source);
if (enc.VerifyMd5Hash(md5Hash, source, hash))
{
if (hash == oldUser.Password)
{
source = model.NewPassword;
hash = enc.GetMd5Hash(md5Hash, source);
if (enc.VerifyMd5Hash(md5Hash, source, hash))
{
oldUser.Password = hash;
db.Users.Attach(oldUser);
db.ObjectStateManager.ChangeObjectState(oldUser, EntityState.Modified);
db.SaveChanges();
changePasswordSucceeded = true;
}
}
}
}
}
}
catch (Exception)
{
changePasswordSucceeded = false;
}
if (changePasswordSucceeded)
{
return RedirectToAction("ChangePasswordSuccess");
}
else
{
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例13: ShouldNotValidateModelWhenGetActionResult
public void ShouldNotValidateModelWhenGetActionResult()
{
// arrange
var invalidModel = new ChangePasswordModel { };
var controllerAction = new AccountController().Action(c => c.ChangePassword(invalidModel));
var context = controllerAction.GetExecutionContext();
// act
controllerAction.GetActionResult(context);
//assert
context.ModelState.IsValid.Should().BeTrue();
}
示例14: ChangePassword
public ActionResult ChangePassword(string Email)
{
var user = userRepository.GetUserProfile(Email);
ChangePasswordModel dv = null;
if (user != null)
{
dv = new ChangePasswordModel();
dv.Id = user.Id;
dv.OldPassword = user.Password;
}
return GetView(WebConstants.View_ChangePassword, dv);
//return GetView(WebConstants.View_ChangePasswordPartial, dv);
}
示例15: ChangePassword
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid) {
if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword)) {
return RedirectToAction("ChangePasswordSuccess");
} else {
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}