Пример #1
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public NGPResponse DeleteFiles(NGPSingleRequest <List <string> > request)
        {
            // 参数验证
            if (request == null || request.RequestData.IsNullOrEmpty())
            {
                return(new NGPResponse
                {
                    ErrorCode = ErrorCode.ParamEmpty,
                    Message = CommonResource.ParameterError,
                    Status = OperateStatus.Error
                });
            }

            // 查询id对应的文件列表
            var fileList = _unitRepository.All <Sys_File_Info>(s => request.RequestData.Contains(s.Id)).ToList();

            // 删除文件
            foreach (var file in fileList)
            {
                var fullPath = Path.Combine(_fileProvider.MapPath(file.FilePath), file.FileName);

                _fileProvider.DeleteFile(fullPath);

                _unitRepository.Delete(file);
            }
            return(new NGPResponse
            {
                AffectedRows = fileList.Count,
                Message = CommonResource.OperatorSuccess,
                Status = OperateStatus.Success,
            });
        }
        public ActionResult <NGPResponse> ResetPassword([FromBody] ResetPasswordRequest request)
        {
            //获取人员Id
            var employee = _repository.FirstOrDefault <SysOrg_Employee>(s => s.LoginName == request.LoginName);

            // 用户不存在
            if (employee == null)
            {
                return(NGPResponse.Create(Framework.Core.StatusCode.NotExistErrorOne, request.LoginName));
            }
            var empId = employee.Id;
            // 验证码校验
            var verItem = _repository.All <SysOrg_EmpVerification>(s => s.IsDelete == false && s.EmpId == empId).OrderByDescending(s => s.SendTime).FirstOrDefault();

            // 验证码错误
            if (verItem == null || !verItem.VerificationCode.Equals(request.VerificationCode))
            {
                return(NGPResponse.Create(Framework.Core.StatusCode.VerificationCodeError));
            }

            employee.Password = CommonHelper.Encrypt(request.Password);
            employee.InitUpdateDefaultFields();
            _repository.Update(employee);
            _repository.SaveChanges();
            return(Ok(NGPResponse.Create()));
        }
