Exemplo n.º 1
0
 public IActionResult ModifyPassword(ModifyPasswordViewModel model)
 {
     if(!CheckRecaptcha(HttpContext.Request.Form["g-recaptcha-response"]))
     {
         ModelState.AddModelError("mail", "El Captcha no fue ingresado correctamente");
     }
     if (model.password != model.confirmPassword)
     {
         ModelState.AddModelError("password", "Las contraseñas no coinciden");
     }
     if (!ModelState.IsValid)
     {
         return View(new ModifyPasswordViewModel() { mail = model.mail });
     }
     try
     {
         api.ModifyPassword(model.mail, model.password);
     }
     catch (Exception e)
 {
         ModelState.AddModelError("password", e.Message);
         return View(new ModifyPasswordViewModel() { mail = model.mail });
     }
     return View("ModifiedCorrectly");
 }
Exemplo n.º 2
0
 public IActionResult RestorePassword(string token)
 {
     var mail = api.GetEmailByToken(Guid.Parse(token));
     if (mail == String.Empty)
     {
         RedirectToAction("Register");
     }
     var model = new ModifyPasswordViewModel()
     {
         mail = mail
     };
     return View(model);
 }
Exemplo n.º 3
0
        public async Task <IActionResult> ModifyPassword(ModifyPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.Password);

                if (result.Succeeded)
                {
                    return(Json(new { ErrNo = 0, ErrMsg = "密码修改成功~" }));
                }
            }
            return(Json(new { ErrNo = 1, ErrMsg = "密码修改失败,请重试~" }));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> ModifyPassword()
        {
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(RedirectToAction("Index", "Root"));
            }
            var model = new ModifyPasswordViewModel();

            model.Email       = user.Email;
            model.DisplayName = user.DisplayName;
            model.Signature   = user.Signature;
            model.Avatar      = user.Avatar;
            return(View(model));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> ModifyPassword(ModifyPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.Password);

                if (result.Succeeded)
                {
                    return(View("ModifyPasswordSuccess"));
                }
                ModelState.AddModelError(string.Empty, "密码修改失败,请重试~");
            }
            return(View(model));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> ModifyPassword(ModifyPasswordViewModel model)
        {
            ViewBag.ReturnUrl = Url.Action("ModifyPassword");
            if (ModelState.IsValid)
            {
                using (UserServiceClient client = new UserServiceClient())
                {
                    MethodReturnResult <User> result = await client.GetAsync(User.Identity.Name);

                    //获取到用户数据。
                    if (result.Code == 0)
                    {
                        //旧密码输入正确。
                        if (result.Data.Password == model.OldPassword)
                        {
                            //设置新密码。
                            result.Data.Password = model.NewPassword;
                            result.Data.Editor   = HttpContext.User.Identity.Name;
                            result.Data.EditTime = DateTime.Now;

                            MethodReturnResult rst = await client.ModifyAsync(result.Data);

                            //修改成功。
                            if (rst.Code == 0)
                            {
                                return(RedirectToAction("ModifyPassword", new { Message = ManageMessageId.ChangePasswordSuccess }));
                            }
                            else
                            {
                                AddErrors(rst);
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("C1000", StringResource.AccountController_OldPasswordError);
                        }
                    }
                    else
                    {//出现错误。
                        AddErrors(result);
                    }
                }
            }
            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> ModifyPassword(ModifyPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "验证未通过");
                return(View(model));
            }
            string result = await _AdminService.ModifyPassword(User, model.OldPwd, model.NewPwd);

            if (result == "ok")
            {
                Utility.WriteMessage("修改密码成功", "/admin/home/modifypassword");
                return(View());
            }
            ModelState.AddModelError(string.Empty, result);
            return(View(model));
        }
Exemplo n.º 8
0
 public IActionResult ModifyPassword(ModifyPasswordViewModel modifyInfo)
 {
     if (IsPost)
     {
         if (!ModelState.IsValid)
         {
             return(Json(Result.FailedResult("提交数据有错误")));
         }
         var modifyInfoDto = modifyInfo.MapTo <ModifyPasswordCmdDto>();
         modifyInfoDto.CheckOldPassword = true;
         modifyInfoDto.SysNo            = User.Id;
         var result = AjaxResult.CopyFromResult(userService.ModifyPassword(modifyInfoDto));
         result.SuccessClose = true;
         return(Json(result));
     }
     return(View("ModifyPassword"));
 }
