/// <summary>
        /// 保存
        /// </summary>
        /// <param name="theData">保存的数据</param>
        public ActionResult SaveData(Base_SysUserOperationLog theData)
        {
            if (theData.Id.IsNullOrEmpty())
            {
                theData.Id = Guid.NewGuid().ToSequentialGuid();

                _base_SysUserOperationLogBusiness.AddData(theData);
            }
            else
            {
                _base_SysUserOperationLogBusiness.UpdateData(theData);
            }

            return(Success());
        }
示例#2
0
        public IActionResult LoginSubmit(SecretDto dto)
        {
            //Todo:获取用户信息
            var user = _homeBus.JwtSubmitLogin(dto.username, dto.password);

            if (user == null)
            {
                return(Ok(
                           new AjaxResult
                {
                    Success = false,
                    Msg = "用户名或密码错误!",
                    Data = new JwtResponseDto
                    {
                        Access = "用户名或密码错误!",
                        Type = "Bearer",
                        Profile = new Profile
                        {
                            UserName = dto.username,
                            Auths = 0,
                            Expires = 0
                        }
                    },
                    ErrorCode = 0
                }));
            }

            var jwt = _jwtApp.Create(user);

            #region 登录系统的操作记录单写,主要是登录系统时,Token还没有传递
            //获取Ip地址的临时写法,这个写法不准确,没考虑代理
            string ipAddress = HttpContextCore.Current.Connection.RemoteIpAddress.ToString();
            Base_SysUserOperationLog sysUserOperationLog = new Base_SysUserOperationLog
            {
                Id         = GuidHelper.GenerateKey(),
                LogType    = EnumType.LogType.用户操作.ToString(),
                LogContent = $"[{DateTime.Now.ToCstTime().ToString("yyyy-MM-dd HH:mm:ss")}][{ipAddress}]地址的[" + user.RealName + "]用户操作记录:登录系统",
                OpTime     = DateTime.Now.ToCstTime(),
                OpUserName = user.RealName
            };
            Task.Run(() =>
            {
                try
                {
                    Base_SysUserOperationLogBusiness _base_SysUserOperationLogBusiness = new Base_SysUserOperationLogBusiness();
                    _base_SysUserOperationLogBusiness.Insert(sysUserOperationLog);
                }
                catch
                {
                }
            });
            #endregion

            return(Ok(
                       new AjaxResult
            {
                Success = true,
                Msg = "登录成功!",
                Data = new JwtResponseDto
                {
                    Access = jwt.Token,
                    Type = "Bearer",
                    Profile = new Profile
                    {
                        UserId = user.UserId,
                        UserName = user.UserName,
                        RealName = user.RealName,
                        Auths = jwt.Auths,
                        Expires = jwt.Expires
                    }
                },
                ErrorCode = 0
            }));
        }