Beispiel #1
0
        /// <summary>
        /// 获取token
        /// </summary>
        /// <param name="item"></param>
        /// <param name="context"></param>
        private static Task Token(HttpContext context, DataContext db, string urlParam)
        {
            var dic       = new Dictionary <string, object>();
            var AppKey    = GetUrlParamKey(urlParam, "AppKey");
            var AppSecret = GetUrlParamKey(urlParam, "AppSecret");

            if (FastRead.Query <ApiGatewayUser>(a => a.AppKey.ToLower() == AppKey.ToLower() && a.AppSecret.ToLower() == AppSecret.ToLower()).ToCount(db) <= 0)
            {
                context.Response.StatusCode = 200;
                dic.Add("success", false);
                dic.Add("result", "AppKey和AppSecret参数不存在");
                return(context.Response.WriteAsync(JsonConvert.SerializeObject(dic).ToString(), Encoding.UTF8));
            }
            else
            {
                var info = FastRead.Query <ApiGatewayUser>(a => a.AppKey.ToLower() == AppKey.ToLower() && a.AppSecret.ToLower() == AppSecret.ToLower()).ToItem <ApiGatewayUser>(db);
                info.Ip            = GetClientIp(context);
                info.AccessExpires = DateTime.Now.AddHours(24).AddHours(8);
                info.AccessToken   = BaseSymmetric.Generate(string.Format("{0}_{1}_{2}", info.AppKey, info.AppSecret, info.AccessExpires)).ToLower();

                //修改信息
                FastWrite.Update <ApiGatewayUser>(info,
                                                  a => a.AppKey.ToLower() == AppKey.ToLower() && a.AppSecret.ToLower() == AppSecret.ToLower()
                                                  , a => new { a.AccessExpires, a.Ip, a.AccessToken }, db);

                dic.Add("success", true);
                dic.Add("AccessToken", info.AccessToken);
                dic.Add("AccessExpires", info.AccessExpires);

                context.Response.StatusCode = 200;
                return(context.Response.WriteAsync(JsonConvert.SerializeObject(dic).ToString(), Encoding.UTF8));
            }
        }
Beispiel #2
0
        public IActionResult Login(LoginModel item)
        {
            var isSuccess = false;

            using (var db = new DataContext(App.DbKey.Api))
            {
                var info = FastRead.Query <ApiGatewayLogin>(a => a.UserName.ToLower() == item.Code.ToLower()).ToDic(db);

                isSuccess = BaseSymmetric.Generate(item.Pwd).ToLower() == info.GetValue("UserPwd").ToStr().ToLower();

                info.Add("ip", App.Ip.Get(HttpContext));

                if (isSuccess)
                {
                    BaseCache.Set <Dictionary <string, object> >(App.Cache.UserInfo, info);
                    return(Json(new { success = isSuccess, url = "/home/index" }));
                }
                else
                {
                    return(Json(new { success = isSuccess, msg = "密码不正确" }));
                }
            }
        }
        /// <summary>
        /// 初始化map 3
        /// </summary>
        /// <returns></returns>
        private void InstanceMap(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json")
        {
            var list   = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile);
            var config = DataConfig.Get(dbKey, null, dbFile);
            var db     = new DataContext(dbKey);
            var query  = new DataQuery {
                Config = config, Key = dbKey
            };

            list.Path.ForEach(p => {
                var info = new FileInfo(p);
                var key  = BaseSymmetric.Generate(info.FullName);

                if (!DbCache.Exists(config.CacheType, key))
                {
                    var temp       = new MapXmlModel();
                    temp.LastWrite = info.LastWriteTime;
                    temp.FileKey   = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""));
                    temp.FileName  = info.FullName;
                    if (MapXml.SaveXml(dbKey, key, info, config, db))
                    {
                        DbCache.Set <MapXmlModel>(config.CacheType, key, temp);
                    }
                }
                else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0)
                {
                    DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(a => { DbCache.Remove(config.CacheType, a); });

                    var model       = new MapXmlModel();
                    model.LastWrite = info.LastWriteTime;
                    model.FileKey   = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""));
                    model.FileName  = info.FullName;
                    if (MapXml.SaveXml(dbKey, key, info, config, db))
                    {
                        DbCache.Set <MapXmlModel>(config.CacheType, key, model);
                    }
                }
            });

            if (config.IsMapSave)
            {
                query.Config.DesignModel = FastData.Core.Base.Config.CodeFirst;
                if (query.Config.DbType == DataDbType.Oracle)
                {
                    var listInfo      = typeof(FastData.Core.DataModel.Oracle.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList();
                    var listAttribute = typeof(FastData.Core.DataModel.Oracle.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList();
                    BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute);
                }

                if (query.Config.DbType == DataDbType.MySql)
                {
                    var listInfo      = typeof(FastData.Core.DataModel.MySql.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList();
                    var listAttribute = typeof(FastData.Core.DataModel.MySql.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList();
                    BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute);
                }

                if (query.Config.DbType == DataDbType.SqlServer)
                {
                    var listInfo      = typeof(FastData.Core.DataModel.SqlServer.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList();
                    var listAttribute = typeof(FastData.Core.DataModel.SqlServer.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList();
                    BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute);
                }
            }

            db.Dispose();
        }
Beispiel #4
0
        public static void InstanceMapResource(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json")
        {
            var projectName = Assembly.GetCallingAssembly().GetName().Name;
            var config      = DataConfig.Get(dbKey, projectName, dbFile);
            var db          = new DataContext(dbKey);
            var assembly    = Assembly.Load(projectName);
            var map         = new MapConfigModel();

            using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, mapFile)))
            {
                if (resource != null)
                {
                    using (var reader = new StreamReader(resource))
                    {
                        var content = reader.ReadToEnd();
                        map.Path = BaseJson.JsonToModel <List <string> >(BaseJson.JsonToDic(BaseJson.ModelToJson(BaseJson.JsonToDic(content).GetValue(AppSettingKey.Map))).GetValue("Path").ToStr());
                    }
                }
                else
                {
                    map = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile);
                }
            }

            if (map.Path == null)
            {
                return;
            }

            map.Path.ForEach(a =>
            {
                using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, a.Replace("/", "."))))
                {
                    var xml = "";
                    if (resource != null)
                    {
                        using (var reader = new StreamReader(resource))
                        {
                            xml = reader.ReadToEnd();
                        }
                    }
                    var info = new FileInfo(a);
                    var key  = BaseSymmetric.Generate(info.FullName);
                    if (!DbCache.Exists(config.CacheType, key))
                    {
                        var temp       = new MapXmlModel();
                        temp.LastWrite = info.LastWriteTime;
                        temp.FileKey   = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml);
                        temp.FileName  = info.FullName;
                        if (MapXml.SaveXml(dbKey, key, info, config, db))
                        {
                            DbCache.Set <MapXmlModel>(config.CacheType, key, temp);
                        }
                    }
                    else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0)
                    {
                        DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(f => { DbCache.Remove(config.CacheType, f); });

                        var model       = new MapXmlModel();
                        model.LastWrite = info.LastWriteTime;
                        model.FileKey   = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml);
                        model.FileName  = info.FullName;
                        if (MapXml.SaveXml(dbKey, key, info, config, db))
                        {
                            DbCache.Set <MapXmlModel>(config.CacheType, key, model);
                        }
                    }
                }
            });
        }