コード例 #1
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var userid = User.Identity.GetUserId();
                    var result = await m_userManager.ChangeUserPasswordAsync(userid, model.CurrentPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        ViewBag.SuccessfulMessage = "Đổi mật khẩu thành công";
                        return(View());
                    }
                    else
                    {
                        ViewBag.FailureMessage = "Mật khẩu không đúng";
                        return(View());
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMessage = ex.Message;
                    ViewBag.Exception    = ex.ToString();
                    return(View("Error"));
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }