Esempio n. 1
0
        // [Route("salt")]
        // [HttpGet]

        // public GetLearnerInfoResponse salt(string token)
        // {
        //     try
        //     {
        //         //  var aa= Request.Headers["Content-Type"];

        //         if (string.IsNullOrEmpty(token))
        //         {

        //             return new GetLearnerInfoResponse
        //             {
        //                 StatusCode = Global.Status[responseCode.TokenError].StatusCode,
        //                 Description = Global.Status[responseCode.TokenError].Description
        //             };
        //         }
        //         var key = "2cff5601e52f4747bfb9e271fe45042a";
        //         var salt = "d31beaac47b44b45b1c6066712d49ff6";
        //         var original_value = token;
        //         var encrypted_value = CryptographyHelpers.Encrypt(key, salt, original_value);
        //         var target = CryptographyHelpers.Decrypt(key, salt, encrypted_value);


        //         return new GetLearnerInfoResponse
        //         {
        //             Name = encrypted_value,
        //             //   Identity = encrypted_value.Length.ToString(),
        //             StatusCode = encrypted_value.Length.ToString(),
        //             Description = target,

        //         };
        //     }
        //     catch (Exception ex)
        //     {

        //         return new GetLearnerInfoResponse
        //         {
        //             StatusCode = Global.Status[responseCode.ProgramError].StatusCode,
        //             Description = Global.Status[responseCode.ProgramError].Description + ex.Message
        //         };
        //     }
        // }
        private async void LogRequest(string content, string method = null, string ip = null)
        {
            try
            {
                var to = GetToken();
                // Log.Information("LogRequest,{0},from ip={1}",to+ ", begin", Request.HttpContext.Connection.RemoteIpAddress);
                // await Task.Delay(5000);
                Log.Information("LogRequest,{0},from ip={1}", to + ", 000", Request.HttpContext.Connection.RemoteIpAddress);
                var dbtext       = string.Empty;
                var dbmethod     = string.Empty;
                var dbip         = string.Empty;
                var contentlenth = 150;
                var shortlength  = 44;
                if (!string.IsNullOrEmpty(content))
                {
                    var lenth = content.Length;
                    dbtext = lenth > contentlenth?content.Substring(0, contentlenth) : content;
                }
                if (!string.IsNullOrEmpty(method))
                {
                    dbmethod = method.Length > shortlength?method.Substring(0, shortlength) : method;
                }
                if (!string.IsNullOrEmpty(ip))
                {
                    dbip = ip.Length > shortlength?ip.Substring(0, shortlength) : ip;
                }
                await Task.Run(() =>
                {
                    Log.Information("LogRequest,{0},from ip={1}", to + ", 111", Request.HttpContext.Connection.RemoteIpAddress);
                    using (var logdb = new blahContext()){
                        for (int i = 0; i < 1000; i++)
                        {
                            logdb.Request.Add(
                                new Request
                            {
                                Content = i.ToString(),
                                Ip      = dbip,
                                Method  = dbmethod,
                                Time    = DateTime.Now
                            }
                                );
                        }

                        logdb.SaveChanges();
                    }
                    Log.Information("LogRequest,{0},from ip={1}", to + ", 222", Request.HttpContext.Connection.RemoteIpAddress);
                    //  await Task.Delay(2000);
                    //      Log.Information("LogRequest,{0},from ip={1}", to+", 333", Request.HttpContext.Connection.RemoteIpAddress);
                });

                Log.Information("LogRequest,{0},from ip={1}", to + ", end", Request.HttpContext.Connection.RemoteIpAddress);
            }
            catch (Exception ex)
            {
                Log.Information("LogRequest error,{0},from ip={1}", ex.Message, Request.HttpContext.Connection.RemoteIpAddress);
            }
        }
Esempio n. 2
0
        private async void LogRequest(string content, string method = null, string ip = null, short businessType = 0)
        {
            var dbtext       = string.Empty;
            var dbmethod     = string.Empty;
            var dbip         = string.Empty;
            var contentlenth = 150;
            var shortlength  = 44;

            if (!string.IsNullOrEmpty(content))
            {
                var lenth = content.Length;
                dbtext = lenth > contentlenth?content.Substring(0, contentlenth) : content;
            }
            if (!string.IsNullOrEmpty(method))
            {
                dbmethod = method.Length > shortlength?method.Substring(0, shortlength) : method;
            }
            if (!string.IsNullOrEmpty(ip))
            {
                dbip = ip.Length > shortlength?ip.Substring(0, shortlength) : ip;
            }
            await Task.Run(() =>
            {
                using (var logdb = new blahContext())
                {
                    logdb.Request.Add(new Request
                    {
                        Content      = dbtext,
                        Businesstype = businessType,
                        Ip           = dbip,
                        Method       = dbmethod,
                        Time         = DateTime.Now
                    });
                    logdb.SaveChanges();
                }
            });
        }
