public async Task DeletePuzzle(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <DeletePuzzleRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //删除它
            var puzzleDb = DbFactory.Get <Puzzle>();
            await puzzleDb.SimpleDb.AsDeleteable().Where(it => it.pid == requestJson.pid).ExecuteCommandAsync();

            await puzzleDb.InvalidateCache();

            await response.OK();
        }
Exemplo n.º 2
0
        public async Task EditAnnouncement(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <EditAnnoRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //生成修改后对象
            var updateAnno = new announcement
            {
                aid         = requestJson.aid,
                content     = requestJson.content,
                update_time = DateTime.Now
            };

            var annoDb = DbFactory.Get <Announcement>();
            await annoDb.SimpleDb.AsUpdateable(updateAnno).IgnoreColumns(it => new { it.create_time }).ExecuteCommandAsync();

            await annoDb.InvalidateCache();

            await response.OK();
        }
Exemplo n.º 3
0
        public async Task ListMyInvite(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Normal);

            if (userSession == null)
            {
                return;
            }

            //读取基础数据
            var groupDb       = DbFactory.Get <UserGroup>();
            var groupNameDict = (await groupDb.SelectAllFromCache()).ToDictionary(it => it.gid, it => it.groupname);

            //读取仍然为有效状态的邀请
            var inviteDb = DbFactory.Get <Invite>();
            var result   = await inviteDb.SimpleDb.AsQueryable().Where(it => it.to_uid == userSession.uid && it.valid == 1).ToListAsync();

            var res = result.Select(it =>
            {
                var r = new ListSentResponse.InviteView(it);
                if (groupNameDict.ContainsKey(r.from_gid))
                {
                    r.from_groupname = groupNameDict[r.from_gid];
                }
                return(r);
            }).ToList();

            await response.JsonResponse(200, new ListSentResponse
            {
                status = 1,
                result = res
            });
        }
Exemplo n.º 4
0
        public async Task SendMail(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Member, true);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <SendMailRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //取得该用户GID
            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            var groupBindItem = groupBindList.FirstOrDefault(it => it.uid == userSession.uid);

            if (groupBindItem == null)
            {
                await response.BadRequest("未确定组队?");

                return;
            }

            var gid = groupBindItem.gid;

            var          content     = requestJson.content;
            const string regExStyle  = "<style[^>]*?>[\\s\\S]*?<\\/style>";
            const string regExScript = "<script[^>]*?>[\\s\\S]*?<\\/script>";
            const string regExHtml   = "<[^>]+>";

            content = Regex.Replace(content, regExStyle, "", RegexOptions.IgnoreCase);
            content = Regex.Replace(content, regExScript, "", RegexOptions.IgnoreCase);
            content = Regex.Replace(content, regExHtml, "");

            //写入新消息
            var newMessage = new message
            {
                content     = content,
                update_time = DateTime.Now,
                create_time = DateTime.Now,
                gid         = gid,
                uid         = userSession.uid,
                is_read     = 0,
                direction   = 0
            };

            var messageDb = DbFactory.Get <Message>();
            await messageDb.SimpleDb.AsInsertable(newMessage).ExecuteCommandAsync();

            await response.OK();
        }
Exemplo n.º 5
0
        protected override async void OnAppearing()
        {
            if (CheckConnection.validate())
            {
                bool validate = await CheckAuth.validate();

                if (validate)
                {
                    await Navigation.PushModalAsync(new Timeline());
                }
                else
                {
                    loader.IsVisible     = false;
                    formLogin.IsVisible  = true;
                    btRemember.IsVisible = true;
                }
            }
            else

            {
                App.Current.MainPage = new NavigationPage(new FailConnection());
            }

            base.OnAppearing();
        }
Exemplo n.º 6
0
        public async Task HeartBeat(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Normal);

            if (userSession == null)
            {
                return;
            }

            var newMessage = 0; //新消息数目

            //取得该用户GID
            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            var groupBindItem = groupBindList.FirstOrDefault(it => it.uid == userSession.uid);

            if (groupBindItem != null)
            {
                var gid       = groupBindItem.gid;
                var messageDb = DbFactory.Get <Message>();
                newMessage = await messageDb.SimpleDb.AsQueryable()
                             .Where(it => it.gid == gid && it.direction == 1 && it.is_read == 0).CountAsync();
            }

            await response.JsonResponse(200, new
            {
                status      = 1,
                new_message = newMessage
            });
        }
