Exemple #1
0
        public SharedResultVM DatabaseExport(string zipName = "db/backup.zip")
        {
            return(SharedResultVM.Try(vm =>
            {
                //是否覆盖备份,默认不覆盖,避免线上重置功能被破坏
                var CoverBack = true;

                if (CoverBack)
                {
                    var edb = new SharedDataKit.TransferVM.ExportDatabase
                    {
                        ZipPath = PathTo.Combine(GlobalTo.ContentRootPath, zipName),
                        ReadConnectionInfo = new SharedDataKit.TransferVM.ConnectionInfo()
                        {
                            ConnectionString = SharedDbContext.FactoryTo.GetConn().Replace("Filename=", "Data Source="),
                            ConnectionType = GlobalTo.TDB
                        }
                    };

                    vm = SharedDataKit.DataKit.ExportDatabase(edb);
                }
                else
                {
                    vm.Set(SharedEnum.RTag.refuse);
                    vm.Msg = "已被限制导出覆盖";
                }

                return vm;
            }));
        }
Exemple #2
0
        public SharedResultVM UpdateUserPhoto(string type, string source)
        {
            var vm = new SharedResultVM();

            try
            {
                vm = Apps.LoginService.CompleteInfoValid(HttpContext);
                if (vm.Code == 200)
                {
                    var uinfo = Apps.LoginService.Get(HttpContext);

                    //物理根路径
                    var prp   = GlobalTo.GetValue("StaticResource:PhysicalRootPath").Replace("~", GlobalTo.ContentRootPath);
                    var ppath = PathTo.Combine(prp, GlobalTo.GetValue("StaticResource:AvatarPath"));

                    if (!Directory.Exists(ppath))
                    {
                        Directory.CreateDirectory(ppath);
                    }

                    if (string.IsNullOrWhiteSpace(uinfo.UserPhoto))
                    {
                        uinfo.UserPhoto = UniqueTo.LongId() + ".jpg";
                    }
                    var upname = uinfo.UserPhoto.Split('?')[0];
                    var npnew  = upname + "?" + DateTime.Now.ToTimestamp();

                    switch (type)
                    {
                    case "file":
                    {
                        source = source[(source.LastIndexOf(",") + 1)..];
Exemple #3
0
        public SharedResultVM DatabaseReset(string zipName = "db/backup.zip")
        {
            return(SharedResultVM.Try(vm =>
            {
                if (HttpContext != null && new UserAgentTo(new ClientTo(HttpContext).UserAgent).IsBot)
                {
                    vm.Set(SharedEnum.RTag.refuse);
                    vm.Msg = "are you human?";
                }
                else
                {
                    var idb = new SharedDataKit.TransferVM.ImportDatabase
                    {
                        WriteConnectionInfo = new SharedDataKit.TransferVM.ConnectionInfo
                        {
                            ConnectionType = GlobalTo.TDB,
                            ConnectionString = SharedDbContext.FactoryTo.GetConn().Replace("Filename=", "Data Source=")
                        },
                        ZipPath = PathTo.Combine(GlobalTo.ContentRootPath, zipName),
                        WriteDeleteData = true
                    };

                    vm = SharedDataKit.DataKit.ImportDatabase(idb);
                }

                return vm;
            }));
        }
Exemple #4
0
        public SharedResultVM ClearTmp()
        {
            return(SharedResultVM.Try(vm =>
            {
                string directoryPath = PathTo.Combine(GlobalTo.WebRootPath, GlobalTo.GetValue("StaticResource:TmpDir"));

                vm.Log.Add($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 清理临时目录:{directoryPath}");

                if (!Directory.Exists(directoryPath))
                {
                    vm.Set(SharedEnum.RTag.lack);
                    vm.Msg = "文件路径不存在";
                }
                else
                {
                    int delFileCount = 0;
                    int delFolderCount = 0;

                    //删除文件
                    var listFile = Directory.GetFiles(directoryPath).ToList();
                    foreach (var path in listFile)
                    {
                        if (!path.Contains("README"))
                        {
                            try
                            {
                                System.IO.File.Delete(path);
                                delFileCount++;
                            }
                            catch (Exception ex)
                            {
                                vm.Log.Add($"删除文件异常:{ex.Message}");
                            }
                        }
                    }

                    //删除文件夹
                    var listFolder = Directory.GetDirectories(directoryPath).ToList();
                    foreach (var path in listFolder)
                    {
                        try
                        {
                            Directory.Delete(path, true);
                            delFolderCount++;
                        }
                        catch (Exception ex)
                        {
                            vm.Log.Add($"删除文件夹异常:{ex.Message}");
                        }
                    }

                    vm.Log.Insert(0, $"删除文件{delFileCount}个,删除{delFolderCount}个文件夹");
                    vm.Set(SharedEnum.RTag.success);
                }

                return vm;
            }));
        }
Exemple #5
0
        public Startup(IConfiguration configuration, IHostEnvironment env)
        {
            GlobalTo.Configuration   = configuration;
            GlobalTo.HostEnvironment = env;

            SharedReady.ReadyTo.EncodingReg();
            SharedReady.ReadyTo.LegacyTimestamp();

            //结巴词典路径
            var jbPath = PathTo.Combine(GlobalTo.ContentRootPath, "db/jieba");

            if (!Directory.Exists(jbPath))
            {
                Directory.CreateDirectory(jbPath);
                try
                {
                    var dhost = "https://raw.githubusercontent.com/anderscui/jieba.NET/master/src/Segmenter/Resources/";
                    "prob_trans.json,prob_emit.json,idf.txt,pos_prob_start.json,pos_prob_trans.json,pos_prob_emit.json,char_state_tab.json".Split(',').ToList().ForEach(file =>
                    {
                        var fullPath = PathTo.Combine(jbPath, file);
                        HttpTo.DownloadSave(HttpTo.HWRequest(dhost + file), fullPath);
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            JiebaNet.Segmenter.ConfigManager.ConfigFileBaseDir = jbPath;

            #region 第三方登录
            new List <Type>
            {
                typeof(QQConfig),
                typeof(WeChatConfig),
                typeof(WeiboConfig),
                typeof(GitHubConfig),
                typeof(GiteeConfig),
                typeof(TaoBaoConfig),
                typeof(MicroSoftConfig),
                typeof(DingTalkConfig),
                typeof(GoogleConfig),
                typeof(AliPayConfig),
                typeof(StackOverflowConfig)
            }.ForEach(lc =>
            {
                var fields = lc.GetFields();
                foreach (var field in fields)
                {
                    if (!field.Name.StartsWith("API_"))
                    {
                        var cv = GlobalTo.GetValue($"OAuthLogin:{lc.Name.Replace("Config", "")}:{field.Name}");
                        field.SetValue(lc, cv);
                    }
                }
            });
            #endregion
        }
Exemple #6
0
        public SharedResultVM DatabaseExport(string zipName = "db/backup.zip")
        {
            return(SharedResultVM.Try(vm =>
            {
                var edb = new SharedDataKit.TransferVM.ExportDatabase
                {
                    ZipPath = PathTo.Combine(GlobalTo.ContentRootPath, zipName),
                    ReadConnectionInfo = new SharedDataKit.TransferVM.ConnectionInfo()
                    {
                        ConnectionString = SharedDbContext.FactoryTo.GetConn().Replace("Filename=", "Data Source="),
                        ConnectionType = GlobalTo.TDB
                    }
                };

                vm = SharedDataKit.DataKit.ExportDatabase(edb);

                return vm;
            }));
        }
Exemple #7
0
        public SharedResultVM DatabaseImport(string zipName = "db/backup.zip", bool clearTable = false)
        {
            return(SharedResultVM.Try(vm =>
            {
                var idb = new SharedDataKit.TransferVM.ImportDatabase
                {
                    WriteConnectionInfo = new SharedDataKit.TransferVM.ConnectionInfo
                    {
                        ConnectionType = GlobalTo.TDB,
                        ConnectionString = SharedDbContext.FactoryTo.GetConn().Replace("Filename=", "Data Source=")
                    },
                    ZipPath = PathTo.Combine(GlobalTo.ContentRootPath, zipName),
                    WriteDeleteData = clearTable
                };

                vm = SharedDataKit.DataKit.ImportDatabase(idb);

                return vm;
            }));
        }
Exemple #8
0
        public SharedResultVM Export(QueryDataInputVM ivm, string title = "export")
        {
            var vm = new SharedResultVM();

            //虚拟路径
            string vpath = GlobalTo.GetValue("StaticResource:TmpDir");
            //物理路径
            var ppath = PathTo.Combine(GlobalTo.WebRootPath, vpath);

            if (!Directory.Exists(ppath))
            {
                Directory.CreateDirectory(ppath);
            }

            //文件名
            string filename = $"{title.Replace(" ", "").Trim()}_{DateTime.Now:yyyyMMdd_HHmmss}.xlsx";

            //导出的表数据
            var dtReport = new DataTable();

            try
            {
                switch (ivm.TableName?.ToLower())
                {
                default:
                    vm.Set(SharedEnum.RTag.invalid);
                    break;

                //角色
                case "sysrole":
                {
                    using var ctl = new SettingController(db);
                    dtReport      = ExportService.ModelsMapping(ivm, ctl.QuerySysRole(ivm));
                }
                break;

                //用户
                case "sysuser":
                {
                    using var ctl = new SettingController(db);
                    dtReport      = ExportService.ModelsMapping(ivm, ctl.QuerySysUser(ivm));
                }
                break;

                //日志
                case "syslog":
                {
                    using var ctl = new SettingController(db);
                    dtReport      = ExportService.ModelsMapping(ivm, ctl.QuerySysLog(ivm));
                }
                break;

                //字典
                case "sysdictionary":
                {
                    using var ctl = new SettingController(db);
                    dtReport      = ExportService.ModelsMapping(ivm, ctl.QuerySysDictionary(ivm));
                }
                break;
                }

                Console.WriteLine($"Export table rows : {dtReport.Rows.Count}");
                if (vm.Msg != SharedEnum.RTag.invalid.ToString())
                {
                    //生成
                    if (NpoiTo.DataTableToExcel(dtReport, PathTo.Combine(ppath, filename)))
                    {
                        vm.Data = PathTo.Combine(vpath, filename);

                        //生成的Excel继续操作
                        ExportService.ExcelDraw(PathTo.Combine(ppath, filename), ivm);

                        vm.Set(SharedEnum.RTag.success);
                    }
                    else
                    {
                        vm.Set(SharedEnum.RTag.fail);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
Exemple #9
0
        public async Task <SharedResultVM> Upload(IFormFileCollection files, int?temp, string subdir)
        {
            var vm = new SharedResultVM();

            try
            {
                if (files.Count > 0)
                {
                    var now = DateTime.Now;

                    //虚拟路径
                    var vpath = GlobalTo.GetValue("StaticResource:RootDir");
                    if (temp == 1)
                    {
                        vpath = GlobalTo.GetValue("StaticResource:TmpDir");
                    }
                    else
                    {
                        vpath = PathTo.Combine(vpath, subdir, now.ToString("yyyy'/'MM'/'dd"));
                    }

                    //物理路径
                    var ppath = PathTo.Combine(GlobalTo.WebRootPath, vpath);
                    if (!Directory.Exists(ppath))
                    {
                        Directory.CreateDirectory(ppath);
                    }

                    var listPath = new List <string>();
                    for (int i = 0; i < files.Count; i++)
                    {
                        var file     = files[i];
                        var ext      = Path.GetExtension(file.FileName);
                        var filename = now.ToString("HHmmss") + RandomTo.NumCode() + ext;

                        using (var stream = new FileStream(PathTo.Combine(ppath, filename), FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }

                        listPath.Add(PathTo.Combine(vpath, filename));
                    }

                    if (listPath.Count == 1)
                    {
                        vm.Data = listPath.FirstOrDefault();
                    }
                    else
                    {
                        vm.Data = listPath;
                    }
                    vm.Set(SharedEnum.RTag.success);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
Exemple #10
0
        private static SharedResultVM UploadCheck(IFormFile file, byte[] content, string ext, string subdir)
        {
            var vm = new SharedResultVM();

            if (file != null)
            {
                ext = Path.GetExtension(file.FileName);
            }

            if (string.IsNullOrWhiteSpace(ext) || !ext.Contains('.') || ext.EndsWith("exe"))
            {
                vm.Set(SharedEnum.RTag.refuse);
                vm.Msg = "Invalid extension";
            }
            else
            {
                var    now      = DateTime.Now;
                string filename = now.ToString("HHmmss") + RandomTo.NumCode() + ext;

                if (!string.IsNullOrWhiteSpace(subdir) && !ParsingTo.IsLinkPath(subdir))
                {
                    vm.Set(SharedEnum.RTag.invalid);
                    vm.Msg = "subdir 仅为字母、数字";
                }
                else
                {
                    //虚拟路径
                    var vpath = PathTo.Combine(subdir, now.ToString("yyyy'/'MM'/'dd"));
                    //物理根路径
                    var prp = GlobalTo.GetValue("StaticResource:PhysicalRootPath").Replace("~", GlobalTo.ContentRootPath);
                    //物理路径
                    var ppath = PathTo.Combine(prp, vpath);
                    //创建物理目录
                    if (!Directory.Exists(ppath))
                    {
                        Directory.CreateDirectory(ppath);
                    }

                    using var fs = new FileStream(PathTo.Combine(ppath, filename), FileMode.CreateNew);
                    if (file != null)
                    {
                        file.CopyTo(fs);
                    }
                    else
                    {
                        fs.Write(content, 0, content.Length);
                    }
                    fs.Flush();
                    fs.Close();

                    //输出
                    vm.Data = new
                    {
                        server = GlobalTo.GetValue("StaticResource:Server"),
                        path   = PathTo.Combine(vpath, filename)
                    };
                    vm.Set(SharedEnum.RTag.success);
                }
            }

            return(vm);
        }
Exemple #11
0
        /// <summary>
        /// 登录授权回调
        /// </summary>
        /// <param name="authorizeResult">获取授权码以及防伪标识</param>
        /// <returns></returns>
        public IActionResult AuthCallback(LoginBase.AuthorizeResult authorizeResult)
        {
            var vm = new SharedResultVM();

            try
            {
                if (string.IsNullOrWhiteSpace(authorizeResult.code))
                {
                    vm.Set(SharedEnum.RTag.unauthorized);
                }
                else
                {
                    //唯一标示
                    string openId = string.Empty;
                    //注册信息
                    var mo = new Domain.UserInfo()
                    {
                        LoginLimit     = 0,
                        UserSex        = 0,
                        UserCreateTime = DateTime.Now
                    };
                    //头像
                    string avatar = string.Empty;

                    Enum.TryParse(RouteData.Values["id"]?.ToString(), true, out LoginBase.LoginType vtype);

                    switch (vtype)
                    {
                    case LoginBase.LoginType.QQ:
                    {
                        //获取 access_token
                        var tokenEntity = QQ.AccessToken(new QQ_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //获取 OpendId
                        var openidEntity = QQ.OpenId(tokenEntity.access_token);
                        Console.WriteLine(openidEntity.ToJson());

                        //获取 UserInfo
                        var userEntity = QQ.OpenId_Get_User_Info(new QQ_OpenAPI_RequestEntity()
                            {
                                access_token = tokenEntity.access_token,
                                openid       = openidEntity.openid
                            });
                        Console.WriteLine(userEntity.ToJson());

                        //身份唯一标识
                        openId     = openidEntity.openid;
                        mo.OpenId1 = openId;

                        mo.Nickname = userEntity.nickname;
                        mo.UserSex  = userEntity.gender == "男" ? 1 : 2;
                        mo.UserSay  = "";
                        mo.UserUrl  = "";

                        avatar = userEntity.figureurl_2;
                    }
                    break;

                    case LoginBase.LoginType.WeiBo:
                    {
                        //获取 access_token
                        var tokenEntity = Weibo.AccessToken(new Weibo_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //获取 access_token 的授权信息
                        var tokenInfoEntity = Weibo.GetTokenInfo(tokenEntity.access_token);
                        Console.WriteLine(tokenInfoEntity.ToJson());

                        //获取 users/show
                        var userEntity = Weibo.UserShow(new Weibo_UserShow_RequestEntity()
                            {
                                access_token = tokenEntity.access_token,
                                uid          = Convert.ToInt64(tokenInfoEntity.uid)
                            });
                        Console.WriteLine(userEntity.ToJson());

                        openId     = tokenEntity.access_token;
                        mo.OpenId2 = openId;

                        mo.Nickname = userEntity.screen_name;
                        mo.UserSex  = userEntity.gender == "m" ? 1 : userEntity.gender == "f" ? 2 : 0;
                        mo.UserSay  = userEntity.description;
                        mo.UserUrl  = userEntity.domain;

                        avatar = userEntity.avatar_large;
                    }
                    break;

                    case LoginBase.LoginType.WeChat:
                    {
                        //获取 access_token
                        var tokenEntity = Netnr.Login.WeChat.AccessToken(new WeChat_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //openId = tokenEntity.openid;

                        //获取 user
                        var userEntity = Netnr.Login.WeChat.Get_User_Info(new WeChat_OpenAPI_RequestEntity()
                            {
                                access_token = tokenEntity.access_token,
                                openid       = tokenEntity.openid
                            });
                        Console.WriteLine(userEntity.ToJson());

                        avatar = userEntity.headimgurl;
                    }
                    break;

                    case LoginBase.LoginType.GitHub:
                    {
                        //获取 access_token
                        var tokenEntity = GitHub.AccessToken(new GitHub_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //获取 user
                        var userEntity = GitHub.User(tokenEntity.access_token);
                        Console.WriteLine(userEntity.ToJson());

                        openId     = userEntity.id.ToString();
                        mo.OpenId3 = openId;

                        mo.Nickname = userEntity.name;
                        mo.UserSay  = userEntity.bio;
                        mo.UserUrl  = userEntity.blog;
                        mo.UserMail = userEntity.email;

                        avatar = userEntity.avatar_url;
                    }
                    break;

                    case LoginBase.LoginType.Gitee:
                    {
                        //获取 access_token
                        var tokenEntity = Gitee.AccessToken(new Gitee_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //获取 user
                        var userEntity = Gitee.User(tokenEntity.access_token);
                        Console.WriteLine(userEntity.ToJson());

                        //openId = userEntity.id.ToString();

                        mo.Nickname = userEntity.name;
                        mo.UserSay  = userEntity.bio;
                        mo.UserUrl  = userEntity.blog;

                        avatar = userEntity.avatar_url;
                    }
                    break;

                    case LoginBase.LoginType.TaoBao:
                    {
                        //获取 access_token
                        var tokenEntity = TaoBao.AccessToken(new TaoBao_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        openId     = tokenEntity.open_uid;
                        mo.OpenId4 = openId;

                        mo.Nickname = "淘宝用户";
                    }
                    break;

                    case LoginBase.LoginType.MicroSoft:
                    {
                        //获取 access_token
                        var tokenEntity = MicroSoft.AccessToken(new MicroSoft_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //获取 user
                        var userEntity = MicroSoft.User(tokenEntity.access_token);
                        Console.WriteLine(userEntity.ToJson());

                        openId     = userEntity.id;
                        mo.OpenId5 = openId;

                        mo.Nickname = userEntity.last_name + userEntity.first_name;
                        mo.UserMail = userEntity.emails?["account"].ToStringOrEmpty();
                    }
                    break;

                    case LoginBase.LoginType.DingTalk:
                    {
                        //获取 user
                        var userEntity = DingTalk.User(new DingTalk_User_RequestEntity(), authorizeResult.code);
                        Console.WriteLine(userEntity.ToJson());

                        openId     = userEntity.openid;
                        mo.OpenId6 = openId;

                        mo.Nickname = userEntity.nick;
                    }
                    break;

                    case LoginBase.LoginType.Google:
                    {
                        //获取 access_token
                        var tokenEntity = Google.AccessToken(new Google_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //获取 user
                        var userEntity = Google.User(tokenEntity.access_token);
                        Console.WriteLine(userEntity.ToJson());

                        //openId = userEntity.sub;

                        avatar = userEntity.picture;
                    }
                    break;

                    case LoginBase.LoginType.AliPay:
                    {
                        //获取 access_token
                        var tokenEntity = AliPay.AccessToken(new AliPay_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //openId = tokenEntity.user_id;

                        //获取 user
                        var userEntity = AliPay.User(new AliPay_User_RequestEntity()
                            {
                                auth_token = tokenEntity.access_token
                            });
                        Console.WriteLine(userEntity.ToJson());

                        avatar = userEntity.avatar;
                    }
                    break;

                    case LoginBase.LoginType.StackOverflow:
                    {
                        //获取 access_token
                        var tokenEntity = StackOverflow.AccessToken(new StackOverflow_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });
                        Console.WriteLine(tokenEntity.ToJson());

                        //获取 user
                        var userEntity = StackOverflow.User(new StackOverflow_User_RequestEntity()
                            {
                                access_token = tokenEntity.access_token
                            });
                        Console.WriteLine(userEntity.ToJson());

                        //openId= userEntity.user_id;

                        avatar = userEntity.profile_image;
                    }
                    break;
                    }

                    mo.UserCreateTime = DateTime.Now;
                    mo.UserName       = openId;
                    mo.UserPwd        = CalcTo.MD5(openId);
                    if (!string.IsNullOrWhiteSpace(avatar))
                    {
                        mo.UserPhoto = UniqueTo.LongId().ToString() + ".jpg";
                    }
                    Console.WriteLine(mo.ToJson());

                    if (string.IsNullOrWhiteSpace(openId))
                    {
                        vm.Set(SharedEnum.RTag.unauthorized);
                        vm.Msg = "身份验证失败";
                    }
                    else
                    {
                        //判断是绑定操作
                        bool isbind = User.Identity.IsAuthenticated && authorizeResult.state.StartsWith("bind");
                        if (isbind)
                        {
                            int uid = Apps.LoginService.Get(HttpContext).UserId;

                            //检测是否绑定其它账号
                            var queryIsBind = db.UserInfo.Where(x => x.UserId != uid);
                            switch (vtype)
                            {
                            case LoginBase.LoginType.QQ:
                                queryIsBind = queryIsBind.Where(x => x.OpenId1 == openId);
                                break;

                            case LoginBase.LoginType.WeiBo:
                                queryIsBind = queryIsBind.Where(x => x.OpenId2 == openId);
                                break;

                            case LoginBase.LoginType.GitHub:
                                queryIsBind = queryIsBind.Where(x => x.OpenId3 == openId);
                                break;

                            case LoginBase.LoginType.TaoBao:
                                queryIsBind = queryIsBind.Where(x => x.OpenId4 == openId);
                                break;

                            case LoginBase.LoginType.MicroSoft:
                                queryIsBind = queryIsBind.Where(x => x.OpenId5 == openId);
                                break;

                            case LoginBase.LoginType.DingTalk:
                                queryIsBind = queryIsBind.Where(x => x.OpenId6 == openId);
                                break;
                            }
                            if (queryIsBind.Any())
                            {
                                return(Content("已绑定其它账号,不能重复绑定"));
                            }

                            var userInfo = db.UserInfo.Find(uid);

                            switch (vtype)
                            {
                            case LoginBase.LoginType.QQ:
                                userInfo.OpenId1 = openId;
                                break;

                            case LoginBase.LoginType.WeiBo:
                                userInfo.OpenId2 = openId;
                                break;

                            case LoginBase.LoginType.GitHub:
                                userInfo.OpenId3 = openId;
                                break;

                            case LoginBase.LoginType.TaoBao:
                                userInfo.OpenId4 = openId;
                                break;

                            case LoginBase.LoginType.MicroSoft:
                                userInfo.OpenId5 = openId;
                                break;

                            case LoginBase.LoginType.DingTalk:
                                userInfo.OpenId6 = openId;
                                break;
                            }
                            db.UserInfo.Update(userInfo);
                            db.SaveChanges();

                            return(Redirect("/user/setting"));
                        }
                        else
                        {
                            Domain.UserInfo vmo = null;
                            switch (vtype)
                            {
                            case LoginBase.LoginType.QQ:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId1 == openId);
                                break;

                            case LoginBase.LoginType.WeiBo:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId2 == openId);
                                break;

                            case LoginBase.LoginType.GitHub:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId3 == openId);
                                break;

                            case LoginBase.LoginType.TaoBao:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId4 == openId);
                                break;

                            case LoginBase.LoginType.MicroSoft:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId5 == openId);
                                break;

                            case LoginBase.LoginType.DingTalk:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId6 == openId);
                                break;
                            }
                            //未注册
                            if (vmo == null)
                            {
                                var ruvm = RegisterUser(mo);
                                if (ruvm.Code == 200)
                                {
                                    vm = ValidateLogin(vtype, mo);
                                    //拉取头像
                                    if (vm.Code == 200 && !string.IsNullOrWhiteSpace(avatar))
                                    {
                                        try
                                        {
                                            //物理根路径
                                            var prp   = GlobalTo.GetValue("StaticResource:PhysicalRootPath").Replace("~", GlobalTo.ContentRootPath);
                                            var ppath = PathTo.Combine(prp, GlobalTo.GetValue("StaticResource:AvatarPath"));

                                            if (!Directory.Exists(ppath))
                                            {
                                                Directory.CreateDirectory(ppath);
                                            }

                                            HttpTo.DownloadSave(HttpTo.HWRequest(avatar), PathTo.Combine(ppath, mo.UserPhoto));
                                        }
                                        catch (Exception ex)
                                        {
                                            Console.WriteLine(ex);
                                        }
                                    }
                                }
                                else
                                {
                                    vm.Msg = ruvm.Msg;
                                }
                            }
                            else
                            {
                                vm = ValidateLogin(vtype, vmo);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Apps.FilterConfigs.WriteLog(HttpContext, ex);
                Response.Headers["X-Output-Msg"] = ex.ToJson();
                vm.Set(ex);
            }

            //成功
            if (vm.Code == 200)
            {
                var rurl = Request.Cookies["ReturnUrl"];
                rurl = string.IsNullOrWhiteSpace(rurl) ? "/" : rurl;

                if (rurl.StartsWith("http"))
                {
                    rurl += "?cookie=ok";
                }

                return(Redirect(rurl));
            }
            else
            {
                return(Redirect("/home/error"));
            }
        }
Exemple #12
0
        public SharedResultVM DatabaseExportDemo()
        {
            var vm = new SharedResultVM();

            try
            {
                var export_before = "db/backup_demo_before.zip";
                var export_demo   = "db/backup_demo.zip";

                //备份
                if (DatabaseExport(export_before).Code == 200)
                {
                    //清理仅保留示例数据

                    using var db = ContextBaseFactory.CreateDbContext();

                    db.UserInfo.RemoveRange(db.UserInfo.ToList());
                    db.UserInfo.Add(new Domain.UserInfo()
                    {
                        UserId         = 1,
                        UserName       = "******",
                        UserPwd        = "e10adc3949ba59abbe56e057f20f883e",//123456
                        UserCreateTime = DateTime.Now
                    });

                    db.UserConnection.RemoveRange(db.UserConnection.ToList());
                    db.UserMessage.RemoveRange(db.UserMessage.ToList());
                    db.UserReply.RemoveRange(db.UserReply.Where(x => x.UrTargetId != "117").ToList());
                    db.UserWriting.RemoveRange(db.UserWriting.Where(x => x.UwId != 117).ToList());
                    db.UserWritingTags.RemoveRange(db.UserWritingTags.Where(x => x.UwId != 117).ToList());

                    db.Tags.RemoveRange(db.Tags.Where(x => x.TagId != 58 && x.TagId != 96).ToList());

                    db.Run.RemoveRange(db.Run.OrderBy(x => x.RunCreateTime).Skip(1).ToList());

                    db.OperationRecord.RemoveRange(db.OperationRecord.ToList());

                    db.Notepad.RemoveRange(db.Notepad.ToList());

                    db.KeyValues.RemoveRange(db.KeyValues.Where(x => x.KeyName != "https" && x.KeyName != "browser").ToList());
                    db.KeyValueSynonym.RemoveRange(db.KeyValueSynonym.ToList());

                    db.GuffRecord.RemoveRange(db.GuffRecord.ToList());

                    db.Gist.RemoveRange(db.Gist.Where(x => x.GistCode != "5373307231488995367").ToList());
                    db.GistSync.RemoveRange(db.GistSync.Where(x => x.GistCode != "5373307231488995367").ToList());

                    db.GiftRecord.RemoveRange(db.GiftRecord.ToList());
                    db.GiftRecordDetail.RemoveRange(db.GiftRecordDetail.ToList());

                    db.Draw.RemoveRange(db.Draw.Where(x => x.DrId != "d4969500168496794720" && x.DrId != "m4976065893797151245").ToList());

                    db.DocSet.RemoveRange(db.DocSet.Where(x => x.DsCode != "4840050256984581805" && x.DsCode != "5036967707833574483").ToList());
                    db.DocSetDetail.RemoveRange(db.DocSetDetail.Where(x => x.DsCode != "4840050256984581805" && x.DsCode != "5036967707833574483").ToList());

                    var num = db.SaveChanges();

                    //导出示例数据
                    vm = DatabaseExport(export_demo);

                    //导入恢复
                    if (DatabaseImport(export_before, true).Code == 200)
                    {
                        var fullPath = PathTo.Combine(GlobalTo.ContentRootPath, "db", export_before);
                        System.IO.File.Delete(fullPath);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
Exemple #13
0
        public SharedResultVM DatabaseBackupToGit()
        {
            return(SharedResultVM.Try(vm =>
            {
                if (GlobalTo.GetValue <bool>("ReadOnly"))
                {
                    vm.Set(SharedEnum.RTag.refuse);
                    return vm;
                }

                var now = $"{DateTime.Now:yyyyMMdd_HHmmss}";

                var db = ContextBaseFactory.CreateDbContext();
                var database = db.Database.GetDbConnection().Database;

                var createScript = db.Database.GenerateCreateScript();

                //备份创建脚本
                try
                {
                    var b1 = Convert.ToBase64String(Encoding.UTF8.GetBytes(createScript));
                    var p1 = $"{database}/backup_{now}.sql";

                    vm.Log.Add(PutGitee(b1, p1, now));
                    vm.Log.Add(PutGitHub(b1, p1, now));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    vm.Log.Add(ex.Message);
                }

                Thread.Sleep(1000 * 1);

                //备份数据
                var zipPath = $"db/backup_{now}.zip";
                if (DatabaseExport(zipPath).Code == 200)
                {
                    var ppath = PathTo.Combine(GlobalTo.ContentRootPath, zipPath);

                    try
                    {
                        var b2 = Convert.ToBase64String(System.IO.File.ReadAllBytes(ppath));
                        var p2 = $"{database}/backup_{now}.zip";

                        vm.Log.Add(PutGitee(b2, p2, now));
                        vm.Log.Add(PutGitHub(b2, p2, now));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        vm.Log.Add(ex.Message);

                        System.IO.File.Delete(ppath);
                    }
                    finally
                    {
                        System.IO.File.Delete(ppath);
                    }
                }

                return vm;
            }));
        }