Ejemplo n.º 1
0
        public commonresponse again()
        {
            var accinfo = highlevel.GetInfoByToken(Request.Headers);

            if (accinfo.status != responseStatus.ok)
            {
                return(accinfo);
            }

            try
            {
                var theuser = _db1.Business.FirstOrDefault(i => i.Identity == accinfo.Identity && i.Businesstype == (short)accinfo.businessType);
                if (theuser == null)
                {
                    return(highlevel.commonreturn(responseStatus.iderror));
                }
                theuser.Integrated = false;
                theuser.Status     = (short)businessstatus.unknown;
                theuser.Exporttime = new DateTime(2000, 1, 1);
                var reason = string.Empty;
                if (!string.IsNullOrEmpty(theuser.Reason))
                {
                    reason = theuser.Reason;
                }
                _db1.Businesshis.Add(new Businesshis
                {
                    Identity     = theuser.Identity,
                    Businesstype = theuser.Businesstype,
                    Completed    = true,
                    Time         = theuser.Finishtime,
                    Reason       = reason
                });

                var pics = _db1.Businesspic.Where(i => i.Identity == accinfo.Identity && i.Businesstype == (short)accinfo.businessType);
                foreach (var p in pics)
                {
                    p.Uploaded = false;
                }
                _db1.SaveChanges();
            }
            catch (Exception ex)
            {
                _log.LogError("db error:{0}", ex.Message);
                return(highlevel.commonreturn(responseStatus.dberror));
            }
            try
            {
                var he = Request.Host.ToString();
                foreach (var a in Request.Headers)
                {
                    he += "--" + a.Key + "=" + a.Value;
                }
                Task.Run(() => highlevel.LogRequest(he + accinfo.Identity,
                                                    "again", Request.HttpContext.Connection.RemoteIpAddress.ToString(), (short)accinfo.businessType));
            }
            catch (Exception ex) { _log.LogError("dblog error:", ex); }
            return(highlevel.commonreturn(responseStatus.ok));
        }
Ejemplo n.º 2
0
        public loginresponse login(string name, string identify, string phone, businessType businessType)
        {
            if (string.IsNullOrEmpty(identify) || identify == "undefined")
            {
                return(new loginresponse {
                    status = responseStatus.iderror
                });
            }
            if (string.IsNullOrEmpty(name) || name == "undefined")
            {
                return(new loginresponse {
                    status = responseStatus.nameerror
                });
            }
            if (string.IsNullOrEmpty(phone) || phone == "undefined")
            {
                return(new loginresponse {
                    status = responseStatus.phoneerror
                });
            }
            if (businessType == businessType.unknown)
            {
                return(new loginresponse {
                    status = responseStatus.businesstypeerror
                });
            }

            //if (!checkbusi(identify, businessType))
            //{
            //    highlevel.LogRequest(name + phone + identify + responseStatus.forbidden, "login", Request.HttpContext.Connection.RemoteIpAddress.ToString(), (short)businessType);

            //    return new loginresponse { status = responseStatus.forbidden };
            //}
            // _log.LogInformation("{3}-{0} from {1}, input is {2}", DateTime.Now, "login",
            //  Request.HttpContext.Connection.RemoteIpAddress.ToString() + HttpContext.Connection.RemoteIpAddress,
            // identify + name + phone + businessType);

            var btype    = (short)businessType;
            var picsl    = new List <short>();
            var token    = GetToken();
            var response = new loginresponse
            {
                status         = responseStatus.ok, blacklist = false,
                businessstatus = businessstatus.unknown,
                submitted      = false,
                content        = "unknown",
                token          = token,
                okpic          = picsl.ToArray()
            };

            try
            {
                if (businessType == businessType.overage)
                {
                    var idl = identify.Length;
                    if (idl == 18)//
                    {
                        var year  = int.Parse(identify.Substring(6, 4));
                        var month = int.Parse(identify.Substring(10, 2));
                        var day   = int.Parse(identify.Substring(12, 2));
                        var birth = new DateTime(year, month, day);
                        if (birth.AddYears(60) > DateTime.Now)
                        {
                            return new loginresponse {
                                       status = responseStatus.forbidden
                            }
                        }
                        ;
                    }
                    else if (idl == 15)
                    {
                        var year  = int.Parse(identify.Substring(6, 2)) + 1900;
                        var month = int.Parse(identify.Substring(8, 2));
                        var day   = int.Parse(identify.Substring(10, 2));
                        var birth = new DateTime(year, month, day);
                        if (birth.AddYears(60) > DateTime.Now)
                        {
                            return new loginresponse {
                                       status = responseStatus.forbidden
                            }
                        }
                        ;
                    }
                }

                var theuser = _db1.Aouser.FirstOrDefault(i => i.Identity == identify);
                if (theuser == null)
                {
                    _db1.Aouser.Add(new Aouser
                    {
                        Identity = identify, Blacklist = false,
                        Phone    = phone,
                        Name     = name
                    });
                    _db1.SaveChanges();
                }

                var business = _db1.Business.FirstOrDefault(i => i.Identity == identify && i.Businesstype == (short)businessType);
                if (business == null)
                {
                    _db1.Business.Add(new Business
                    {
                        Identity     = identify,
                        Businesstype = (short)businessType,
                        Completed    = false,
                        Time         = DateTime.Now,
                    });
                    _db1.SaveChanges();
                }
                else
                {
                    var pics = _db1.Businesspic.Where(c => c.Businesstype == btype && c.Identity == identify && c.Uploaded == true);
                    response.businessstatus = (businessstatus)business.Status;
                    response.finish_time    = business.Finishtime;
                    response.wait_time      = business.Waittime;
                    response.process_time   = business.Processtime;
                    if (!string.IsNullOrEmpty(business.Reason))
                    {
                        response.content = business.Reason;
                    }
                    if (pics.Count() < global.businesscount[businessType] || response.businessstatus == businessstatus.failure)
                    {
                        foreach (var a in pics)
                        {
                            picsl.Add(a.Pictype);
                        }
                        response.okpic = picsl.ToArray();
                        if (response.businessstatus == businessstatus.failure)
                        {
                            response.submitted = true;
                        }
                    }
                    else
                    {
                        response.submitted = true;
                        // response.businessstatus = (businessstatus)business.Status;

                        // response.finish_time = business.Finishtime;
                        // response.wait_time = business.Waittime;
                        // response.process_time = business.Processtime;
                    }
                }
                if (theuser != null && theuser.Blacklist == true)
                {
                    response.blacklist = true;
                }
            }
            catch (Exception ex)
            {
                _log.LogError("login -- process error:{0}", ex.Message);
            }

            try
            {
                var redisdb = highlevel.redis.GetDatabase();
                redisdb.StringSet(token, JsonConvert.SerializeObject(new idinfo {
                    Identity = identify, businessType = businessType
                }));
                redisdb.KeyExpire(token, TimeSpan.FromDays(30));
            }
            catch (Exception ex)
            {
                _log.LogError("redis key process error:{0}", ex.Message);
            }

            var found = false;

            foreach (var a in global.tokens)
            {
                if (a.idinfo.Identity == identify && a.idinfo.businessType == businessType)
                {
                    a.Token = token;
                    found   = true;
                    break;
                }
            }
            if (!found)
            {
                global.tokens.Add(new Ptoken {
                    idinfo = new idinfo {
                        Identity = identify, businessType = businessType
                    }, Token = token
                });
            }
            try
            {
                var he = Request.Host.ToString();
                foreach (var a in Request.Headers)
                {
                    he += "--" + a.Key + "=" + a.Value;
                }
                Task.Run(() => highlevel.LogRequest(he + name + phone + identify + JsonConvert.SerializeObject(response),
                                                    "login", Request.HttpContext.Connection.RemoteIpAddress.ToString(), (short)businessType));
            }
            catch (Exception ex) { _log.LogError("dblog error:", ex); }
            return(response);
        }