Exemplo n.º 9
0
 public ActionResult AdminModifyPassword(ModifyPasswordViewModel modifyInfo)
 {
     if (IsPost)
     {
         ModelState.Remove("NowPassword");
         if (!ModelState.IsValid)
         {
             return(Json(Result.FailedResult("提交数据有错误")));
         }
         var modifyInfoDto = modifyInfo.MapTo <ModifyPasswordCmdDto>();
         modifyInfoDto.CheckOldPassword = false;
         var modifyResult = userService.ModifyPassword(modifyInfoDto);
         var result       = AjaxResult.CopyFromResult(modifyResult);
         result.SuccessClose = true;
         return(Json(result));
     }
     return(View(modifyInfo));
 }
        public ActionResult ModifyPassword(ModifyPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = User.GetUserId <Guid>();
                var user   = _bLLUser.Fetch(x => x.UserId == userId);
                if (user == null)
                {
                    return(Json(false));
                }
                try
                {
                    //判断原密码是否正确,原密码正确的情况才能修改密码
                    if (user.UserPassword.Equals(HashHelper.GetHashedString(HashType.SHA256, model.OldPassword)))
                    {
                        user.UserPassword = HashHelper.GetHashedString(HashType.SHA256, model.NewPassword);
                        if (_bLLUser.Update(user, u => u.UserPassword) > 0)
                        {
                            OperLogHelper.AddOperLog($"{UserName} 修改密码 {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}",
                                                     OperLogModule.Account, UserName);

                            Logger.Info($"{UserName} modify password at {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}");

                            //密码修改成功,需要重新登录
                            HttpContext.SignOutAsync().ConfigureAwait(false);
                            //
                            return(Json(true));
                        }
                    }
                    else
                    {
                        //原密码错误
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }
            return(Json(false));
        }
Exemplo n.º 11
0
        public ActionResult ModifyPassword(ModifyPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (CurrentUser == null)
                {
                    return(Json(false));
                }
                try
                {
                    //判断原密码是否正确,原密码正确的情况才能修改密码
                    if (CurrentUser.UserPassword.Equals(SecurityHelper.SHA256_Encrypt(model.OldPassword)))
                    {
                        CurrentUser.UserPassword = SecurityHelper.SHA256_Encrypt(model.NewPassword);
                        if (_bLLUser.Update(u => u.UserId == CurrentUser.UserId, u => u.UserPassword, CurrentUser.UserPassword) > 0)
                        {
                            OperLogHelper.AddOperLog($"{Username} 修改密码 {DateTime.Now:yyyy-MM-dd HH:mm:ss}",
                                                     OperLogModule.Account, Username);

                            Logger.Info($"{Username} modify password at {DateTime.Now:yyyy-MM-dd HH:mm:ss}");

                            //密码修改成功,需要重新登录
                            HttpContext.Session.Remove(AuthFormService.AuthCacheKey);
                            HttpContext.SignOutAsync().ConfigureAwait(false);
                            //
                            return(Json(true));
                        }
                    }
                    else
                    {
                        //原密码错误
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }
            return(Json(false));
        }
        public ActionResult ModifyPassword(ModifyPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (CurrentUser == null)
                {
                    return(Json(false));
                }
                try
                {
                    //判断原密码是否正确,原密码正确的情况才能修改密码
                    if (CurrentUser.UserPassword.Equals(SecurityHelper.SHA256_Encrypt(model.OldPassword)))
                    {
                        CurrentUser.UserPassword = SecurityHelper.SHA256_Encrypt(model.NewPassword);
                        if (BusinessHelper.UserHelper.Update(CurrentUser, "UserPassword") > 0)
                        {
                            OperLogHelper.AddOperLog($"{Username} 修改密码 {DateTime.Now:yyyy-MM-dd HH:mm:ss}",
                                                     OperLogModule.Account, Username);

                            Logger.Info($"{Username} modify password at {DateTime.Now:yyyy-MM-dd HH:mm:ss}");

                            //密码修改成功,需要重新登录
                            AuthFormService.Logout();
                            return(Json(true));
                        }
                    }
                    else
                    {
                        //原密码错误
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }
            return(Json(false));
        }
Exemplo n.º 13
0
        public IActionResult RestorePassword(ModifyPasswordViewModel model)
        {
            if (model.password != model.confirmPassword)
            {
                return(StatusCode(400, "Las contraseñas no coinciden"));
            }

            if (!ModelState.IsValid)
            {
                return(StatusCode(400));
            }

            try
            {
                api.ModifyPassword(model.mail, model.password);
            }

            catch (Exception e)
            {
                return(StatusCode(400, e.Message));
            }
            return(StatusCode(200, "Password modified correctly"));
        }
Exemplo n.º 14
0
 public ModifyPassword()
 {
     InitializeComponent();
     _ViewModel = new ModifyPasswordViewModel();
 }
Exemplo n.º 15
0
 public IActionResult ModifyPassword(ModifyPasswordViewModel mp)
 {
     if (ModelState.IsValid)
     {
         if (string.Equals(HttpContext.Session.Get <SessionData>(SessionUser).Role, "customer", StringComparison.OrdinalIgnoreCase))
         {
             Customer c = db.Customer.Where(i => i.CustomerId == HttpContext.Session.Get <SessionData>(SessionUser).Id).FirstOrDefault();
             if (mp.OldPassword == c.Password)
             {
                 c.Password = mp.NewPassword;
                 using (var tr = db.Database.BeginTransaction())
                 {
                     try
                     {
                         db.Customer.Update(c);
                         db.SaveChanges();
                         tr.Commit();
                     }
                     catch
                     {
                         tr.Rollback();
                         ModelState.AddModelError("", "Cannot modify your password.");
                         return(View(mp));
                     }
                 }
                 ViewBag.Success = "Your Password is successfuly Modified.";
                 return(View());
             }
             else
             {
                 ModelState.AddModelError("", "Sorry your password Does not match with record.");
                 return(View(mp));
             }
         }
         else if (string.Equals(HttpContext.Session.Get <SessionData>(SessionUser).Role, "chef", StringComparison.OrdinalIgnoreCase))
         {
             Customer c = db.Customer.Where(i => i.CustomerId == HttpContext.Session.Get <SessionData>(SessionUser).Id).FirstOrDefault();
             if (mp.OldPassword == c.Password)
             {
                 c.Password = mp.NewPassword;
                 using (var tr = db.Database.BeginTransaction())
                 {
                     try
                     {
                         db.Customer.Update(c);
                         db.SaveChanges();
                         tr.Commit();
                     }
                     catch
                     {
                         tr.Rollback();
                         ModelState.AddModelError("", "Cannot modify your password.");
                         return(View(mp));
                     }
                 }
                 ViewBag.Success = "Your Password is successfuly Modified.";
                 return(View());
             }
             else
             {
                 ModelState.AddModelError("", "Sorry your password Does not match with record.");
                 return(View(mp));
             }
         }
         else if (string.Equals(HttpContext.Session.Get <SessionData>(SessionUser).Role, "DBoy", StringComparison.OrdinalIgnoreCase))
         {
             Customer c = db.Customer.Where(i => i.CustomerId == HttpContext.Session.Get <SessionData>(SessionUser).Id).FirstOrDefault();
             if (mp.OldPassword == c.Password)
             {
                 if (mp.NewPassword == mp.ConfirmPassword)
                 {
                     c.Password = mp.NewPassword;
                     using (var tr = db.Database.BeginTransaction())
                     {
                         try
                         {
                             db.Customer.Update(c);
                             db.SaveChanges();
                             tr.Commit();
                         }
                         catch
                         {
                             tr.Rollback();
                             ModelState.AddModelError("", "Cannot modify your password.");
                             return(View(mp));
                         }
                     }
                     ViewBag.Success = "Your Password is successfuly Modified.";
                     return(View());
                 }
             }
             else
             {
                 ModelState.AddModelError("", "Sorry your password Does not match with record.");
                 return(View(mp));
             }
         }
     }
     return(View());
 }
        public async Task <IActionResult> Password([FromBody] ModifyPasswordViewModel model)
        {
            string userid = null;
            var    isCid  = model.Id.CheckIDCard(out var _);

            // 身份证转id
            if (isCid)
            {
                userid = _context.AppUsersDb.Where(u => u.BaseInfo.Cid == model.Id).FirstOrDefault()?.Id;
            }
            else
            {
                userid = model.Id;
            }
            // 目标用户权限判断
            var currentUser = currentUserService.CurrentUser;
            var targetUser  = _usersService.GetById(userid);
            var ua          = _userActionServices.Log(UserOperation.ModifyPsw, userid, $"通过{currentUser?.Id}");

            if (targetUser == null)
            {
                return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.UserMessage.NotExist)));
            }
            var  authUser           = currentUser;
            bool authUserPermission = false;

            if (model.Auth?.AuthByUserID != null)
            {
                authUser = _usersService.GetById(model.Auth.AuthByUserID);
                _userActionServices.Status(ua, false, $"授权自{model.Auth.AuthByUserID}");
                if (authUser == null)
                {
                    return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.UserMessage.NotExist)));
                }
                if (!model.Auth.Verify(_authService, currentUser?.Id))
                {
                    return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.Account.Auth.AuthCode.Invalid)));
                }
                // 允许本人修改本人密码,允许本级以上修改密码
                authUserPermission = authUser.Id == userid;
            }
            if (authUser == null)
            {
                return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.Account.Auth.Invalid.NotLogin)));
            }
            if (!authUserPermission)
            {
                authUserPermission = _userActionServices.Permission(authUser.Application.Permission, DictionaryAllPermission.User.Application, Operation.Update, authUser.Id, targetUser.CompanyInfo.CompanyCode, $"修改{targetUser.Id}密码");
            }
            if (!authUserPermission)
            {
                return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.Account.Auth.Invalid.Default)));
            }

            // 密码修改判断
            var appUser = _context.Users.Where(u => u.UserName == targetUser.Id).FirstOrDefault();

            model.ConfirmNewPassword = model.ConfirmNewPassword.FromCipperToString(model.Id, cipperServices);
            model.NewPassword        = model.NewPassword.FromCipperToString(model.Id, cipperServices);
            if (model.NewPassword == null || model.ConfirmNewPassword == null)
            {
                return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.Account.Login.AuthFormat)));
            }
            if (model.NewPassword.Length < 8)
            {
                return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.Account.Register.PasswordTooSimple)));
            }
            if (model.NewPassword != model.ConfirmNewPassword)
            {
                return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.Account.Register.ConfirmPasswordNotSame)));
            }
            model.OldPassword = model.OldPassword.FromCipperToString(model.Id, cipperServices);
            // 本人修改密码,则判断旧密码
            if (userid == authUser.Id)
            {
                var sign = await _signInManager.PasswordSignInAsync(appUser, model.OldPassword, false, false);

                if (!sign.Succeeded && !authUserPermission)
                {
                    return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.Account.Login.AuthAccountOrPsw)));
                }
                if (model.ConfirmNewPassword == model.OldPassword)
                {
                    return(new JsonResult(_userActionServices.LogNewActionInfo(ua, ActionStatusMessage.Account.Login.PasswordIsSame)));
                }
            }
            appUser.PasswordHash = new PasswordHasher <ApplicationUser>().HashPassword(appUser, model.ConfirmNewPassword);
            _context.Users.Update(appUser);
            targetUser.BaseInfo.PasswordModify = true;
            _context.AppUserBaseInfos.Update(targetUser.BaseInfo);
            await _context.SaveChangesAsync().ConfigureAwait(false);

            _userActionServices.Status(ua, true);
            return(new JsonResult(ActionStatusMessage.Success));
        }
 public ModifyPasswordPage()
 {
     InitializeComponent();
     BindingContext = new ModifyPasswordViewModel();
 }