Exemplo n.º 7
0
        public async Task UploadPrepare(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Member);

            if (userSession == null)
            {
                return;
            }

            var cache            = DbFactory.GetCache();
            var imageUploadToken = Guid.NewGuid().ToString("n");

            var imageUploadCacheKey = cache.GetDataKey($"upload_prepare_{imageUploadToken}");
            await cache.Put(imageUploadCacheKey, new ImagePrepareData
            {
                token = imageUploadToken
            }, 300000);

            await response.JsonResponse(200, new ImagePrepareResponse
            {
                status       = 1,
                message      = "成功获取上传Token,请在300秒完成上传",
                upload_token = imageUploadToken
            });
        }
        private async void Authorisation()
        {
            await PopupNavigation.PushAsync(new LoadPage(), true);

            string description = null;
            int    stateAuth   = managerVazoo.A_RWork("authorisation", ref description, idCompany, Username, password);
            await PopupNavigation.PopAllAsync();

            if (stateAuth == 3)
            {
                CheckAuth.SavingAccount(IdCompany, Username, Password);
                Application.Current.MainPage = new MenuDetalePage();
            }
            else if (stateAuth == 2)
            {
                await PopupNavigation.PushAsync(new Error("Invalid login or password, please try again"), true);
            }
            else if (stateAuth == 1)
            {
                await PopupNavigation.PushAsync(new Error("No network"), true);
            }
            else if (stateAuth == 4)
            {
                await PopupNavigation.PushAsync(new Error("Technical works on the server"), true);
            }
        }
Exemplo n.º 9
0
        public async Task EditPuzzleGroup(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <EditPuzzleGroupRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //生成修改后对象
            var updatePg = new puzzle_group
            {
                pgid    = requestJson.pgid,
                pg_name = requestJson.pg_name,
                pg_desc = requestJson.pg_desc,
                is_hide = (byte)(requestJson.is_hide == 1 ? 1 : 0)
            };

            var pgDb = DbFactory.Get <PuzzleGroup>();
            await pgDb.SimpleDb.AsUpdateable(updatePg).ExecuteCommandAsync();

            await pgDb.InvalidateCache();

            await response.OK();
        }
Exemplo n.º 10
0
        protected override async void OnAppearing()
        {
            if (CheckConnection.validate())
            {
                bool validate = await CheckAuth.validate();

                if (!validate)
                {
                    App.Current.MainPage = new NavigationPage(new Login());
                }
                else
                {
                    await makeTimeline();

                    string screen = Settings.config_screen;

                    double s = Convert.ToDouble(screen);

                    MainRelative.HeightRequest = s;
                }
            }
            else
            {
                App.Current.MainPage = new NavigationPage(new FailConnection());
            }

            base.OnAppearing();
        }
Exemplo n.º 11
0
        public async Task SetReadMessage(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <MessageAdminRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            var messageDb = DbFactory.Get <Message>();

            await messageDb.SimpleDb.AsUpdateable(new message
            {
                mid     = requestJson.mid,
                is_read = 1
            }).UpdateColumns(it => new { it.is_read }).WhereColumns(it => it.mid).ExecuteCommandAsync();

            await response.OK();
        }
Exemplo n.º 12
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            bool validate = await CheckAuth.validate();

            if (validate)
            {
                await Navigation.PushAsync(new Timeline());
            }

            string endpoint = "portalib-dev-category";

            IDictionary <string, string> parameters = new Dictionary <string, string>()
            {
                { "", "" }
            };

            IDictionary <string, string> call = new Dictionary <string, string>
            {
                { "act", "categoryall" },
                { "mod", "category" }
            };

            dynamic res = await decora.Service.Run(endpoint, call, "GET", parameters);

            makeCategories(res);
        }
        public async Task SearchNoGroupUser(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.TeamLeader);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <SearchNoGroupUserRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            var keyword = requestJson.kw_uname.ToLower();

            //读入roleid == 1(没有组队)的用户列表
            var userDb   = DbFactory.Get <User>();
            var userList = await userDb.SelectAllFromCache();

            var res = userList.Where(it => it.roleid == 1 && (string.IsNullOrEmpty(keyword) || it.username.ToLower().Contains(keyword)))
                      .Select(it => new SearchNoGroupUserResponse.UserSearchResult(it)).ToList();

            await response.JsonResponse(200, new SearchNoGroupUserResponse
            {
                status = 1,
                result = res
            });
        }
