Ejemplo n.º 1
0
            void IJob.Execute()
            {
                var vm = new Controllers.ServicesController().HandleOperationRecord();

                ConsoleTo.Log(vm.ToJson(true));
                Console.WriteLine(vm);
            }
Ejemplo n.º 2
0
            void IJob.Execute()
            {
                var vm = new Controllers.ServicesController().ClearTmp();

                Console.WriteLine(vm.ToJson(true));
                ConsoleTo.Log(vm);
            }
Ejemplo n.º 3
0
            void IJob.Execute()
            {
                var vm = new Controllers.ServicesController().DatabaseReset();

                Console.WriteLine(vm.ToJson(true));
                ConsoleTo.Log(vm);
            }
Ejemplo n.º 4
0
        /// <summary>
        /// WebHook
        /// </summary>
        /// <returns></returns>
        public ActionResultVM WebHook()
        {
            var vm = new ActionResultVM();

            try
            {
                if (Request.Method == "POST")
                {
                    using var ms = new MemoryStream();
                    Request.Body.CopyTo(ms);
                    string postStr = System.Text.Encoding.UTF8.GetString(ms.ToArray());

                    //new WebHookService(postStr);

                    vm.data = postStr;
                    vm.Set(ARTag.success);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 5
0
        public ActionResultVM UserInfo()
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(HttpContext).Get();
                if (uinfo.UserId != 0)
                {
                    vm.data = uinfo;

                    vm.Set(ARTag.success);
                }
                else
                {
                    vm.Set(ARTag.unauthorized);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 6
0
        public ActionResultVM CreateApp(string password)
        {
            var vm = new ActionResultVM();

            try
            {
                if (GlobalTo.GetValue <bool>("Safe:IsDev"))
                {
                    if (!string.IsNullOrWhiteSpace(password) && password == GlobalTo.GetValue("Safe:CreateAppPassword"))
                    {
                        vm = SQLiteBase.CreateApp();
                    }
                    else
                    {
                        vm.Set(ARTag.unauthorized);
                        vm.msg = "密码错误";
                    }
                }
                else
                {
                    vm.Set(ARTag.refuse);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 7
0
        public SharedResultVM AboutServerStatus()
        {
            var vm = new SharedResultVM();

            try
            {
                var ckss = "Global_SystemStatus";
                if (CacheTo.Get(ckss) is not SystemStatusTo ss)
                {
                    ss = new SystemStatusTo();
                    CacheTo.Set(ckss, ss, 10, false);
                }

                vm.Log.Add(ss);
                vm.Data = ss.ToView();
                vm.Set(SharedEnum.RTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 8
0
        public ActionResultVM Delete(string id)
        {
            var vm = new ActionResultVM();

            try
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else
                {
                    var uinfo = new UserAuthAid(HttpContext).Get();
                    if (uinfo.UserId != 0)
                    {
                        using var db = new ContextBase();
                        var mo = db.GuffRecord.Find(id);

                        if (mo == null)
                        {
                            vm.Set(ARTag.invalid);
                        }
                        else
                        {
                            if (mo.Uid != uinfo.UserId)
                            {
                                vm.Set(ARTag.unauthorized);
                            }
                            else if (mo.GrStatus == -1)
                            {
                                vm.Set(ARTag.refuse);
                            }
                            else
                            {
                                db.Remove(mo);
                                int num = db.SaveChanges();

                                vm.Set(num > 0);
                            }
                        }
                    }
                    else
                    {
                        vm.Set(ARTag.unauthorized);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 9
0
        public ActionResultVM List(string category, string q, int uid, string nv, string tag, string obj, int page = 1)
        {
            var vm = new ActionResultVM();

            try
            {
                //所属用户
                var OwnerId = 0;

                if (uid != 0)
                {
                    OwnerId = uid;
                }

                var uinfo = new UserAuthAid(HttpContext).Get();

                if (new List <string> {
                    "me", "melaud", "mereply"
                }.Contains(category))
                {
                    if (uinfo.UserId == 0)
                    {
                        vm.Set(ARTag.unauthorized);
                    }
                    else
                    {
                        if (category == "me")
                        {
                            OwnerId = uinfo.UserId;
                        }

                        var pvm = Func.Common.GuffQuery(category, q, nv, tag, obj, OwnerId, uinfo.UserId, page);
                        vm.data = pvm;

                        vm.Set(ARTag.success);
                    }
                }
                else
                {
                    var pvm = Func.Common.GuffQuery(category, q, nv, tag, obj, OwnerId, uinfo.UserId, page);
                    vm.data = pvm;

                    vm.Set(ARTag.success);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 起始页
        /// </summary>
        /// <returns></returns>
        public ActionResultVM Index()
        {
            var vm = new ActionResultVM();

            try
            {
                //TO DO
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex, true);
            }

            return(vm);
        }
Ejemplo n.º 11
0
        public ActionResultVM ResetAll(string password)
        {
            var vm = new ActionResultVM();

            try
            {
                if (GlobalTo.GetValue <bool>("Safe:IsDev"))
                {
                    if (!string.IsNullOrWhiteSpace(password) && password == GlobalTo.GetValue("Safe:CreateAppPassword"))
                    {
                        //清空数据库
                        using var db = new SQLite.SQLiteConnection(SQLiteBase.SQLiteConn);
                        db.DeleteAll <SysKey>();
                        db.DeleteAll <FileRecord>();

                        //删除上传文件
                        var rootdir = GlobalTo.WebRootPath + GlobalTo.GetValue("StaticResource:RootDir");
                        if (Directory.Exists(rootdir))
                        {
                            Directory.Delete(rootdir, true);
                        }

                        vm.Set(ARTag.success);
                    }
                    else
                    {
                        vm.Set(ARTag.unauthorized);
                        vm.msg = "密码错误";
                    }
                }
                else
                {
                    vm.Set(ARTag.refuse);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 12
0
        public ActionResultVM ReplyList(string id, int page = 1)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(HttpContext).Get();

                var pag = new PaginationVM
                {
                    PageNumber = Math.Max(page, 1),
                    PageSize   = 10
                };

                var list = Func.Common.ReplyOneQuery(EnumAid.ReplyType.GuffRecord, id, pag);
                //匿名用户,生成邮箱MD5加密用于请求头像
                foreach (var item in list)
                {
                    if (item.Uid == 0 && !string.IsNullOrWhiteSpace(item.UrAnonymousMail))
                    {
                        item.Spare3 = CalcTo.MD5(item.UrAnonymousMail);
                    }
                }

                var pvm = new PageVM()
                {
                    Rows = list,
                    Pag  = pag
                };
                vm.data = pvm;

                vm.Set(ARTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 13
0
        public ActionResultVM HotTag()
        {
            var vm = new ActionResultVM();

            try
            {
                using var db = new ContextBase();
                var listTags  = db.GuffRecord.OrderByDescending(x => x.GrCreateTime).Select(x => x.GrTag).Take(1000).ToList();
                var orderTags = string.Join(",", listTags).Split(',').GroupBy(x => x).OrderByDescending(x => x.Count()).Select(x => x.Key).Take(20).ToList();

                vm.data = orderTags;
                vm.Set(ARTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 14
0
        public ActionResultVM MenuTree()
        {
            var vm = new ActionResultVM();

            try
            {
                var code = RouteData.Values["id"]?.ToString();

                using var db = new ContextBase();
                var list = db.DocSetDetail.Where(x => x.DsCode == code).OrderBy(x => x.DsdOrder).Select(x => new
                {
                    x.DsdId,
                    x.DsdPid,
                    x.DsdTitle,
                    x.DsdOrder,
                    IsCatalog = string.IsNullOrEmpty(x.DsdContentMd)
                }).ToList();

                var listtree = TreeTo.ListToTree(list, "DsdPid", "DsdId", new List <string> {
                    Guid.Empty.ToString()
                });
                if (string.IsNullOrWhiteSpace(listtree))
                {
                    vm.Set(ARTag.lack);
                }
                else
                {
                    vm.data = listtree.ToJArray();
                    vm.Set(ARTag.success);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 15
0
        public ActionResultVM API81(int?count = 10)
        {
            var vm = new ActionResultVM();

            try
            {
                var list = new List <string>();
                for (int i = 0; i < count; i++)
                {
                    list.Add(Guid.NewGuid().ToString());
                }
                vm.data = list;
                vm.Set(ARTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 16
0
        public ActionResultVM API9999()
        {
            var vm = new ActionResultVM();

            try
            {
                var dic = new Dictionary <int, string>();
                foreach (ARTag item in Enum.GetValues(typeof(ARTag)))
                {
                    dic.Add((int)item, item.ToString());
                }
                vm.data = dic;
                vm.Set(ARTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 17
0
        public ActionResultVM API82(int?count = 10)
        {
            var vm = new ActionResultVM();

            try
            {
                var list = new List <long>();
                for (int i = 0; i < count; i++)
                {
                    list.Add(UniqueTo.LongId());
                }
                vm.data = list;
                vm.Set(ARTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 18
0
        public ActionResultVM GetAppList(int pageNumber = 1, int pageSize = 20)
        {
            var vm = new ActionResultVM();

            try
            {
                if (GlobalTo.GetValue <bool>("Safe:IsDev"))
                {
                    vm = SQLiteBase.GetAppList(pageNumber, pageSize);
                }
                else
                {
                    vm.Set(ARTag.refuse);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 19
0
        public ActionResultVM Add(GuffRecord mo)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(HttpContext).Get();

                if (string.IsNullOrWhiteSpace(mo.GrContent) && string.IsNullOrWhiteSpace(mo.GrImage) && string.IsNullOrWhiteSpace(mo.GrAudio) && string.IsNullOrWhiteSpace(mo.GrVideo))
                {
                    vm.code = 1;
                    vm.msg  = "内容不能为空(内容、图片、音频、视频 至少有一项有内容)";
                }
                else if (string.IsNullOrWhiteSpace(mo.GrTag))
                {
                    vm.code = 2;
                    vm.msg  = "标签不能为空";
                }
                else if (uinfo.UserId == 0)
                {
                    vm.Set(ARTag.unauthorized);
                }
                else
                {
                    using var db = new ContextBase();

                    if (db.UserInfo.Find(uinfo.UserId).UserMailValid != 1)
                    {
                        vm.code = 1;
                        vm.msg  = "请先验证邮箱";
                    }
                    else
                    {
                        var now = DateTime.Now;

                        mo.Uid          = uinfo.UserId;
                        mo.GrId         = UniqueTo.LongId().ToString();
                        mo.GrCreateTime = now;
                        mo.GrUpdateTime = now;
                        mo.GrStatus     = 1;
                        mo.GrReadNum    = 0;
                        mo.GrLaud       = 0;
                        mo.GrMark       = 0;
                        mo.GrReplyNum   = 0;
                        mo.GrOpen ??= 1;

                        mo.GrTypeName  = ParsingTo.JsSafeJoin(mo.GrTypeName);
                        mo.GrTypeValue = ParsingTo.JsSafeJoin(mo.GrTypeValue);
                        mo.GrObject    = ParsingTo.JsSafeJoin(mo.GrObject);
                        mo.GrImage     = ParsingTo.JsSafeJoin(mo.GrImage);
                        mo.GrAudio     = ParsingTo.JsSafeJoin(mo.GrAudio);
                        mo.GrVideo     = ParsingTo.JsSafeJoin(mo.GrVideo);
                        mo.GrFile      = ParsingTo.JsSafeJoin(mo.GrFile);
                        mo.GrTag       = ParsingTo.JsSafeJoin(mo.GrTag);

                        db.GuffRecord.Add(mo);

                        int num = db.SaveChanges();

                        vm.data = mo.GrId;
                        vm.Set(num > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 20
0
        public SharedResultVM WriteSave(UserWriting mo, string TagIds)
        {
            var vm = new SharedResultVM();

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

                    var lisTagId = new List <int>();
                    TagIds.Split(',').ToList().ForEach(x => lisTagId.Add(Convert.ToInt32(x)));

                    var lisTagName = Application.CommonService.TagsQuery().Where(x => lisTagId.Contains(x.TagId)).ToList();

                    mo.Uid          = uinfo.UserId;
                    mo.UwCreateTime = DateTime.Now;
                    mo.UwUpdateTime = mo.UwCreateTime;
                    mo.UwLastUid    = mo.Uid;
                    mo.UwLastDate   = mo.UwCreateTime;
                    mo.UwReplyNum   = 0;
                    mo.UwReadNum    = 0;
                    mo.UwOpen       = 1;
                    mo.UwLaud       = 0;
                    mo.UwMark       = 0;
                    mo.UwStatus     = 1;

                    db.UserWriting.Add(mo);
                    db.SaveChanges();

                    var listwt = new List <UserWritingTags>();
                    foreach (var tag in lisTagId)
                    {
                        var wtmo = new UserWritingTags
                        {
                            UwId    = mo.UwId,
                            TagId   = tag,
                            TagName = lisTagName.FirstOrDefault(x => x.TagId == tag).TagName
                        };

                        listwt.Add(wtmo);
                    }
                    db.UserWritingTags.AddRange(listwt);

                    //标签热点+1
                    var listTagId = listwt.Select(x => x.TagId.Value);
                    var listTags  = db.Tags.Where(x => listTagId.Contains(x.TagId)).ToList();
                    listTags.ForEach(x => x.TagHot += 1);
                    db.Tags.UpdateRange(listTags);

                    int num = db.SaveChanges();

                    vm.Data = mo.UwId;
                    vm.Set(num > 0);
                }
            }
            catch (Exception ex)
            {
                ConsoleTo.Log(ex);
                vm.Set(ex);
            }

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

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

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

                    switch (vtype)
                    {
                    case ValidateloginType.qq:
                    {
                        //获取 access_token
                        var tokenEntity = QQ.AccessToken(new QQ_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });

                        //获取 OpendId
                        var openidEntity = QQ.OpenId(new QQ_OpenId_RequestEntity()
                            {
                                access_token = tokenEntity.access_token
                            });

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

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

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

                        avatar   = userEntity.figureurl_qq_1;
                        avatarhd = userEntity.figureurl_qq_2;
                    }
                    break;
                    //case ValidateloginType.weibo:
                    //    {
                    //        //获取 access_token
                    //        var tokenEntity = Weibo.AccessToken(new Weibo_AccessToken_RequestEntity()
                    //        {
                    //            code = authorizeResult.code
                    //        });

                    //        //获取 access_token 的授权信息
                    //        var tokenInfoEntity = Weibo.GetTokenInfo(new Weibo_GetTokenInfo_RequestEntity()
                    //        {
                    //            access_token = tokenEntity.access_token
                    //        });

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

                    //        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.profile_image_url;
                    //        avatarhd = userEntity.avatar_large;
                    //    }
                    //    break;
                    case ValidateloginType.github:
                    {
                        //获取 access_token
                        var tokenEntity = GitHub.AccessToken(new GitHub_AccessToken_RequestEntity()
                            {
                                code = authorizeResult.code
                            });

                        //获取 user
                        var userEntity = GitHub.User(new GitHub_User_RequestEntity()
                            {
                                access_token = tokenEntity.access_token
                            });

                        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;
                        avatarhd = userEntity.avatar_url;
                    }
                    break;
                        //case ValidateloginType.taobao:
                        //    {
                        //        //获取 access_token
                        //        var tokenEntity = TaoBao.AccessToken(new TaoBao_AccessToken_RequestEntity()
                        //        {
                        //            code = authorizeResult.code
                        //        });

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

                        //        mo.Nickname = "淘宝用户";
                        //    }
                        //    break;
                        //case ValidateloginType.microsoft:
                        //    {
                        //        //获取 access_token
                        //        var tokenEntity = MicroSoft.AccessToken(new MicroSoft_AccessToken_RequestEntity()
                        //        {
                        //            code = authorizeResult.code
                        //        });

                        //        //获取 user
                        //        var userEntity = MicroSoft.User(new MicroSoft_User_RequestEntity()
                        //        {
                        //            access_token = tokenEntity.access_token
                        //        });

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

                        //        mo.Nickname = userEntity.last_name + userEntity.first_name;
                        //        mo.UserMail = userEntity.emails?["account"].ToStringOrEmpty();
                        //    }
                        //    break;
                        //case ValidateloginType.dingtalk:
                        //    {
                        //        //获取 user
                        //        var userEntity = DingTalk.User(new DingTalk_User_RequestEntity(), authorizeResult.code);

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

                        //        mo.Nickname = userEntity.nick;
                        //    }
                        //    break;
                    }

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

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

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

                                case ValidateloginType.weibo:
                                    queryIsBind = queryIsBind.Where(x => x.OpenId2 == openId);
                                    break;

                                case ValidateloginType.github:
                                    queryIsBind = queryIsBind.Where(x => x.OpenId3 == openId);
                                    break;

                                case ValidateloginType.taobao:
                                    queryIsBind = queryIsBind.Where(x => x.OpenId4 == openId);
                                    break;

                                case ValidateloginType.microsoft:
                                    queryIsBind = queryIsBind.Where(x => x.OpenId5 == openId);
                                    break;

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

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

                                switch (vtype)
                                {
                                case ValidateloginType.qq:
                                    userInfo.OpenId1 = openId;
                                    break;

                                case ValidateloginType.weibo:
                                    userInfo.OpenId2 = openId;
                                    break;

                                case ValidateloginType.github:
                                    userInfo.OpenId3 = openId;
                                    break;

                                case ValidateloginType.taobao:
                                    userInfo.OpenId4 = openId;
                                    break;

                                case ValidateloginType.microsoft:
                                    userInfo.OpenId5 = openId;
                                    break;

                                case ValidateloginType.dingtalk:
                                    userInfo.OpenId6 = openId;
                                    break;
                                }
                                db.UserInfo.Update(userInfo);
                                db.SaveChanges();
                            }

                            return(Redirect("/user/setting"));
                        }
                        else
                        {
                            using var db = new ContextBase();
                            UserInfo vmo = null;
                            switch (vtype)
                            {
                            case ValidateloginType.qq:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId1 == openId);
                                break;

                            case ValidateloginType.weibo:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId2 == openId);
                                break;

                            case ValidateloginType.github:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId3 == openId);
                                break;

                            case ValidateloginType.taobao:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId4 == openId);
                                break;

                            case ValidateloginType.microsoft:
                                vmo = db.UserInfo.FirstOrDefault(x => x.OpenId5 == openId);
                                break;

                            case ValidateloginType.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) || !string.IsNullOrWhiteSpace(avatarhd)))
                                    {
                                        try
                                        {
                                            using var wc = new System.Net.WebClient();
                                            var rootdir  = GlobalTo.WebRootPath + "/" + (GlobalTo.GetValue("StaticResource:RootDir").TrimStart('/').TrimEnd('/') + "/");
                                            var path     = GlobalTo.GetValue("StaticResource:AvatarPath").TrimEnd('/').TrimStart('/') + '/';
                                            var fullpath = rootdir + path;

                                            if (!System.IO.Directory.Exists(fullpath))
                                            {
                                                System.IO.Directory.CreateDirectory(fullpath);
                                            }
                                            if (!string.IsNullOrWhiteSpace(avatar))
                                            {
                                                wc.DownloadFile(avatar, fullpath + mo.UserPhoto);
                                            }
                                            if (!string.IsNullOrWhiteSpace(avatarhd))
                                            {
                                                wc.DownloadFile(avatarhd, fullpath + mo.UserPhoto.Replace(".jpg", "_lg.jpg"));
                                            }
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                }
                                else
                                {
                                    vm.msg = ruvm.msg;
                                }
                            }
                            else
                            {
                                vm = ValidateLogin(vtype, vmo);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);

                ConsoleTo.Log(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
            {
                string msg = "【登录失败】( " + vm.msg + " )".ToEncode();
                return(Redirect("/home/error?msg=" + msg));
            }
        }
Ejemplo n.º 22
0
        public ActionResultVM Connection(string type, int ac, string id)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(HttpContext).Get();

                if (uinfo.UserId == 0)
                {
                    vm.Set(ARTag.unauthorized);
                }
                else if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (!new List <string> {
                    "add", "cancel"
                }.Contains(type))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (!new List <int> {
                    1, 2
                }.Contains(ac))
                {
                    vm.Set(ARTag.invalid);
                }
                else
                {
                    using var db = new ContextBase();
                    var currMo = db.GuffRecord.Find(id);

                    if (currMo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        var ctype = EnumAid.ConnectionType.GuffRecord.ToString();
                        switch (type)
                        {
                        case "add":
                        {
                            if (db.UserConnection.Any(x => x.Uid == uinfo.UserId && x.UconnTargetType == ctype && x.UconnTargetId == id && x.UconnAction == ac))
                            {
                                vm.Set(ARTag.exist);
                            }
                            else
                            {
                                //关联记录
                                var ucmo = new UserConnection()
                                {
                                    UconnId         = UniqueTo.LongId().ToString(),
                                    Uid             = uinfo.UserId,
                                    UconnTargetType = EnumAid.ConnectionType.GuffRecord.ToString(),
                                    UconnTargetId   = id,
                                    UconnAction     = ac,
                                    UconnCreateTime = DateTime.Now
                                };

                                db.Add(ucmo);

                                switch (ac)
                                {
                                case 1:
                                    currMo.GrLaud += 1;
                                    break;

                                case 2:
                                    currMo.GrMark += 1;
                                    break;
                                }
                                db.Update(currMo);

                                int num = db.SaveChanges();

                                vm.Set(num > 0);
                            }
                        }
                        break;

                        case "cancel":
                        {
                            var curruc = db.UserConnection.FirstOrDefault(x => x.Uid == uinfo.UserId && x.UconnTargetType == ctype && x.UconnTargetId == id && x.UconnAction == ac);
                            if (curruc == null)
                            {
                                vm.Set(ARTag.invalid);
                            }
                            else
                            {
                                db.Remove(curruc);

                                switch (ac)
                                {
                                case 1:
                                    currMo.GrLaud -= 1;
                                    break;

                                case 2:
                                    currMo.GrMark -= 1;
                                    break;
                                }
                                db.Update(currMo);

                                int num = db.SaveChanges();

                                vm.Set(num > 0);
                            }
                        }
                        break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Gist代码片段,同步到GitHub、Gitee
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static ActionResultVM GistSync(int UserId = 1)
        {
            var vm = new ActionResultVM();

            try
            {
                //日志
                var listLog = new List <object>();

                using var db = new ContextBase();
                var listGist = db.Gist.Where(x => x.Uid == UserId).OrderBy(x => x.GistCreateTime).ToList();

                var codes = listGist.Select(x => x.GistCode).ToList();

                var listGs = db.GistSync.Where(x => x.Uid == UserId).ToList();

                //执行命令记录
                var dicSync = new Dictionary <string, string>();

                foreach (var gist in listGist)
                {
                    var gs = listGs.FirstOrDefault(x => x.GistCode == gist.GistCode);
                    //新增
                    if (gs == null)
                    {
                        dicSync.Add(gist.GistCode, "add");
                    }
                    else if (gs?.GsGitHubTime != gist.GistUpdateTime || gs?.GsGiteeTime != gist.GistUpdateTime)
                    {
                        dicSync.Add(gist.GistCode, "update");
                    }
                }

                //删除
                var delCode = listGs.Select(x => x.GistCode).Except(listGist.Select(x => x.GistCode)).ToList();

                var token_gh = GlobalTo.GetValue("ApiKey:GitHub:GistToken");
                var token_ge = GlobalTo.GetValue("ApiKey:Gitee:GistToken");

                listLog.Add("同步新增、修改:" + dicSync.Count + " 条");
                listLog.Add(dicSync);

                //同步新增、修改
                if (dicSync.Count > 0)
                {
                    foreach (var key in dicSync.Keys)
                    {
                        var st   = dicSync[key];
                        var gist = listGist.FirstOrDefault(x => x.GistCode == key);
                        var gs   = listGs.FirstOrDefault(x => x.GistCode == key);

                        //发送主体
                        #region MyRegion
                        var jo = new JObject
                        {
                            ["access_token"] = token_ge,//only gitee

                            ["description"] = gist.GistRemark,
                            ["public"]      = gist.GistOpen == 1
                        };

                        var jc = new JObject
                        {
                            ["content"] = gist.GistContent
                        };

                        var jf = new JObject
                        {
                            [gist.GistFilename] = jc
                        };

                        jo["files"] = jf;
                        #endregion

                        switch (st)
                        {
                        case "add":
                        {
                            var gsmo = new GistSync()
                            {
                                GistCode     = key,
                                Uid          = UserId,
                                GistFilename = gist.GistFilename
                            };

                            //GitHub
                            {
                                var hwr = HttpTo.HWRequest("https://api.github.com/gists", "POST", jo.ToJson());
                                hwr.Headers.Add(HttpRequestHeader.Authorization, "token " + token_gh);
                                hwr.ContentType = "application/json";
                                hwr.UserAgent   = GlobalTo.GetValue("UserAgent");

                                var rt = HttpTo.Url(hwr);

                                gsmo.GsGitHubId   = rt.ToJObject()["id"].ToString();
                                gsmo.GsGitHubTime = gist.GistUpdateTime;
                            }

                            //Gitee
                            {
                                var hwr = HttpTo.HWRequest("https://gitee.com/api/v5/gists", "POST", jo.ToJson());
                                hwr.ContentType = "application/json";

                                var rt = HttpTo.Url(hwr);

                                gsmo.GsGiteeId   = rt.ToJObject()["id"].ToString();
                                gsmo.GsGiteeTime = gist.GistUpdateTime;
                            }

                            _ = db.GistSync.Add(gsmo);
                            _ = db.SaveChanges();

                            listLog.Add("新增一条成功");
                            listLog.Add(gsmo);
                        }
                        break;

                        case "update":
                        {
                            if (gs.GistFilename != gist.GistFilename)
                            {
                                jo["files"][gs.GistFilename] = null;
                                gs.GistFilename = gist.GistFilename;
                            }

                            //GitHub
                            {
                                var hwr = HttpTo.HWRequest("https://api.github.com/gists/" + gs.GsGitHubId, "PATCH", jo.ToJson());
                                hwr.Headers.Add(HttpRequestHeader.Authorization, "token " + token_gh);
                                hwr.ContentType = "application/json";
                                hwr.UserAgent   = GlobalTo.GetValue("UserAgent");

                                _ = HttpTo.Url(hwr);

                                gs.GsGitHubTime = gist.GistUpdateTime;
                            }

                            //Gitee
                            {
                                var hwr = HttpTo.HWRequest("https://gitee.com/api/v5/gists/" + gs.GsGiteeId, "PATCH", jo.ToJson());
                                hwr.ContentType = "application/json";

                                _ = HttpTo.Url(hwr);

                                gs.GsGiteeTime = gist.GistUpdateTime;
                            }

                            _ = db.GistSync.Update(gs);
                            _ = db.SaveChanges();

                            listLog.Add("更新一条成功");
                            listLog.Add(gs);
                        }
                        break;
                        }

                        Thread.Sleep(1000 * 2);
                    }
                }

                listLog.Add("同步删除:" + delCode.Count + " 条");
                listLog.Add(delCode);

                //同步删除
                if (delCode.Count > 0)
                {
                    foreach (var code in delCode)
                    {
                        var gs = listGs.FirstOrDefault(x => x.GistCode == code);

                        var dc = "00".ToCharArray();

                        #region GitHub
                        var hwr_gh = HttpTo.HWRequest("https://api.github.com/gists/" + gs.GsGitHubId, "DELETE");
                        hwr_gh.Headers.Add(HttpRequestHeader.Authorization, "token " + token_gh);
                        hwr_gh.UserAgent = GlobalTo.GetValue("UserAgent");
                        var resp_gh = (HttpWebResponse)hwr_gh.GetResponse();
                        if (resp_gh.StatusCode == HttpStatusCode.NoContent)
                        {
                            dc[0] = '1';
                        }
                        #endregion

                        #region Gitee
                        var hwr_ge  = HttpTo.HWRequest("https://gitee.com/api/v5/gists/" + gs.GsGiteeId + "?access_token=" + token_ge, "DELETE");
                        var resp_ge = (HttpWebResponse)hwr_ge.GetResponse();
                        if (resp_ge.StatusCode == HttpStatusCode.NoContent)
                        {
                            dc[1] = '1';
                        }
                        #endregion

                        if (string.Join("", dc) == "11")
                        {
                            _ = db.GistSync.Remove(gs);
                            _ = db.SaveChanges();

                            listLog.Add("删除一条成功");
                            listLog.Add(gs);
                        }
                        else
                        {
                            listLog.Add("删除一条异常");
                            listLog.Add(dc);
                        }

                        Thread.Sleep(1000 * 2);
                    }
                }

                listLog.Add("完成同步");

                vm.Set(ARTag.success);
                vm.data = listLog;
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Console.WriteLine(ex);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
                ConsoleTo.Log(ex, true);
            }

            return(vm);
        }
Ejemplo n.º 24
0
 void IJob.Execute()
 {
     ConsoleTo.Log(BackupDataBase().ToJson());
 }
Ejemplo n.º 25
0
        public ActionResultVM Update(GuffRecord mo)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(HttpContext).Get();

                if (string.IsNullOrWhiteSpace(mo.GrContent) && string.IsNullOrWhiteSpace(mo.GrImage) && string.IsNullOrWhiteSpace(mo.GrAudio) && string.IsNullOrWhiteSpace(mo.GrVideo))
                {
                    vm.code = 1;
                    vm.msg  = "内容不能为空(内容、图片、音频、视频 至少有一项有内容)";
                }
                else if (string.IsNullOrWhiteSpace(mo.GrTag))
                {
                    vm.code = 2;
                    vm.msg  = "标签不能为空";
                }
                else if (uinfo.UserId == 0)
                {
                    vm.Set(ARTag.unauthorized);
                }
                else
                {
                    using var db = new ContextBase();
                    var currMo = db.GuffRecord.Find(mo.GrId);

                    if (currMo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        currMo.GrTypeName  = ParsingTo.JsSafeJoin(mo.GrTypeName);
                        currMo.GrTypeValue = ParsingTo.JsSafeJoin(mo.GrTypeValue);
                        currMo.GrObject    = ParsingTo.JsSafeJoin(mo.GrObject);

                        currMo.GrContent   = mo.GrContent;
                        currMo.GrContentMd = mo.GrContentMd;

                        currMo.GrImage  = ParsingTo.JsSafeJoin(mo.GrImage);
                        currMo.GrAudio  = ParsingTo.JsSafeJoin(mo.GrAudio);
                        currMo.GrVideo  = ParsingTo.JsSafeJoin(mo.GrVideo);
                        currMo.GrFile   = ParsingTo.JsSafeJoin(mo.GrFile);
                        currMo.GrRemark = mo.GrRemark;

                        currMo.GrTag        = mo.GrTag;
                        currMo.GrUpdateTime = DateTime.Now;
                        currMo.GrOpen       = mo.GrOpen ?? 1;

                        db.Update(currMo);

                        int num = db.SaveChanges();

                        vm.data = mo.GrId;
                        vm.Set(num > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 26
0
        public ActionResultVM Detail(string id)
        {
            var vm = new ActionResultVM();

            try
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else
                {
                    var ctype = EnumAid.ConnectionType.GuffRecord.ToString();

                    var uinfo = new UserAuthAid(HttpContext).Get();

                    using var db = new ContextBase();
                    var query = from a in db.GuffRecord
                                join b in db.UserInfo on a.Uid equals b.UserId
                                join c in db.UserConnection.Where(x => x.UconnTargetType == ctype && x.UconnAction == 1 && x.Uid == uinfo.UserId) on a.GrId equals c.UconnTargetId into cg
                                from c1 in cg.DefaultIfEmpty()
                                where a.GrId == id
                                select new
                    {
                        a,
                        c1.UconnTargetId,
                        b.Nickname
                    };
                    var qm = query.FirstOrDefault();
                    if (qm == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        if (qm.a.GrOpen == 1 || uinfo.UserId == qm.a.Uid)
                        {
                            // 阅读 +1
                            qm.a.GrReadNum += 1;
                            db.Update(qm.a);
                            db.SaveChanges();

                            qm.a.Spare1 = string.IsNullOrEmpty(qm.UconnTargetId) ? "" : "laud";
                            qm.a.Spare2 = (uinfo.UserId == qm.a.Uid) ? "owner" : "";
                            qm.a.Spare3 = qm.Nickname;

                            vm.data = qm.a;

                            vm.Set(ARTag.success);
                        }
                        else
                        {
                            vm.Set(ARTag.unauthorized);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 27
0
 void IJob.Execute()
 {
     ConsoleTo.Log(HandleOperationRecord().ToJson());
 }
Ejemplo n.º 28
0
 void IJob.Execute()
 {
     ConsoleTo.Log(GistSync().ToJson());
 }
Ejemplo n.º 29
0
        public ActionResultVM API98(IFormFile file, string cp = null)
        {
            var vm = new ActionResultVM();

            if (Request.Method == "OPTIONS")
            {
                vm.Set(ARTag.success);
                return(vm);
            }

            try
            {
                if (file != null)
                {
                    var    now      = DateTime.Now;
                    string filename = now.ToString("HHmmss") + Guid.NewGuid().ToString("N").Substring(25, 4);
                    string ext      = file.FileName.Substring(file.FileName.LastIndexOf('.'));

                    if (ext.ToLower() == ".exe")
                    {
                        vm.code = 2;
                        vm.msg  = "Unsupported file format:" + ext;
                    }
                    else
                    {
                        //自定义路径
                        if (!string.IsNullOrWhiteSpace(cp))
                        {
                            cp = cp.TrimStart('/').TrimEnd('/') + '/';
                        }

                        var    path     = cp + now.ToString("yyyy/MM/dd/");
                        var    rootdir  = GlobalTo.WebRootPath + "/" + (GlobalTo.GetValue("StaticResource:RootDir") + "/");
                        string fullpath = rootdir + path;

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

                        using (var fs = new FileStream(fullpath + filename + ext, FileMode.CreateNew))
                        {
                            file.CopyTo(fs);
                            fs.Flush();
                        }

                        var FilePath = path + filename + ext;

                        var jo = new
                        {
                            server = GlobalTo.GetValue("StaticResource:Server").TrimEnd('/') + '/',
                            path   = FilePath
                        };

                        vm.data = jo;

                        vm.Set(ARTag.success);
                    }
                }
                else
                {
                    vm.Set(ARTag.lack);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 30
0
        public ActionResultVM ReplyAdd(UserReply mo, string id)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(HttpContext).Get();

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    mo.Uid = uinfo.UserId;
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(mo.UrAnonymousName) || !ParsingTo.IsMail(mo.UrAnonymousMail))
                    {
                        vm.Set(ARTag.invalid);
                        vm.msg = "昵称、邮箱不能为空";

                        return(vm);
                    }

                    mo.Uid = 0;
                }

                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (string.IsNullOrWhiteSpace(mo.UrContent))
                {
                    vm.Set(ARTag.invalid);
                    vm.msg = "回复内容不能为空";
                }
                else
                {
                    using var db = new ContextBase();
                    var guffmo = db.GuffRecord.Find(id);
                    if (guffmo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        mo.Uid          = uinfo.UserId;
                        mo.UrTargetType = EnumAid.ConnectionType.GuffRecord.ToString();
                        mo.UrTargetId   = id;
                        mo.UrCreateTime = DateTime.Now;
                        mo.UrStatus     = 1;
                        mo.UrTargetPid  = 0;

                        mo.UrAnonymousLink = ParsingTo.JsSafeJoin(mo.UrAnonymousLink);

                        db.UserReply.Add(mo);

                        guffmo.GrReplyNum += 1;
                        db.GuffRecord.Update(guffmo);

                        int num = db.SaveChanges();
                        vm.Set(num > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }