public ActionResult EditPassword(Models.ChangePasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         var session = (Models.AdminViewModel)Session["Taikhoanadmin"];
         if (session != null)
         {
             if (session.MatKhau.Equals(model.ExPassword))
             {
                 var _admin = new QuanTriVien();
                 _admin.MaAdmin = session.MaAdmin;
                 _admin.MatKhau = model.Password.ToString();
                 new Models.ChangePasswordViewModel().EditPassword(_admin);
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError("", "Nhập sai mật khẩu");
             }
         }
         else
         {
             ModelState.AddModelError("", "Không tồn tại tài khoản này");
         }
     }
     return(View(model));
 }
        public async Task <ActionResult> ChangePassword([Bind(Prefix = "ChangePasswordViewModel")] Models.ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                TempData["ViewData"] = ViewData;
                return(RedirectToAction("Index"));
            }

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

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInAsync(user, isPersistent : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);

            if (!ModelState.IsValid)
            {
                TempData["ViewData"] = ViewData;
                return(RedirectToAction("Index"));
            }

            var message = ManageMessageId.ChangePasswordSuccess;

            return(RedirectToAction("Index", new { Message = message }));
        }
Exemple #3
0
 public ActionResult ChangePassword(int id, Models.ChangePasswordViewModel change)
 {
     if (ModelState.IsValid)
     {
         if (Convert.ToInt32(AuthenticationManager.User.FindFirst(ClaimTypes.Sid).Value) != id)
         {
             ModelState.AddModelError("", "非法篡改");
         }
         else
         {
             User _user = userService.Find(id);
             if (_user.Password != Encryption.Sha256(change.OriginalPassword))
             {
                 ModelState.AddModelError("", "原始密码错误");
             }
             else
             {
                 _user.Password = Encryption.Sha256(change.Password);
                 if (userService.Update(_user))
                 {
                     return(new Success());
                 }
             }
         }
     }
     return(View(change));
 }
        public ActionResult ChangePassword(Models.ChangePasswordViewModel model)
        {
            if (model.OldPassword.Trim() == "")
            {
                return(View(model));
            }

            var myAccount         = DB_GEN_Repo.GetUser(model.UserID);   // DB_GEN.GenProxyAccount.Find(model.UserID.Trim());
            var myProxyAccount    = hluser_Repo.GetUser(model.UserID);   // hluser.passwd.Find(model.UserID.Trim());
            var myMedProxyAccount = MedProxy_Repo.GetUser(model.UserID); // MedProxy.passwd.Find(model.UserID.Trim());

            if ((myAccount == null) || (myProxyAccount == null) || (myMedProxyAccount == null))
            {
                return(View("AccountNotFound"));
            }

            string OldPasswordMD5 = DB_GEN_Repo.GetMD5(model.OldPassword); // DB_GEN.GetMD5(model.OldPassword).First().ToUpper();

            if (myAccount.chXData != OldPasswordMD5)
            {
                return(View("PasswordIncorrect"));
            }

            if (model.NewPassword != model.NewPasswordConfirm)
            {
                return(View("PasswordInconfirm"));
            }

            string NewPasswordMD5 = DB_GEN_Repo.GetMD5(model.NewPassword); //DB_GEN.GetMD5(model.NewPassword).First().ToUpper();

            myAccount.chXData        = NewPasswordMD5;
            myAccount.dtLastModified = DateTime.Now;
            myAccount.chXDataHosp    = "Web";
            DB_GEN_Repo.UnitOfWork.Commit(); //DB_GEN.SaveChanges();

            myProxyAccount.password = NewPasswordMD5.ToLower();
            myProxyAccount.comment  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "; Update by web";
            hluser_Repo.UnitOfWork.Commit(); //hluser.SaveChanges();

            myMedProxyAccount.password = NewPasswordMD5.ToLower();
            myMedProxyAccount.comment  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "; Update by web";
            MedProxy_Repo.UnitOfWork.Commit(); // MedProxy.SaveChanges();

            return(View("PasswordChanged"));
        }
Exemple #5
0
 public async Task <ActionResult> ChangePassword(Models.ChangePasswordViewModel model)
 {
     //if (!ModelState.IsValid)
     //{
     //    return View(model);
     //}
     //var result = UserManager.ChangePassword(User.Identity.GetUserId().AsLong(), model.OldPassword, model.NewPassword);
     //if (result.Succeeded)
     //{
     //    var user = await UserManager.FindById(User.Identity.GetUserId());
     //    if (user != null)
     //    {
     //        await SignInAsync(user, isPersistent: false);
     //    }
     //    return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
     //}
     //AddErrors(result);
     return(View(model));
 }
        public IActionResult ChangePassword(Models.ChangePasswordViewModel v)
        {
            var cJ03 = Factory.j03UserBL.Load(Factory.CurrentUser.pid);
            var lu   = new BO.LoggingUser();
            var ret  = lu.ValidateChangePassword(v.NewPassword, v.CurrentPassword, v.VerifyPassword, cJ03);

            if (ret.Flag == BO.ResultEnum.Success)
            {
                cJ03.j03PasswordHash         = lu.Pwd2Hash(v.NewPassword, cJ03);
                cJ03.j03IsMustChangePassword = false;
                if (Factory.j03UserBL.Save(cJ03) > 0)
                {
                    Factory.CurrentUser.AddMessage("Heslo bylo změněno.", "info");
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                Factory.CurrentUser.AddMessage(ret.Message);
            }
            return(View(v));
        }
Exemple #7
0
        public async Task <ActionResult> ChangePassword(Models.ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new
                {
                    success = false,
                    message = "Change password fail"
                }));
                //            AddErrors(result);
                //return View(model);
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(Json(new
                {
                    success = true,
                    message = "Your password has been changed"
                }));
                //return RedirectToAction("ChangePassword", new { Message = "Change Password Success" });
            }
            return(Json(new
            {
                success = false,
                message = "Change password fail"
            }));
            //            AddErrors(result);
            //            return View(model);
        }