Ejemplo n.º 1
0
        /// <summary>
        /// 保存修改后密码信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <OperateStatus> SaveChangePassword(ChangePasswordInput input)
        {
            var operateStatus = new OperateStatus();

            //后台再次验证是否一致
            if (!input.NewPassword.Equals(input.ConfirmNewPassword))
            {
                operateStatus.Message = string.Format(Chs.Error, "录入的新密码和确认密码不一致。");
                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, GlobalParams.Get("pwdKey").ToString());

            if (await _userInfoRepository.ResetPassword(new ResetPasswordInput
            {
                EncryptPassword = encryptPwd,
                Id = input.Id
            }))
            {
                operateStatus.ResultSign = ResultSign.Successful;
                operateStatus.Message    = string.Format(ResourceSystem.重置密码成功, input.NewPassword);
            }
            return(operateStatus);
        }
Ejemplo n.º 2
0
        public JsonResult GetLogZTree()
        {
            var tree = new List <TreeEntity>();
            var path = GlobalParams.Get("logPath").ToString();

            GetFiles(path, ref tree);
            return(Json(tree.OrderByDescending(o => o.name).ToList()));
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     赋值Cookie并加密
 /// </summary>
 /// <param name="userName">用户名</param>
 /// <param name="user">用户信息</param>
 /// <param name="rememberMe">记住我</param>
 public static void SetAuthCookie(string userName, PrincipalUser user, bool rememberMe)
 {
     //如果为记住我
     //if (rememberMe)
     //配置文件中读取记住我时间
     _cookieSaveDays = Convert.ToDouble(GlobalParams.Get("rememberMeDay").ToString());
     //赋值Cookie信息
     SetAuthCookie(userName, user, rememberMe, _cookieSaveDays);
 }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
 /// <summary>
 ///     从数据库中读取配置信息
 /// </summary>
 private static void LoadConfig()
 {
     //如果没有加载则进行加载
     if (!hasLoad)
     {
         lock (obj)
         {
             if (!hasLoad)
             {
                 //读取log4net配置文件信息
                 var configStr = (string)GlobalParams.Get("log4net");
                 //序列化xml
                 var xml = new XmlDocument();
                 xml.LoadXml(configStr);
                 XmlConfigurator.Configure(xml.DocumentElement);
                 hasLoad = true;
             }
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 重写基类
        /// </summary>
        public override void WriteLog()
        {
            //写入数据库
            base.WriteLog();
            string exceptionHtml = ExceptionHtml(log);

            //是否发送邮件
            if (bool.Parse(GlobalParams.Get("errorSendMail").ToString()))
            {
                string    fromAccount = GlobalParams.Get("errorSendMailFromAccount").ToString();
                string    fromPwd     = GlobalParams.Get("errorSendMailFromPwd").ToString();
                string    toAccount   = GlobalParams.Get("errorSendMailToAccount").ToString();
                string    toSmtp      = GlobalParams.Get("errorSendMailSmtp").ToString();
                bool      toSmtpSsl   = bool.Parse(GlobalParams.Get("errorSendMailSmtpSsl").ToString());
                EmailUtil email       = new EmailUtil(toAccount, fromAccount, "错误接受者", "系统错误提醒", "系统发生错误", exceptionHtml, true);
                email.SetSmtp(fromPwd, toSmtp, toSmtpSsl);
            }
            //写入文本
            LogWriter.WriteLog(FolderName.Exception, exceptionHtml);
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 执行方法前进入该重置方法
        ///     1、一个帐号只能在一个地方登录
        ///     2、权限验证
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //获取当前登录人员信息
            PrincipalUser currentUser = FormAuthenticationExtension.Current(HttpContext.Current.Request);

            #region 是否具有忽略验证特性
            //是否具有忽略特性:若有忽略特性则不进行其他的验证
            if (filterContext.ActionDescriptor.IsDefined(typeof(IgnoreAttribute), false))
            {
                return;
            }
            #endregion

            #region 一个帐号只能在一个浏览器登录
            if (GlobalParams.Get("loginOnce").ToString() == "是")
            {
                //如果当前登录人员信息不为空
                if (currentUser != null)
                {
                    //检查对应登录状态缓存是否为空
                    if (HttpRuntime.Cache[currentUser.Code] != null)
                    {
                        if (filterContext.HttpContext.Session != null &&
                            HttpRuntime.Cache[currentUser.Code].ToString() !=
                            filterContext.HttpContext.Session.SessionID)
                        {
                            //清空Session
                            filterContext.HttpContext.Session.Remove(currentUser.Code);
                            //清空Cookie
                            FormAuthenticationExtension.SignOut();
                            //跳转强制下线界面
                            ErrorRedirect(filterContext, "/Error/HaveLogin");
                        }
                    }
                    //否则重新赋值Cache
                    else
                    {
                        if (filterContext.HttpContext.Session != null)
                        {
                            filterContext.HttpContext.Session[currentUser.Code] = currentUser.UserId;
                            HttpRuntime.Cache[currentUser.Code] = filterContext.HttpContext.Session.SessionID;
                        }
                    }
                }
            }
            #endregion

            #region 用户是否登录
            PrincipalUser principalUser = FormAuthenticationExtension.Current(HttpContext.Current.Request);
            if (principalUser == null)
            {
                ErrorRedirect(filterContext, "/Error/ReturnToLogin");
                return;
            }
            #endregion

            #region 是否具有HttpPost/HttpGet请求验证
            var isAjaxRequest = filterContext.HttpContext.Request.IsAjaxRequest();
            #endregion

            #region 验证该方法是否需要进行权限验证
            //todo:1、获取用户信息。2、从缓存中获取该用户权限,若没有数据则从数据库中重新拉取(有可能缓存失效),再将权限数据填充到缓存中。
            //配置的当前系统代码
            string appCode = ConfigurationManager.AppSettings["AppCode"];
            //区域
            string area = string.Empty;
            //控制器
            string controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            //方法
            string action    = filterContext.ActionDescriptor.ActionName;
            var    routeData = filterContext.RequestContext.RouteData;
            if (routeData.DataTokens["area"] != null)
            {
                area = routeData.DataTokens["area"].ToString();
            }
            //调用Api接口查看是否具有该权限
            string apiUrl = ConfigurationManager.AppSettings["SolutionApiUrl"];

            //是否为Ajax请求,若是Ajax请求则不进行界面验证(此处只验证视图)
            if (!isAjaxRequest)
            {
                if (currentUser != null)
                {
                    //string request = RequestUtil.SendPostRequest(apiUrl + "api/System/Permission/GetSystemPermissionsMvcRote",
                    //"UserId=" + currentUser.UserId + "&AppCode=" + appCode + "&Area=" + area + "&Controller=" + controller + "&Action=" + action);
                    //OperateStatus operateStatus = request.Deserialize<OperateStatus>();
                    //if (operateStatus.ResultSign == ResultSign.Error)
                    //{
                    //     //ErrorRedirect(filterContext, "/Error/Warn");
                    //}
                }
            }

            #endregion
        }
Ejemplo n.º 10
0
        /// <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);
        }