Пример #3
0
        public MoviesView GetMovie(string Id)
        {
            var data = _repository.FindById <MoviesInfo>(Id);

            var detial = _repository.All <UrlSource>().Where(s => s.MovieId == Id).
                         Select(s => new SelectListItem {
                Text = s.VideoSource, Value = s.Url
            }).ToList();

            var line = new List <SelectListItem>();

            line.Add(new SelectListItem {
                Text = "A", Value = "http://www.wq114.org/x2/tong.php?url="
            });
            line.Add(new SelectListItem {
                Text = "B", Value = "https://jx.618g.com/?url="
            });
            line.Add(new SelectListItem {
                Text = "C", Value = "http://www.wmxz.wang/video.php?url="
            });
            line.Add(new SelectListItem {
                Text = "D", Value = "http://www.a305.org/weixin.php?url="
            });
            line.Add(new SelectListItem {
                Text = "E", Value = "http://www.vipjiexi.com/tong.php?url="
            });

            return(new MoviesView()
            {
                Id = data.Id,
                Name = data.Name,
                Stars = data.Stars,
                Description = data.Description,
                Image = data.ImageUrl,
                Sources = detial,
                Line = line,
                PlayLine = line[0],
                PlaySources = detial[0],
                PlayUrl = "https://jx.618g.com/?url=" + detial[0].Value
            });
        }
        /// <summary>
        /// Validates the resource owner password credential
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var dtNow = DateTime.Now;
            // 人员验证
            var employee = _unitRepository.FirstOrDefault <SysOrg_Employee>(s => s.LoginName == context.UserName && s.IsDelete == false);

            if (employee == null)
            {
                InsertLoginRecord(null, context.UserName);

                // "用户不存在!"

                // TODO
                context.Result.CustomResponse = NGPResponse.Create(StatusCode.UserNotExistOrDeleted).ToDictionary();
                return(Task.CompletedTask);
            }
            if (employee.IsDelete)
            {
                InsertLoginRecord(null, context.UserName);
                context.Result.CustomResponse = NGPResponse.Create(StatusCode.HasDeleted).ToDictionary();
                return(Task.CompletedTask);
            }
            //获取当前用户登录验证信息
            var verificationInfo = _unitRepository.All <SysOrg_EmpVerification>(s => s.IsDelete == false && s.EmpId == employee.Id).OrderByDescending(s => s.SendTime).FirstOrDefault();


            var verificationCode = string.Empty;

            if (context.Request.Raw.AllKeys.Contains("verification_code"))
            {
                verificationCode = context.Request.Raw["verification_code"];
            }

            //用户已锁定
            if (employee.IsLocking.HasValue && employee.IsLocking.Value)
            {
                //判断传参是否有验证码
                if (!string.IsNullOrWhiteSpace(verificationCode))
                {
                    //判断验证码是否正确
                    if (verificationInfo != null && verificationCode == verificationInfo.VerificationCode)
                    {
                        employee.IsLocking    = false;
                        employee.FailureTimes = 0;
                    }
                    else
                    {
                        InsertLoginRecord(employee, context.UserName, false);
                        context.Result.CustomResponse = NGPResponse.Create(StatusCode.WrongCode).ToDictionary();
                        return(Task.CompletedTask);
                    }
                    //获取时间差
                    var mins = dtNow.Subtract(verificationInfo.SendTime.Value).Minutes;
                    //判断验证码是否失效
                    if (mins > 5)
                    {
                        InsertLoginRecord(employee, context.UserName, false);
                        context.Result.CustomResponse = NGPResponse.Create(StatusCode.OverdueCode).ToDictionary();
                        return(Task.CompletedTask);
                    }
                }
                else
                {
                    //判断该账户是否绑定手机
                    if (string.IsNullOrEmpty(employee.PhoneNumber))
                    {
                        InsertLoginRecord(employee, context.UserName, false);
                        context.Result.CustomResponse = NGPResponse.Create(StatusCode.BeLocked).ToDictionary();
                        return(Task.CompletedTask);
                    }
                    else
                    {
                        InsertLoginRecord(employee, context.UserName, false);
                        context.Result.CustomResponse = NGPResponse.Create(StatusCode.WarnRelieve).ToDictionary();
                        return(Task.CompletedTask);
                    }
                }
            }

            //用户被禁用
            if (employee.AccountStatus.HasValue && employee.AccountStatus == false)
            {
                InsertLoginRecord(employee, context.UserName, false);
                context.Result.CustomResponse = NGPResponse.Create(StatusCode.BeBaned).ToDictionary();
                return(Task.CompletedTask);
            }
            // 密码不正确
            if (!string.Equals(employee.Password, CommonHelper.Encrypt(context.Password), StringComparison.CurrentCulture))
            {
                //判断登录失败次数是否已超过5次
                if (employee.FailureTimes.HasValue && employee.FailureTimes.Value >= 4)
                {
                    employee.IsLocking = true;
                }
                else
                {
                    employee.FailureTimes = (employee.FailureTimes ?? 0) + 1;
                }
                _unitRepository.Update(employee);
                InsertLoginRecord(employee, context.UserName, false);
                context.Result.CustomResponse = NGPResponse.Create(StatusCode.WrongPassword).ToDictionary();
                return(Task.CompletedTask);
            }
            //判断当前用户是否为白名单
            if (!(employee.IsWhiteList.HasValue && employee.IsWhiteList.Value))
            {
                //判断当前用户是否填写手机号
                if (string.IsNullOrWhiteSpace(employee.PhoneNumber))
                {
                    InsertLoginRecord(employee, context.UserName, false);
                    context.Result.CustomResponse = NGPResponse.Create(StatusCode.UnBindPhone).ToDictionary();
                    return(Task.CompletedTask);
                }
                //判断验证码是否正确
                if (string.IsNullOrWhiteSpace(verificationCode))
                {
                    InsertLoginRecord(employee, context.UserName, false);
                    context.Result.CustomResponse = NGPResponse.Create(StatusCode.PleaseSendVerification).ToDictionary();
                    return(Task.CompletedTask);
                }
                if (verificationInfo == null || !verificationCode.Equals(verificationInfo.VerificationCode))
                {
                    InsertLoginRecord(employee, context.UserName, false);
                    InsertLoginRecord(employee, context.UserName, false);
                    context.Result.CustomResponse = NGPResponse.Create(StatusCode.WrongCode).ToDictionary();
                    return(Task.CompletedTask);
                }
                else
                {
                    //获取时间差
                    var minutes = dtNow.Subtract(verificationInfo.SendTime.Value).Minutes;
                    //判断验证码是否失效
                    if (minutes > 5)
                    {
                        InsertLoginRecord(employee, context.UserName, false);
                        context.Result.CustomResponse = NGPResponse.Create(StatusCode.OverdueCode).ToDictionary();
                        return(Task.CompletedTask);
                    }
                }
            }

            // 添加claim
            ICollection <Claim> claims = new HashSet <Claim>(new ClaimComparer())
            {
                // 用户id
                new Claim(JwtClaimTypes.Id, employee.Id),
                // 用户名(登录后显示用)
                new Claim(JwtClaimTypes.Name, employee.EmployeeName),
                // AreaId
                new Claim("ngp_area_id", employee.AreaId),
                // LoginName
                new Claim("ngp_login_name", employee.LoginName),
            };

            // 添加公司id
            if (context.Request.Raw.AllKeys.Contains("company_id"))
            {
                claims.Add(new Claim("company_id", context.Request.Raw["company_id"]));
            }

            // 部门id
            if (!string.IsNullOrWhiteSpace(employee.DeptId))
            {
                claims.Add(new Claim("ngp_dept_id", employee.DeptId));
            }

            // 人员类别
            if (!string.IsNullOrWhiteSpace(employee.EmployeeTypes))
            {
                claims.Add(new Claim("ngp_employee_types", employee.EmployeeTypes));
            }

            // 是否系统管理员
            if (employee.IsSystemAdmin.HasValue)
            {
                claims.Add(new Claim("is_system_admin", employee.IsSystemAdmin.ToString()));
            }
            //身份类别
            if (!string.IsNullOrWhiteSpace(employee.IdentityType))
            {
                claims.Add(new Claim("ngp_identity_type", employee.IdentityType));
            }
            // 用户角色
            var roleEmpl = _unitRepository.FirstOrDefault <SysOrg_RoleEmpl>(s => s.EmplId == employee.Id && s.IsDelete == false);

            // 角色信息
            if (roleEmpl != null)
            {
                claims.Add(new Claim("role_id", roleEmpl.RoleId));
                var roleinfo = _unitRepository.FirstOrDefault <SysOrg_Role>(s => s.Id == roleEmpl.RoleId && s.IsDelete == false);
                if (roleinfo != null)
                {
                    claims.Add(new Claim("role_type", roleinfo.RoleType));
                }
            }

            employee.FailureTimes = 0;
            employee.SuccessTimes = (employee.SuccessTimes ?? 0) + 1;
            employee.LoginTime    = DateTime.Now;
            _unitRepository.Update(employee);
            InsertLoginRecord(employee, context.UserName, true);

            context.Result = new GrantValidationResult(
                employee.LoginName,
                OidcConstants.AuthenticationMethods.Password,
                _clock.UtcNow.UtcDateTime,
                claims);
            context.Result.CustomResponse = NGPResponse.Create(StatusCode.Success).ToDictionary();
            return(Task.CompletedTask);
        }
