public async Task <WebQueryResult> ProcessRequest(string query, CallbackTypeEnum type, string ip, WebAuthUserData data)
        {
            if (!Settings.Config.ModuleContractNotifications)
            {
                return(WebQueryResult.False);
            }

            try
            {
                RunningRequestCount++;
                if (!query.Contains("&state=12"))
                {
                    return(WebQueryResult.False);
                }

                var prms = query.TrimStart('?').Split('&');
                var code = prms[0].Split('=')[1];

                var result = await WebAuthModule.GetCharacterIdFromCode(code,
                                                                        Settings.WebServerModule.CcpAppClientId, Settings.WebServerModule.CcpAppSecret);

                if (result == null)
                {
                    return(WebQueryResult.EsiFailure);
                }

                var characterId   = result[0];
                var numericCharId = Convert.ToInt64(characterId);

                if (string.IsNullOrEmpty(characterId))
                {
                    await LogHelper.LogWarning("Bad or outdated feed request!");

                    var r = WebQueryResult.BadRequestToSystemAuth;
                    r.Message1 = LM.Get("accessDenied");
                    return(r);
                }

                if (!HasAuthAccess(numericCharId))
                {
                    await LogHelper.LogWarning($"Unauthorized feed request from {characterId}");

                    var r = WebQueryResult.BadRequestToSystemAuth;
                    r.Message1 = LM.Get("accessDenied");
                    return(r);
                }

                if (WebGetAuthGroup(numericCharId, out _) == null)
                {
                    await LogHelper.LogWarning("Feed auth group not found!");

                    var r = WebQueryResult.BadRequestToSystemAuth;
                    r.Message1 = LM.Get("accessDenied");
                    return(r);
                }

                //var rChar = await APIHelper.ESIAPI.GetCharacterData(Reason, characterId, true);

                await SQLHelper.InsertOrUpdateTokens("", characterId, "", result[1]);

                await LogHelper.LogInfo($"Mail feed added for character: {characterId}", LogCat.AuthWeb);

                var res = WebQueryResult.ContractsAuthSuccess;
                res.Message1 = LM.Get("mailAuthSuccessHeader");
                res.Message2 = LM.Get("mailAuthSuccessBody");
                res.AddValue("url", ServerPaths.GetFeedSuccessUrl());
                return(res);
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);
            }
            finally
            {
                RunningRequestCount--;
            }

            return(WebQueryResult.False);
        }
Exemplo n.º 2
0
        public async Task <WebQueryResult> ProcessRequest(string query, CallbackTypeEnum type, string ip, WebAuthUserData data)
        {
            if (!Settings.Config.ModuleNotificationFeed)
            {
                return(WebQueryResult.False);
            }

            try
            {
                RunningRequestCount++;
                if (query.Contains("&state=9"))
                {
                    //var prms = QueryHelpers.ParseQuery(query);
                    var prms = query.TrimStart('?').Split('&');
                    var code = prms[0].Split('=')[1];

                    var result = await WebAuthModule.GetCharacterIdFromCode(code,
                                                                            Settings.WebServerModule.CcpAppClientId, Settings.WebServerModule.CcpAppSecret);

                    if (result == null)
                    {
                        return(WebQueryResult.EsiFailure);
                    }

                    var characterId   = result[0];
                    var numericCharId = Convert.ToInt64(characterId);

                    if (string.IsNullOrEmpty(characterId))
                    {
                        await LogHelper.LogWarning("Bad or outdated notify feed request!");

                        var r = WebQueryResult.BadRequestToSystemAuth;
                        r.Message1 = LM.Get("authTokenBodyFail");
                        r.Message2 = LM.Get("authTokenBadRequest");
                        return(r);
                    }

                    if (!TickManager.GetModule <NotificationModule>().IsValidCharacter(numericCharId))
                    {
                        await LogHelper.LogWarning($"Unauthorized notify feed request from {characterId}");

                        var r = WebQueryResult.BadRequestToSystemAuth;
                        r.Message1 = LM.Get("authTokenBodyFail");
                        return(r);
                    }

                    var rChar = await APIHelper.ESIAPI.GetCharacterData(Reason, characterId, true);

                    await SQLHelper.InsertOrUpdateTokens(result[1] ?? "", characterId, null, null);

                    await LogHelper.LogInfo($"Notification feed added for character: {characterId}", LogCat.AuthWeb);

                    var res = WebQueryResult.GeneralAuthSuccess;
                    res.Message1 = LM.Get("authTokenRcv");
                    res.Message2 = LM.Get("authTokenRcv2", rChar.name);
                    res.AddUrl(ServerPaths.GetFeedSuccessUrl());
                    return(res);
                }
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);
            }
            finally
            {
                RunningRequestCount--;
            }

            return(WebQueryResult.False);
        }