Ejemplo n.º 1
0
        public async Task <IActionResult> CheckPin([FromForm(Name = "pinId")] int pinId)
        {
            var pin = await _plexApi.GetPinAsync(pinId);

            // Validation.
            if (pin.ExpiresAt < DateTimeOffset.UtcNow)
            {
                return(Ok(new ApiResponse <CheckPinData>
                {
                    Errors = new[]
                    {
                        new ApiResponseError("The pin has expired, please try again.")
                    },
                    Data = new CheckPinData
                    {
                        Cancel = true,
                        Success = false,
                        Location = null
                    }
                }));
            }

            if (string.IsNullOrEmpty(pin.AuthToken))
            {
                return(Ok(new ApiResponse <CheckPinData>
                {
                    Errors = new[]
                    {
                        new ApiResponseError("User has not signed in yet.")
                    },
                    Data = new CheckPinData
                    {
                        Cancel = false,
                        Success = false,
                        Location = null
                    }
                }));
            }

            // Authenticate.
            await _authService.AuthenticateAsync(pin.AuthToken);

            return(Ok(new ApiResponse <CheckPinData>
            {
                Data = new CheckPinData
                {
                    Cancel = true,
                    Success = true,
                    Location = Url.Action("Index", "Home")
                }
            }));
        }