Exemplo n.º 14
0
        public async Task GetPrologue(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Member, true);

            if (userSession == null)
            {
                return;
            }

            //取得该用户GID
            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            var groupBindItem = groupBindList.FirstOrDefault(it => it.uid == userSession.uid);

            if (groupBindItem == null)
            {
                await response.BadRequest("未确定组队?");

                return;
            }

            var gid = groupBindItem.gid;

            //取得进度
            var progressDb = DbFactory.Get <Progress>();
            var progress   = await progressDb.SimpleDb.AsQueryable().Where(it => it.gid == gid).FirstAsync();

            if (progress == null)
            {
                await response.BadRequest("没有进度,请返回首页重新开始。");

                return;
            }

            var progressData = progress.data;

            if (progressData == null)
            {
                await response.BadRequest("未找到可用存档,请联系管理员。");

                return;
            }

            var groupDb       = DbFactory.Get <PuzzleGroup>();
            var prologueGroup = (await groupDb.SelectAllFromCache()).First(it => it.pg_name == "prologue");

            var prologueResult = "";

            if (prologueGroup != null)
            {
                prologueResult = prologueGroup.pg_desc;
            }

            await response.JsonResponse(200, new BasicResponse
            {
                status  = 1,
                message = prologueResult
            });
        }
Exemplo n.º 15
0
        public async Task InvalidateInvite(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.TeamLeader);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <IidInviteRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //取得该用户GID
            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            var groupBindItem = groupBindList.FirstOrDefault(it => it.uid == userSession.uid);

            if (groupBindItem == null)
            {
                await response.BadRequest("未确定组队?");

                return;
            }

            var gid = groupBindItem.gid;

            //读取目标iid
            var inviteDb   = DbFactory.Get <Invite>();
            var inviteItem = inviteDb.SimpleDb.GetById(requestJson.iid);

            if (inviteItem == null)
            {
                await response.BadRequest("无效邀请");

                return;
            }

            if (inviteItem.from_gid != gid)
            {
                await response.BadRequest("无修改权限");
            }

            //将目标置为无效
            inviteItem.valid = 0;

            await inviteDb.SimpleDb.AsUpdateable(inviteItem).ExecuteCommandAsync();

            await inviteDb.InvalidateCache();

            await response.OK();
        }
Exemplo n.º 16
0
        public ActionResult <CheckAuth> Check()
        {
            var ok = new CheckAuth();

            ok.Ok      = User.Identity.IsAuthenticated;
            ok.Message = "Login successful";
            return(ok);
        }
Exemplo n.º 17
0
        public async Task GetGameInfo(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Member, true);

            if (userSession == null)
            {
                return;
            }

            //取得该用户GID
            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            var groupBindItem = groupBindList.FirstOrDefault(it => it.uid == userSession.uid);

            if (groupBindItem == null)
            {
                await response.BadRequest("未确定组队?");

                return;
            }

            var gid = groupBindItem.gid;

            //取得进度
            var progressDb = DbFactory.Get <Progress>();
            var progress   = await progressDb.SimpleDb.AsQueryable().Where(it => it.gid == gid).FirstAsync();

            if (progress == null)
            {
                await response.BadRequest("没有进度,请返回首页重新开始。");

                return;
            }

            var progressData = progress.data;

            if (progressData == null)
            {
                await response.BadRequest("未找到可用存档,请联系管理员。");

                return;
            }

            var res = new GetGameInfoResponse
            {
                status                = 1,
                open_group_count      = progressData.NowOpenPuzzleGroups.Count,
                finished_puzzle_count = progressData.FinishedPuzzles.Count,
                is_open_next_group    = progressData.IsOpenNextGroup ? 1 : 0,
                score   = progress.score,
                penalty = progress.penalty
            };
            await response.JsonResponse(200, res);
        }
Exemplo n.º 18
0
        protected override async void OnAppearing()
        {
            bool validate = await CheckAuth.validate();

            if (!validate)
            {
                App.Current.MainPage = new NavigationPage(new Login());
            }

            base.OnAppearing();
        }
