public async Task <IActionResult> NewShip(IFormCollection request)
        {
            string hullType = request._str("ship_name");
            int    queue_id = request._int("queue_id");

            ShipType ship = await _Db.ShipTypes.Where(c => c.Name.ToLower() == hullType.ToLower()).FirstOrDefaultAsync();

            if (ship != null)
            {
                ship.Queue = (Queue)queue_id;
                await _Db.SaveChangesAsync();

                return(Accepted());
            }

            SearchResults x = await EsiWrapper.Search(hullType, true, SearchCategory.InventoryType);

            if (x.InventoryTypes == null)
            {
                return(NotFound($"{hullType} could not be found. Is the name spelt correctly?"));
            }

            await _Db.AddAsync(new ShipType
            {
                Id    = (int)x.InventoryTypes[0],
                Name  = hullType,
                Queue = (Queue)queue_id
            });

            await _Db.SaveChangesAsync();

            return(Ok());
        }
コード例 #2
0
        EnsureInDatabase(int typeId, Data.WaitlistDataContext _Db)
        {
            ShipType ship = await _Db.ShipTypes.FindAsync(typeId);

            if (ship != null)
            {
                return;
            }

            var esiResponse = await EsiWrapper.GetShipTypeAsync(typeId);

            if (esiResponse.FirstOrDefault() == null)
            {
                return;
            }

            ship = new ShipType
            {
                Id   = typeId,
                Name = esiResponse[0].Name
            };

            await _Db.AddAsync(ship);

            await _Db.SaveChangesAsync();

            return;
        }
コード例 #3
0
        public async Task <IActionResult> Fit(IFormCollection request)
        {
            int currentFits = await _Db.Fits.Where(c => c.AccountId == User.AccountId() && !c.IsShipScan && c.DeletedAt == null).CountAsync();

            // Accounts are only allowed five fits at a time
            if (currentFits >= 5)// Does not take into account fits added by an FC through the fit scanner
            {
                return(BadRequest("You have reached your five ship limit. Please delete a ship before saving a new one"));
            }

            FitDna fitUrlObject;

            try
            {
                fitUrlObject = Util.ParseFitDna(request._str("fitUrl"));

                await ShipType.EnsureInDatabase(fitUrlObject.ship_typeId, _Db);

                Fit newFit = new Fit
                {
                    AccountId   = User.AccountId(),
                    ShipTypeId  = fitUrlObject.ship_typeId,
                    FittingDNA  = fitUrlObject.dna,
                    Description = fitUrlObject.description,
                    IsShipScan  = false,
                    CreatedAt   = DateTime.UtcNow
                };

                // Save new fit
                await _Db.AddAsync(newFit);

                await _Db.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                _Logger.LogError("{0} submitted an invalid fit URL {1}: {2}", User.AccountName(), request._str("fitUrl"), ex.Message);
                return(BadRequest(ex.Message));
            }
        }
コード例 #4
0
        public async Task <IActionResult> SaveAnnouncment(IFormCollection request)
        {
            try
            {
                Announcement announcement = new Announcement
                {
                    CreatorAdminId = User.AccountId(),
                    Type           = request._str("type") != "" ? request._str("type") : "primary",
                    Message        = request._str("message"),
                    CreatedAt      = DateTime.UtcNow
                };

                await _Db.AddAsync(announcement);

                await _Db.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                _Logger.LogError("Error creating an announcment. The admin was {0}: {1}", User.AccountName(), ex.Message);
                return(BadRequest(ex.Message));
            }
        }
コード例 #5
0
        public async Task <IActionResult> Callback(string code, string state)
        {
            // Verify a code and state query parameter was returned.
            if (code == null || state == null)
            {
                _Logger.LogWarning("GICE Callback Error: One or more of the query parameters are missing. State: {0}. Code: {1}", state, code);
                return(StatusCode(452));
            }

            // Verify the state to protect against CSRF attacks.
            if (HttpContext.Session.GetString("state") != state)
            {
                _Logger.LogWarning("GICE Callback Error: Invalid state returned.");
                HttpContext.Session.Remove("state");
                return(StatusCode(452));
            }

            // Clear the state session
            HttpContext.Session.Remove("state");

            // Set the callback URL
            _GiceConfig.CallbackUrl = Url.Action("Callback", "Gice", null, "https").ToLower();

            GiceClientv2 gice = new GiceClientv2(_GiceConfig);
            Dictionary <string, string> ClaimsDict = gice.VerifyCode(code);


            if (ClaimsDict.Count == 0)
            {
                _Logger.LogWarning("GICE Callback Error: The JwtVerify method failed.");
                return(StatusCode(452));
            }

            // Do we have an account for this GSF User?
            int gice_id          = int.Parse(ClaimsDict["sub"]);
            var waitlist_account = await _Db.Accounts.FindAsync(gice_id);

            if (waitlist_account != null)
            {
                // Update and save user account
                waitlist_account.Name        = ClaimsDict["name"];
                waitlist_account.LastLogin   = DateTime.UtcNow;
                waitlist_account.LastLoginIP = _RequestorIP.MapToIPv4().ToString();

                await _Db.SaveChangesAsync();
            }
            else
            {
                // User doesn't exist, create a new account
                waitlist_account = new Account()
                {
                    Id                  = gice_id,
                    Name                = ClaimsDict["name"],
                    RegisteredAt        = DateTime.UtcNow,
                    JabberNotifications = true,
                    LastLogin           = DateTime.UtcNow,
                    LastLoginIP         = _RequestorIP.MapToIPv4().ToString()
                };

                await _Db.AddAsync(waitlist_account);

                await _Db.SaveChangesAsync();
            }

            // Attempt to log the user in
            await LoginUserUsingId(waitlist_account.Id);

            _Logger.LogDebug("{0} has logged in.", ClaimsDict["name"]);

            return(Redirect("~/pilot-select"));
        }
