Esempio n. 1
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            ActionResult action;
            var          flag = HasPassword();

            ViewBag.HasLocalPassword = flag;
            ViewBag.ReturnUrl        = Url.Action("Index", "Home");

            if (!flag)
            {
                var item = ModelState["OldPassword"];
                item?.Errors.Clear();

                if (ModelState.IsValid)
                {
                    var identityResult = await UserManager.AddPasswordAsync(GetGuid(User.Identity.GetUserId()), model.NewPassword);

                    var identityResult1 = identityResult;
                    if (!identityResult1.Succeeded)
                    {
                        AddErrors(identityResult1);
                    }
                    else
                    {
                        action = RedirectToAction("PostManagement", "Account", new { area = "" });
                        return(action);
                    }
                }
            }
            else if (ModelState.IsValid)
            {
                var identityResult2 = await UserManager.ChangePasswordAsync(GetGuid(User.Identity.GetUserId()), model.OldPassword, model.NewPassword);

                if (!identityResult2.Succeeded)
                {
                    ViewBag.Error = "Mật khẩu cũ không chính xác.";
                }
                else
                {
                    action = RedirectToAction("PostManagement", "Account", new { area = "" });
                    return(action);
                }
            }

            action = View();

            return(action);
        }
Esempio n. 2
0
        public async Task <ActionResult> Manage(ChangePasswordViewModel model)
        {
            var hasPassword = HasPassword();

            ViewBag.HasLocalPassword = hasPassword;
            ViewBag.ReturnUrl        = Url.Action("Manage");

            if (hasPassword)
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

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

                if (result.Succeeded)
                {
                    return(RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }));
                }

                AddErrors(result);
            }
            else
            {
                var state = ModelState["OldPassword"];
                state?.Errors.Clear();

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var result = await UserManager.AddPasswordAsync(GetGuid(User.Identity.GetUserId()), model.NewPassword);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess }));
                }

                AddErrors(result);
            }

            return(View(model));
        }
Esempio n. 3
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            var hasPassword = HasPassword();

            ViewBag.HasLocalPassword = hasPassword;
            ViewBag.ReturnUrl        = Url.Action("Index", "Home");

            if (!hasPassword)
            {
                var item = ModelState["OldPassword"];
                item?.Errors.Clear();

                if (ModelState.IsValid)
                {
                    var addPw = await UserManager.AddPasswordAsync(GetGuid(User.Identity.GetUserId()), model.NewPassword);

                    if (!addPw.Succeeded)
                    {
                        AddErrors(addPw);
                    }
                    else
                    {
                        return(RedirectToAction("Orders", "User", new { area = "" }));
                    }
                }
            }
            else if (ModelState.IsValid)
            {
                var changePw = await UserManager.ChangePasswordAsync(GetGuid(User.Identity.GetUserId()), model.OldPassword, model.NewPassword);

                if (!changePw.Succeeded)
                {
                    ViewBag.Error = "Mật khẩu cũ không chính xác.";
                }
                else
                {
                    return(RedirectToAction("Orders", "User", new { area = "" }));
                }
            }

            return(View());
        }