Exemplo n.º 19
0
        protected override async void OnAppearing()
        {
            bool validate = await CheckAuth.validate();

            if (!validate)
            {
                App.Current.MainPage = new NavigationPage(new Login());
            }

            base.OnAppearing();

            img_category.Source = ImageRender.display("post", "foto5.jpg");
        }
        public async Task RemoveBanUser(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <AdminUidRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out var reason))
            {
                await response.BadRequest(reason);

                return;
            }

            var userDb   = DbFactory.Get <User>();
            var userDict = (await userDb.SelectAllFromCache()).ToDictionary(it => it.uid, it => it);

            if (!userDict.ContainsKey(requestJson.uid))
            {
                await response.BadRequest("请求的UID不存在");

                return;
            }

            var groupBindDb    = DbFactory.Get <UserGroupBind>();
            var userLeaderDict = (await groupBindDb.SelectAllFromCache()).ToDictionary(it => it.uid, it => it.is_leader);

            //修改用户
            var user = userDict[requestJson.uid];

            if (userLeaderDict.ContainsKey(user.uid))
            {
                var isLeader = userLeaderDict[user.uid];
                user.roleid = isLeader == 1 ? 3 : 2;
            }
            else
            {
                user.roleid = 1;
            }

            await userDb.SimpleDb.AsUpdateable(user).ExecuteCommandAsync();

            await userDb.InvalidateCache();

            await response.OK();
        }
Exemplo n.º 21
0
        public async Task ModifyPassword(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Normal);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <ModifyPasswordRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //取出当前用户信息
            var userDb = DbFactory.Get <User>();

            var user = await userDb.SimpleDb.AsQueryable().Where(it => it.uid == userSession.uid).FirstAsync();

            if (user == null || user.roleid < 1)
            {
                await response.Unauthorized("用户不存在或不允许当前用户进行操作。");

                return;
            }

            //验证原密码
            var oldPass = CryptoUtils.GetLoginHash(requestJson.old_pass);

            if (oldPass != user.password)
            {
                await response.BadRequest("原密码不正确。");

                return;
            }

            //新密码写入数据库
            user.password    = CryptoUtils.GetLoginHash(requestJson.pass);
            user.update_time = DateTime.Now;

            await userDb.SimpleDb.AsUpdateable(user).ExecuteCommandAsync();

            await userDb.InvalidateCache();

            await response.OK();
        }
        public async Task Overview(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var result = new List <string>
            {
                $"服务器时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}"
            };

            var userDb   = DbFactory.Get <User>();
            var userList = await userDb.SelectAllFromCache();

            result.Add($"注册用户数:{userList.Count}");

            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            result.Add($"有效报名人数:{groupBindList.Count}");

            var groupDb   = DbFactory.Get <UserGroup>();
            var groupList = await groupDb.SelectAllFromCache();

            result.Add($"报名队伍数:{groupList.Count}");

            var cache = DbFactory.GetCache();
            //登录成功
            var keyPattern     = cache.GetUserSessionKey("*");
            var sessions       = cache.FindKeys(keyPattern);
            var lastActionList = (await Task.WhenAll(sessions.Select(async it => await cache.Get <UserSession>(it))))
                                 .Where(it => it != null && it.is_active == 1)
                                 .GroupBy(it => it.uid)
                                 .Select(it => it.First() == null ? DateTime.MinValue : it.First().last_update)
                                 .Where(it => Math.Abs((DateTime.Now - it).TotalMinutes) < 1.1);

            result.Add($"在线人数:{lastActionList.Count()}");

            var resultString = string.Join("", result.Select(it => "<p>" + it + "</p>"));

            await response.JsonResponse(200, new
            {
                status = 1,
                result = resultString
            });
        }
Exemplo n.º 23
0
        public async Task UserLogout(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Normal);

            if (userSession == null)
            {
                return;
            }

            var cache      = DbFactory.GetCache();
            var sessionKey = cache.GetUserSessionKey(userSession.token);
            await cache.Delete(sessionKey);

            await response.OK();
        }