Esempio n. 3
0
        public async Task <LoginAndQueryResponse> LoginAndQuery([FromBody] LoginAndQueryRequest inputRequest)
        {
            try
            {
                var input = JsonConvert.SerializeObject(inputRequest);
                await Task.Run(() =>
                               LogRequest(input, "LoginAndQuery", Request.HttpContext.Connection.RemoteIpAddress.ToString()));

                if (inputRequest == null)
                {
                    Log.Error("LoginAndQuery,{0}", Global.Status[responseCode.studyRequestError].Description);
                    return(new LoginAndQueryResponse
                    {
                        StatusCode = Global.Status[responseCode.studyRequestError].StatusCode,
                        Description = Global.Status[responseCode.studyRequestError].Description
                    });
                }
                Log.Information("LoginAndQuery,input={0},from {1}", input, Request.HttpContext.Connection.RemoteIpAddress);
                var allstatus       = string.Empty;
                var allow           = true;
                var completed       = true;
                var signed          = true;
                var firstsigned     = true;
                var drivinglicense  = string.Empty;
                var deductedmarks   = 0;
                var identity        = inputRequest.Identity;
                var fname           = identity + ".jpg";
                var cryptographicid = CryptographyHelpers.StudyEncrypt(identity);
                var pic             = new byte[8];


                //token process
                var toke1n    = GetToken();
                var found     = false;
                var lasttoken = string.Empty;
                foreach (var a in tokens)
                {
                    if (a.Identity == identity)
                    {
                        //  lasttoken = a.Token;
                        a.Token = toke1n;
                        found   = true;
                        break;
                    }
                }
                if (!found)
                {
                    tokens.Add(new Ptoken {
                        Identity = identity, Token = toke1n
                    });
                }

                var theuser = _db1.User.FirstOrDefault(async => (async.Identity == identity || async.Identity == cryptographicid) &&
                                                       async.Inspect == "1"
                                                       );
                if (theuser == null)
                {
                    var his = _db1.History.Where(async => async.Identity == identity || async.Identity == cryptographicid)
                              .OrderBy(al => al.Finishdate).LastOrDefault();
                    if (his == null)
                    {
                        Log.Error("LoginAndQuery,{0}", Global.Status[responseCode.studyNotNecessary].Description + identity);
                        return(new LoginAndQueryResponse
                        {
                            StatusCode = Global.Status[responseCode.studyNotNecessary].StatusCode,
                            Description = Global.Status[responseCode.studyNotNecessary].Description + identity
                        });
                    }
                    allow = his.Drugrelated != "1" ? true : false;
                    if (!string.IsNullOrEmpty(his.Status) && (his.Status.Contains("H") || his.Status.Contains("M")))
                    {
                        allow = false;
                    }
                    completed   = his.Completed == "1" ? true : false;
                    signed      = his.Signed == "1" ? true : false;
                    firstsigned = his.Firstsigned == "1" ? true : false;
                    if (!string.IsNullOrEmpty(his.Licensetype))
                    {
                        drivinglicense = his.Licensetype;
                    }
                    if (his.Deductedmarks != null)
                    {
                        deductedmarks = (int)his?.Deductedmarks;
                    }
                    try
                    {
                        if (!string.IsNullOrEmpty(his.Photofile))
                        {
                            fname = his.Photofile;
                            pic   = CryptographyHelpers.StudyFileDecrypt(Path.Combine(Global.PhotoPath, fname));
                        }
                        else
                        {
                            var filename = Path.Combine(Global.PhotoPath, fname);
                            pic = System.IO.File.ReadAllBytes(filename);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("loginandquery,{0},={1}", identity, ex.Message);
                    }
                    if (allow)
                    {
                        allstatus = his.Studylog;
                    }
                    else
                    {
                        allstatus = "您不能参加网络学习,可以参加现场学习";
                    }
                }
                else
                {
                    //drugrelated judge
                    allow = theuser.Drugrelated != "1" ? true : false;
                    if (!string.IsNullOrEmpty(theuser.Status) && (theuser.Status.Contains("H") || theuser.Status.Contains("M")))
                    {
                        allow = false;
                    }
                    completed   = theuser.Completed == "1" ? true : false;
                    signed      = theuser.Signed == "1" ? true : false;
                    firstsigned = theuser.Firstsigned == "1" ? true : false;
                    if (!string.IsNullOrEmpty(theuser.Licensetype))
                    {
                        drivinglicense = theuser.Licensetype;
                    }
                    if (theuser.Deductedmarks != null)
                    {
                        deductedmarks = (int)theuser?.Deductedmarks;
                    }
                    if (allow)
                    {
                        allstatus = theuser.Studylog;
                        //need update?
                        if (!string.IsNullOrEmpty(inputRequest.Name))
                        {
                            theuser.Name = inputRequest.Name;
                        }
                        //  theuser.Licensetype = ((int)inputRequest.DrivingLicenseType).ToString();//elements?
                        if (!string.IsNullOrEmpty(inputRequest.Phone))
                        {
                            theuser.Phone = inputRequest.Phone;
                        }
                        // theuser.Wechat = inputRequest.Wechat;
                        if (theuser.Startdate == null)
                        {
                            theuser.Startdate = DateTime.Now;
                        }
                        if (!string.IsNullOrEmpty(theuser.Token))
                        {
                            lasttoken = theuser.Token;
                        }
                        _db1.SaveChanges();
                    }
                    else
                    {
                        allstatus = "您不能参加网络学习,可以参加现场学习";
                    }
                    try
                    {
                        if (!string.IsNullOrEmpty(theuser.Photofile))
                        {
                            fname = theuser.Photofile;
                            pic   = CryptographyHelpers.StudyFileDecrypt(Path.Combine(Global.PhotoPath, fname));
                        }
                        else
                        {
                            var filename = Path.Combine(Global.PhotoPath, fname);
                            pic = System.IO.File.ReadAllBytes(filename);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("loginandquery,{0},={1}", identity, ex.Message);
                    }
                }



                return(new LoginAndQueryResponse
                {
                    Token = toke1n,
                    LastToken = lasttoken,
                    StatusCode = Global.Status[responseCode.studyOk].StatusCode,
                    Description = Global.Status[responseCode.studyOk].Description,
                    AllowedToStudy = allow,
                    Completed = completed,
                    Signed = signed,
                    FirstSigned = firstsigned,
                    DrivingLicense = drivinglicense,
                    DeductedMarks = deductedmarks,
                    Photo = pic,
                    AllStatus = allstatus
                });
            }
            catch (Exception ex)
            {
                Log.Error("LoginAndQuery,{0}", ex);
                return(new LoginAndQueryResponse
                {
                    StatusCode = Global.Status[responseCode.studyProgramError].StatusCode,
                    Description = Global.Status[responseCode.studyProgramError].Description
                });
            }
        }
Esempio n. 4
0
        public commonresponse uploadpic([FromBody] uploadpicrequest input)
        {
            LogRequest("uploadpic", "uploadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString());
            if (input == null)
            {
                return(new commonresponse {
                    status = responseStatus.requesterror
                });
            }
            var identity = string.Empty;
            var btype    = businessType.basicinfo;

            try
            {
                var htoken = Request.Headers["token"].First();
                if (string.IsNullOrEmpty(htoken))
                {
                    return(new commonresponse {
                        status = responseStatus.tokenerror
                    });
                }
                var found = false;

                foreach (var a in tokens)
                {
                    if (a.Token == htoken)
                    {
                        identity = a.idinfo.Identity;
                        btype    = a.idinfo.businessType;
                        found    = true;
                        break;
                    }
                }
                if (!found)
                {
                    var redisdb     = highlevel.redis.GetDatabase();
                    var cacheidinfo = redisdb.StringGet(htoken);
                    if (cacheidinfo == "nil")
                    {
                        return(new commonresponse {
                            status = responseStatus.tokenerror
                        });
                    }
                    var ci = JsonConvert.DeserializeObject <idinfo>(cacheidinfo);
                    identity = ci.Identity;
                    btype    = ci.businessType;
                }
            }
            catch (Exception ex)
            {
                return(new commonresponse {
                    status = responseStatus.tokenerror
                });
            }

            // if (string.IsNullOrEmpty(input.id_back))
            // {
            //     return new commonresponse { status = responseStatus.imageerror };
            // }

            if (!savePic(input.picture, input.picType, identity, btype))
            {
                return new commonresponse {
                           status = responseStatus.fileprocesserror
                }
            }
            ;

            _db1.Businesspic.Add(new Businesspic
            {
                Identity     = identity,
                Businesstype = (short)btype,
                Pictype      = (short)input.picType,
                Uploaded     = true
            });
            _db1.SaveChanges();

            return(new commonresponse {
                status = responseStatus.ok
            });
        }