/// <summary> /// 保存修改后密码信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <OperateStatus> SaveChangePassword(SystemUserChangePasswordInput input) { var operateStatus = new OperateStatus(); //后台再次验证是否一致 if (!input.NewPassword.Equals(input.ConfirmNewPassword)) { operateStatus.Message = "录入的新密码和确认密码不一致。"; return(operateStatus); } //旧密码是否正确 operateStatus = await CheckOldPassword(new CheckSameValueInput { Id = input.Id, Param = input.OldPassword }); if (operateStatus.ResultSign == ResultSign.Error) { return(operateStatus); } //将传入的密码加密 var encryptPwd = DEncryptUtil.Encrypt(input.NewPassword, _configOptions.Value.PasswordKey); if (await _userInfoRepository.ResetPassword(new SystemUserResetPasswordInput { EncryptPassword = encryptPwd, Id = input.Id })) { operateStatus.ResultSign = ResultSign.Successful; operateStatus.Message = string.Format(ResourceSystem.重置密码成功, input.NewPassword); } return(operateStatus); }
/// <summary> /// 保存系统配置项信息 /// </summary> /// <param name="doubleWays">系统配置项信息</param> /// <returns></returns> public async Task <OperateStatus> SaveConfig(IEnumerable <SystemConfigDoubleWay> doubleWays) { OperateStatus operateStatus = new OperateStatus(); //更新 try { foreach (var config in doubleWays) { config.V = DEncryptUtil.HttpUtilityUrlEncode(config.V); //更新对应值 var c = await GetByIdAsync(config.C); c.Value = config.V; if (await _configRepository.UpdateAsync(c) > 0) { GlobalParams.Set(c.Code, config.V); } } operateStatus.Message = Chs.Successful; operateStatus.ResultSign = ResultSign.Successful; } catch (Exception e) { LogWriter.WriteLog(FolderName.Exception, e); } return(operateStatus); }
/// <summary> /// 当重写验证返回为false时进入该重写方法 /// </summary> /// <param name="filterContext"></param> protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { base.HandleUnauthorizedRequest(filterContext); //验证不通过,直接跳转到相应页面,注意:如果不使用以下跳转,则会继续执行Action方法 if (filterContext.HttpContext.Request.Url != null) { filterContext.Result = new RedirectResult("/Error/Transfer?t=" + DEncryptUtil.Base64Encrypt("/Error/ReturnToLogin")); } }
/// <summary> /// 验证旧密码是否输入正确 /// </summary> /// <param name="input">需要验证的参数</param> /// <returns></returns> public async Task <OperateStatus> CheckOldPassword(CheckSameValueInput input) { var operateStatus = new OperateStatus(); input.Param = DEncryptUtil.Encrypt(input.Param, _configOptions.Value.PasswordKey); if (!await _userInfoRepository.CheckOldPassword(input)) { operateStatus.ResultSign = ResultSign.Error; operateStatus.Message = "旧密码不正确"; } else { operateStatus.ResultSign = ResultSign.Successful; } return(operateStatus); }
/// <summary> /// 验证旧密码是否输入正确 /// </summary> /// <param name="input">需要验证的参数</param> /// <returns></returns> public async Task <OperateStatus> CheckOldPassword(CheckSameValueInput input) { var operateStatus = new OperateStatus(); input.Param = DEncryptUtil.Encrypt(input.Param, GlobalParams.Get("pwdKey").ToString()); if (!await _userInfoRepository.CheckOldPassword(input)) { operateStatus.ResultSign = ResultSign.Error; operateStatus.Message = string.Format("旧密码不正确"); } else { operateStatus.ResultSign = ResultSign.Successful; } return(operateStatus); }
/// <summary> /// 根据用户Id重置某人密码 /// </summary> /// <param name="input">用户Id</param> /// <returns></returns> public async Task <OperateStatus> ResetPassword(SystemUserResetPasswordInput input) { var operateStatus = new OperateStatus(); //将传入的密码加密 var encryptPwd = DEncryptUtil.Encrypt(input.EncryptPassword, _configOptions.Value.PasswordKey); if (await _userInfoRepository.ResetPassword(new SystemUserResetPasswordInput { EncryptPassword = encryptPwd, Id = input.Id })) { operateStatus.ResultSign = ResultSign.Successful; operateStatus.Message = string.Format(ResourceSystem.重置密码成功, input.EncryptPassword); } return(operateStatus); }
/// <summary> /// 根据用户Id重置某人密码 /// </summary> /// <param name="input">用户Id</param> /// <returns></returns> public async Task <OperateStatus> ResetPassword(IdInput input) { var operateStatus = new OperateStatus(); //获取系统默认配置重置密码 var password = GlobalParams.Get("resetPassword").ToString(); //加密密码 //将传入的密码加密 var encryptPwd = DEncryptUtil.Encrypt(password, GlobalParams.Get("pwdKey").ToString()); if (await _userInfoRepository.ResetPassword(new ResetPasswordInput { EncryptPassword = encryptPwd, Id = input.Id })) { operateStatus.ResultSign = ResultSign.Successful; operateStatus.Message = string.Format(ResourceSystem.重置密码成功, password); } return(operateStatus); }
/// <summary> /// 根据登录代码和密码查询用户信息 /// </summary> /// <param name="input">登录名、密码等</param> /// <returns></returns> public async Task <OperateStatus <SystemUserLoginOutput> > CheckUserByCodeAndPwd(SystemUserLoginInput input) { var operateStatus = new OperateStatus <SystemUserLoginOutput>(); //将传入的密码加密 var encryptPwd = DEncryptUtil.Encrypt(input.Pwd, _configOptions.Value.PasswordKey); //查询信息 input.Pwd = encryptPwd; var data = await _userInfoRepository.CheckUserByCodeAndPwd(input); //是否存在 if (data == null) { operateStatus.ResultSign = ResultSign.Error; operateStatus.Message = ResourceSystem.用户名或密码错误; return(operateStatus); } //是否冻结 if (data.IsFreeze) { operateStatus.ResultSign = ResultSign.Error; operateStatus.Message = ResourceSystem.登录用户已冻结; return(operateStatus); } //成功 operateStatus.ResultSign = ResultSign.Successful; operateStatus.Message = "/"; if (data.FirstVisitTime == null) { //更新用户最后一次登录时间 _userInfoRepository.UpdateFirstVisitTime(new IdInput(data.UserId)); } //更新用户最后一次登录时间 _userInfoRepository.UpdateLastLoginTime(new IdInput(data.UserId)); data.LoginId = CombUtil.NewComb(); operateStatus.Data = data; return(operateStatus); }
/// <summary> /// 根据登录代码和密码查询用户信息 /// </summary> /// <param name="input">登录名、密码等</param> /// <returns></returns> public async Task <OperateStatus <SystemUserOutput> > CheckUserByCodeAndPwd(UserLoginInput input) { var operateStatus = new OperateStatus <SystemUserOutput>(); //将传入的密码加密 var encryptPwd = DEncryptUtil.Encrypt(input.Pwd, GlobalParams.Get("pwdKey").ToString()); //查询信息 input.Pwd = encryptPwd; var data = await _userInfoRepository.CheckUserByCodeAndPwd(input); //是否存在 if (data == null) { operateStatus.ResultSign = ResultSign.Error; operateStatus.Message = ResourceSystem.用户名或密码错误; return(operateStatus); } //是否冻结 if (data.IsFreeze) { operateStatus.ResultSign = ResultSign.Error; operateStatus.Message = ResourceSystem.登录用户已冻结; return(operateStatus); } //成功 operateStatus.ResultSign = ResultSign.Successful; operateStatus.Message = "/"; operateStatus.Data = data; if (data.FirstVisitTime == null) { //更新用户最后一次登录时间 _userInfoRepository.UpdateFirstVisitTime(new IdInput(data.UserId)); } //更新用户最后一次登录时间 _userInfoRepository.UpdateLastLoginTime(new IdInput(data.UserId)); return(operateStatus); }
/// <summary> /// 保存人员信息 /// </summary> /// <param name="input">人员信息</param> /// <returns></returns> public async Task <OperateStatus> SaveUser(SystemUserSaveInput input) { OperateStatus operateStatus; if (input.UserId.IsEmptyGuid()) { //新增 input.CreateTime = DateTime.Now; input.UserId = Guid.NewGuid(); if (!input.Code.IsNullOrEmpty()) { input.Password = DEncryptUtil.Encrypt("123456", _configOptions.Value.PasswordKey); } SystemUserInfo userInfoMap = input.MapTo <SystemUserInfo>(); operateStatus = await InsertAsync(userInfoMap); if (operateStatus.ResultSign == ResultSign.Successful) { //添加用户到组织机构 operateStatus = await _permissionUserLogic.SavePermissionUser(EnumPrivilegeMaster.组织机构, input.OrganizationId, new List <Guid> { input.UserId }); if (operateStatus.ResultSign == ResultSign.Successful) { return(operateStatus); } } else { return(operateStatus); } } else { //删除对应组织机构 operateStatus = await _permissionUserLogic.DeletePrivilegeMasterUser(input.UserId, EnumPrivilegeMaster.组织机构); if (operateStatus.ResultSign == ResultSign.Successful) { //添加用户到组织机构 operateStatus = await _permissionUserLogic.SavePermissionUser(EnumPrivilegeMaster.组织机构, input.OrganizationId, new List <Guid> { input.UserId }); if (operateStatus.ResultSign == ResultSign.Successful) { var userInfo = await GetByIdAsync(input.UserId); input.CreateTime = userInfo.CreateTime; input.Password = userInfo.Password; input.UpdateTime = DateTime.Now; input.UpdateUserId = userInfo.CreateUserId; input.UpdateUserName = input.CreateUserName; SystemUserInfo userInfoMap = input.MapTo <SystemUserInfo>(); return(await UpdateAsync(userInfoMap)); } } } return(operateStatus); }
/// <summary> /// 添加跳转界面 /// </summary> /// <param name="t"></param> /// <returns></returns> public ActionResult Transfer(string t) { t = DEncryptUtil.Base64Decrypt(t); ViewBag.Url = t; return(View("Transfer")); }
/// <summary> /// 保存人员信息 /// </summary> /// <param name="user">人员信息</param> /// <param name="orgId">业务表Id:如组织机构Id</param> /// <returns></returns> public async Task <OperateStatus> SaveUser(SystemUserInfo user, Guid orgId) { OperateStatus operateStatus; if (user.UserId.IsEmptyGuid()) { //新增 user.CreateTime = DateTime.Now; user.UserId = Guid.NewGuid(); user.Password = DEncryptUtil.Encrypt(GlobalParams.Get("defaultPwd").ToString(), GlobalParams.Get("pwdKey").ToString()); operateStatus = await InsertAsync(user); if (operateStatus.ResultSign == ResultSign.Successful) { //添加用户到组织机构 operateStatus = await _permissionUserLogic.SavePermissionUser(EnumPrivilegeMaster.组织机构, orgId, new List <Guid> { user.UserId }); if (operateStatus.ResultSign == ResultSign.Successful) { return(operateStatus); } } else { return(operateStatus); } } else { //删除对应组织机构 operateStatus = await _permissionUserLogic.DeletePrivilegeMasterUser(user.UserId, EnumPrivilegeMaster.组织机构); if (operateStatus.ResultSign == ResultSign.Successful) { //添加用户到组织机构 operateStatus = await _permissionUserLogic.SavePermissionUser(EnumPrivilegeMaster.组织机构, orgId, new List <Guid> { user.UserId }); if (operateStatus.ResultSign == ResultSign.Successful) { var userInfo = await GetByIdAsync(user.UserId); user.CreateTime = userInfo.CreateTime; user.Password = userInfo.Password; user.UpdateTime = DateTime.Now; user.UpdateUserId = userInfo.CreateUserId; user.UpdateUserName = user.CreateUserName; return(await UpdateAsync(user)); } } } return(operateStatus); }