Exemplo n.º 24
0
        public async Task ListSentInvites(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.TeamLeader);

            if (userSession == null)
            {
                return;
            }

            //取得该用户GID
            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            var groupBindItem = groupBindList.FirstOrDefault(it => it.uid == userSession.uid);

            if (groupBindItem == null)
            {
                await response.BadRequest("未确定组队?");

                return;
            }

            var gid = groupBindItem.gid;

            //读取基础数据
            var userDb       = DbFactory.Get <User>();
            var userNameDict = (await userDb.SelectAllFromCache()).ToDictionary(it => it.uid, it => it.username);

            //读取仍然为有效状态的邀请
            var inviteDb = DbFactory.Get <Invite>();
            var result   = await inviteDb.SimpleDb.AsQueryable().Where(it => it.from_gid == gid && it.valid == 1).ToListAsync();

            var res = result.Select(it =>
            {
                var r = new ListSentResponse.InviteView(it);
                if (userNameDict.ContainsKey(r.to_uid))
                {
                    r.to_username = userNameDict[r.to_uid];
                }
                return(r);
            }).ToList();

            await response.JsonResponse(200, new ListSentResponse
            {
                status = 1,
                result = res
            });
        }
Exemplo n.º 25
0
        protected override async void OnAppearing()
        {
            bool validate = await CheckAuth.validate();

            if (!validate)
            {
                App.Current.MainPage = new NavigationPage(new Login());
            }
            else
            {
                MainRelative.HeightRequest = Application.Current.MainPage.Height;

                makePost(postId);
            }
            base.OnAppearing();
        }
        public async Task GetPuzzle(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var puzzleDb   = DbFactory.Get <Puzzle>();
            var puzzleList = (await puzzleDb.SelectAllFromCache()).OrderBy(it => it.pgid).ThenBy(it => it.pid);

            await response.JsonResponse(200, new GetPuzzleResponse
            {
                status = 1,
                puzzle = puzzleList.ToList()
            });
        }
Exemplo n.º 27
0
        public async Task GetAnnouncement(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var pgDb   = DbFactory.Get <PuzzleGroup>();
            var pgList = (await pgDb.SelectAllFromCache()).OrderBy(it => it.pgid);

            await response.JsonResponse(200, new GetPuzzleGroupResponse
            {
                status       = 1,
                puzzle_group = pgList.ToList()
            });
        }
Exemplo n.º 28
0
        public async Task DeclineInvite(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Normal);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <IidInviteRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //读取目标iid
            var inviteDb   = DbFactory.Get <Invite>();
            var inviteItem = inviteDb.SimpleDb.GetById(requestJson.iid);

            if (inviteItem == null)
            {
                await response.BadRequest("无效邀请");

                return;
            }

            if (inviteItem.to_uid != userSession.uid)
            {
                await response.BadRequest("无修改权限");
            }

            //将目标置为无效
            inviteItem.valid = 2;

            await inviteDb.SimpleDb.AsUpdateable(inviteItem).ExecuteCommandAsync();

            await inviteDb.InvalidateCache();

            await response.OK();
        }
Exemplo n.º 29
0
        public async Task AddMessage(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <AddMessageRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            if (requestJson.gid <= 0)
            {
                await response.BadRequest("发送目标不正确");

                return;
            }

            //写入新消息
            var newMessage = new message
            {
                content     = requestJson.content,
                update_time = DateTime.Now,
                create_time = DateTime.Now,
                gid         = requestJson.gid,
                uid         = userSession.uid,
                is_read     = 0,
                direction   = 1
            };

            var messageDb = DbFactory.Get <Message>();
            await messageDb.SimpleDb.AsInsertable(newMessage).ExecuteCommandAsync();

            await response.OK();
        }
        public async Task EditPuzzle(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Organizer);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <EditPuzzleRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out string reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //生成修改后对象
            var updatePuzzle = new puzzle
            {
                pid            = requestJson.pid,
                pgid           = requestJson.pgid,
                type           = requestJson.type,
                title          = requestJson.title,
                content        = requestJson.content,
                image          = requestJson.image,
                html           = requestJson.html,
                answer_type    = requestJson.answer_type,
                answer         = requestJson.answer,
                jump_keyword   = requestJson.jump_keyword,
                extend_content = requestJson.extend_content
            };

            var puzzleDb = DbFactory.Get <Puzzle>();
            await puzzleDb.SimpleDb.AsUpdateable(updatePuzzle).ExecuteCommandAsync();

            await puzzleDb.InvalidateCache();

            await response.OK();
        }