Ejemplo n.º 3
0
        public commonresponse uploadpic([FromBody] uploadpicrequest input)
        {
            //  highlevel.LogRequest("uploadpic", "uploadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString());
            if (input == null)
            {
                return(highlevel.commonreturn(responseStatus.requesterror));
            }
            var accinfo = highlevel.GetInfoByToken(Request.Headers);

            if (accinfo.status != responseStatus.ok)
            {
                return(accinfo);
            }

            _log.LogInformation("uploadpic-{3}: id={0},bt={1},pictype={2}", accinfo.Identity, accinfo.businessType, input.picType, DateTime.Now);
            if (!savePic(input.picture, input.picType, accinfo.Identity, accinfo.businessType))
            {
                return(highlevel.commonreturn(responseStatus.fileprocesserror));
            }

            if (input.picType == picType.unknown)
            {
                return(highlevel.commonreturn(responseStatus.pictypeerror));
            }
            if (accinfo.businessType == businessType.unknown)
            {
                return(highlevel.commonreturn(responseStatus.businesstypeerror));
            }
            try
            {
                using (var ddbb = new aboContext())
                {
                    var already = ddbb.Businesspic.FirstOrDefault(i => i.Businesstype == (int)accinfo.businessType && i.Identity == accinfo.Identity && i.Pictype == (short)input.picType);
                    if (already == null)
                    {
                        var newpic = new Businesspic
                        {
                            Identity     = accinfo.Identity,
                            Businesstype = (short)accinfo.businessType,
                            Pictype      = (short)input.picType,
                            Uploaded     = true,
                            Time         = DateTime.Now
                        };
                        //  highlevel.infolog(_log, "uploadpic", JsonConvert.SerializeObject(newpic));
                        var ret = ddbb.Businesspic.Add(newpic);
                        //  highlevel.infolog(_log, "uploadpic88", JsonConvert.SerializeObject(ret.Entity));
                    }
                    else
                    {
                        already.Uploaded = true;
                        already.Time     = DateTime.Now;
                    }
                    ddbb.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                highlevel.errorlog(_log, "uploadpic", ex);
            }
            try
            {
                var he = Request.Host.ToString();
                foreach (var a in Request.Headers)
                {
                    he += "--" + a.Key + "=" + a.Value;
                }
                Task.Run(() => highlevel.LogRequest(he + input.picType + accinfo.Identity,
                                                    "uploadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString(), (short)accinfo.businessType));
            }
            catch (Exception ex) { _log.LogError("dblog error:", ex); }
            _log.LogInformation("uploadpic-{3}: id={0},bt={1},pictype={2}---over", accinfo.Identity, accinfo.businessType, input.picType, DateTime.Now);
            return(new commonresponse {
                status = responseStatus.ok
            });
        }