public async Task <IActionResult> ConnectLauncher([Required] LauncherLinkCodeCheckForm request)
        {
            Response.ContentType = "application/json";
            var user = await GetUserForNewLink(request.Code);

            // Update user to consume the code
            user.LauncherCodeExpires = DateTime.UtcNow - TimeSpan.FromSeconds(1);
            user.LauncherLinkCode    = null;
            user.TotalLauncherLinks += 1;

            // Create a new code, which the user doesn't directly see to avoid it leaking as easily
            var code = NonceGenerator.GenerateNonce(42);

            var remoteAddress = HttpContext.Connection.RemoteIpAddress;

            await database.LauncherLinks.AddAsync(new LauncherLink()
            {
                User           = user,
                LinkCode       = code,
                LastIp         = remoteAddress?.ToString(),
                LastConnection = DateTime.UtcNow
            });

            await database.LogEntries.AddAsync(new LogEntry()
            {
                Message      = $"New launcher link created from: {remoteAddress}",
                TargetUserId = user.Id
            });

            await database.SaveChangesAsync();

            logger.LogInformation("New launcher linked to user {Id} from {RemoteAddress}", user.Id, remoteAddress);

            return(Created(string.Empty, new LauncherLinkResult(true, code)));
        }
        public async Task <ActionResult <LauncherConnectionStatus> > CheckNewLinkCode(
            [Required] LauncherLinkCodeCheckForm request)
        {
            Response.ContentType = "application/json";
            var user = await GetUserForNewLink(request.Code);

            return(new LauncherConnectionStatus()
            {
                Valid = true,
                Username = user.UserName ?? user.Email,
                Email = user.Email,
                Developer = user.HasAccessLevel(UserAccessLevel.Developer)
            });
        }