コード例 #6
0
        public async Task <IActionResult> Callback(string code, string state)
        {
            // Verify a code and state query parameter was returned.
            if (code == null || state == null)
            {
                _Logger.LogWarning("Eve Callback Error: One or more of the query parameters are missing. State: {0}. Code: {1}", state, code);
                return(StatusCode(452));
            }

            // Verify the state to protect against CSRF attacks.
            if (HttpContext.Session.GetString("state") != state)
            {
                _Logger.LogWarning("Eve Callback Error: Invalid state returned.");
                HttpContext.Session.Remove("state");
                return(StatusCode(452));
            }

            // Clear the state session
            HttpContext.Session.Remove("state");


            ESI.NET.EsiClient s_client = EsiWrapper.GetEsiClient();

            SsoToken token = await s_client.SSO.GetToken(GrantType.AuthorizationCode, code);

            AuthorizedCharacterData n_pilot = await s_client.SSO.Verify(token);


            long corporation_id = (long)n_pilot.CorporationID;

            Corporation.EnsureInDatabase(corporation_id, _Db);

            var pilot = await _Db.Pilots.FindAsync(n_pilot.CharacterID);

            if (pilot == null)
            {
                // User doesn't exist, create a new account
                pilot = new Pilot()
                {
                    CharacterID   = n_pilot.CharacterID,
                    AccountId     = User.AccountId(),
                    CharacterName = n_pilot.CharacterName,
                    CorporationID = corporation_id,
                    RefreshToken  = n_pilot.RefreshToken,
                    Token         = n_pilot.Token,
                    UpdatedAt     = DateTime.UtcNow,
                    RegisteredAt  = DateTime.UtcNow,
                };

                await _Db.AddAsync(pilot);

                await _Db.SaveChangesAsync();

                _Logger.LogDebug("{0} has linked the pilot {1} to their account.", User.FindFirst("name").Value, pilot.CharacterName);

                //TODO: alert user that it worked
                return(Redirect("/pilot-select"));
            }
            else if (!pilot.IsLinked() || pilot.BelongsToAccount(int.Parse(User.FindFirst("id").Value)))
            {
                // Update the pilot information - This may include a new account if it was unlinked.
                pilot.AccountId     = User.AccountId();
                pilot.CharacterName = n_pilot.CharacterName;
                pilot.CorporationID = corporation_id;
                pilot.RefreshToken  = n_pilot.RefreshToken;
                pilot.Token         = n_pilot.Token;
                pilot.UpdatedAt     = DateTime.UtcNow;

                await _Db.SaveChangesAsync();

                _Logger.LogDebug("{0} has updated the pilot {1} that is linked to their account.", User.FindFirst("name").Value, pilot.CharacterName);

                //TODO: alert user that it worked
                return(Redirect("/pilot-select"));
            }

            //TODO: alert user that it failed
            _Logger.LogDebug("{0} has tried to link {1} to their account, however it is linked to someone else’s account.", User.AccountName(), pilot.CharacterName);
            return(Redirect("/pilot-select"));
        }
コード例 #7
0
        public async Task <IActionResult> Index(IFormCollection request)
        {
            string EsiUrl = request._str("EsiFleetUrl");
            long   fleetId;

            try
            {
                fleetId = request._str("EsiFleetUrl").GetEsiId();
            }
            catch (Exception ex)
            {
                _Logger.LogError("Cannot parse the ESI Fleet ID from the URL provided. {0}", EsiUrl);
                return(BadRequest(string.Format("Cannot parse the ESI Fleet ID from the URL provided. {0}\n{1}", EsiUrl, ex.Message)));
            }

            int   bossId = request._int("fleetBoss");
            Pilot pilot  = await _Db.Pilots.Where(c => c.CharacterID == bossId && c.AccountId == User.AccountId()).FirstOrDefaultAsync();

            if (pilot == null)
            {
                return(NotFound("Pilot not found, or you do not have access to it."));
            }

            string fleetType = request._str("FleetType");

            //Is there an active fleet with this ID? IF yes redirect to that fleet else continue
            var fleet = await _Db.Fleets.Where(c => c.EveFleetId == fleetId && c.ClosedAt == null).FirstOrDefaultAsync();

            if (fleet != null)
            {
                // Fleet already registered let's redirect the user to that page.
                return(Ok(fleet.Id));
            }

            CommChannel comms = await _Db.CommChannels.FindAsync(request._int("FleetComms"));

            if (comms == null)
            {
                // Fleet comms not found
                _Logger.LogError("Invalid Comms channel provided.");
            }


            // TODO: Can we actually ESI into this fleet?
            if (false)
            {
                _Logger.LogWarning("(ID: {0}) does not have access to fleet {1}.", bossId, fleetId);
                return(Forbid("Pilot selected does not have access to that fleet. Check you selected the correct fleet boss!"));
            }

            Fleet newFleet = new Fleet
            {
                EveFleetId    = fleetId,
                BossPilot     = pilot,
                CommChannelId = comms.Id,
                IsPublic      = false,
                Type          = fleetType,
                CreatedAt     = DateTime.UtcNow,
                UpdatedAt     = DateTime.UtcNow
            };

            await _Db.AddAsync(newFleet);

            await _Db.SaveChangesAsync();

            // Redirect to page!
            return(Ok(newFleet.Id));
        }