Пример #5
0
        private void Hao123MoviesCrawler(List <string> urlList, bool isDetial = false)
        {
            HtmlParser htmlParser = new HtmlParser();
            string     resource   = Const.SourcesType.Hao123;

            for (var i = 0; i < urlList.Count; i++)
            {
                var crawler = new SimpleCrawler();

                crawler.OnStart += (s, e) =>
                {
                    Console.WriteLine("爬虫开始抓取地址:" + e.Uri.ToString());
                };
                crawler.OnError += (s, e) =>
                {
                    Console.WriteLine("爬虫抓取出现错误:" + e.Uri.ToString() + ",异常消息:" + e.Exception.Message);
                };
                crawler.OnCompleted += (s, e) =>
                {
                    if (isDetial)
                    {
                        var dom = htmlParser.ParseDocument(e.PageSource);

                        var moviesInfo    = new MoviesInfo();
                        var urlSourceList = new List <UrlSource>();

                        moviesInfo.Id       = GuidExtend.NewGuid();
                        moviesInfo.Resource = resource;

                        moviesInfo.CreateTime = DateTime.Now;

                        var a = dom.QuerySelectorAll("div.poster>a");
                        if (a.Any())
                        {
                            moviesInfo.Name = a[0].GetAttribute("title"); //--电影名称
                        }
                        else
                        {
                            return;
                        }

                        var stars = dom.All.Where(sl => sl.GetAttribute("monkey") == "actor").ToList();

                        if (stars.Any())
                        {
                            moviesInfo.Stars = string.Join(",", stars[0].QuerySelectorAll("a").Select(X => X.InnerHtml).ToList().Distinct());
                        }

                        var type = dom.All.Where(sl => sl.GetAttribute("monkey") == "category").ToList();

                        if (type.Any())
                        {
                            moviesInfo.Type = string.Join(",", type[0].QuerySelectorAll("a").Select(X => X.InnerHtml).ToList().Distinct());
                        }


                        var area = dom.All.Where(sl => sl.GetAttribute("monkey") == "area").ToList();

                        if (area.Any())
                        {
                            moviesInfo.Area = string.Join(",", area[0].QuerySelectorAll("a").Select(X => X.InnerHtml).ToList().Distinct());
                        }

                        var year = dom.All.Where(sl => sl.GetAttribute("monkey") == "decade").ToList();

                        if (year.Any())
                        {
                            moviesInfo.Year = string.Join(",", year[0].QuerySelectorAll("a").Select(X => X.InnerHtml).ToList().Distinct());
                        }

                        var img = dom.QuerySelectorAll("div.poster>a>img");

                        if (img.Any())
                        {
                            moviesInfo.ImageUrl = img[0].GetAttribute("src"); //--图片
                        }

                        var des = dom.QuerySelectorAll("p.abstract>em");

                        if (des.Any())
                        {
                            moviesInfo.Description = des[0].InnerHtml;
                        }

                        var url = dom.QuerySelectorAll("div.source>a.play-btn");

                        if (url.Any())
                        {
                            var urlSource = new UrlSource();
                            urlSource.Url         = url[0].GetAttribute("href");
                            urlSource.VideoSource = url[0].GetAttribute("alog-text");
                            urlSource.Id          = GuidExtend.NewGuid();
                            urlSource.MovieId     = moviesInfo.Id;
                            urlSource.Resource    = resource;

                            urlSourceList.Add(urlSource);
                        }

                        var urls = dom.QuerySelectorAll("div.source")[0].QuerySelectorAll("ul>li>a").
                                   Select(x => new UrlSource
                        {
                            Id          = GuidExtend.NewGuid(),
                            MovieId     = moviesInfo.Id,
                            Url         = x.GetAttribute("href"),
                            VideoSource = x.TextContent,
                            Resource    = resource
                        });

                        if (urls.Any())
                        {
                            urlSourceList.AddRange(urls);
                        }

                        if (!string.IsNullOrEmpty(moviesInfo.Name) && urlSourceList.Count > 0)
                        {
                            var oldData = _repository.All <MoviesInfo>(sl => sl.Name == moviesInfo.Name && sl.ImageUrl == moviesInfo.ImageUrl);

                            oldData.DeleteFromQuery();

                            _repository.DeleteByExpression <UrlSource>(sl => oldData.Select(m => m.Id).Contains(sl.MovieId));

                            _repository.Insert(moviesInfo, true);
                            _repository.BulkInsert <UrlSource>(urlSourceList);
                        }
                    }
                    else
                    {
                        var dom = htmlParser.ParseDocument(e.PageSource);

                        var MovieUrlList = dom.QuerySelectorAll("li.card>a").Select(a => a.GetAttribute("href")).ToList();

                        Hao123MoviesCrawler(MovieUrlList, true);
                    }
                };
                crawler.Start(new Uri(urlList[i])).Wait();
            }
        }
Пример #6
0
 public List <RefreshTokenInfo> GetAllRefreshTokens()
 {
     return(_repository.All <RefreshTokenInfo>().ToList());
 }