public IActionResult GetTokenEndpoint(string token)
        {
            // Use the proivded token from the URL to check against the status of that tokens link
            var t = HttpUtility.HtmlDecode(token);

            switch (_linkService.GetLinkStatus(t))
            {
            case AccountLinkService.LinkStatus.Ready:
                // If it is ready (discord and faf account sign in completed)
                // then save the link, and tell the user.
                _ = Task.Run(async() => await _linkService.FinalizeLink(token));

                return(Ok("Accounts linked successfully."));

            case AccountLinkService.LinkStatus.Waiting:
                // If it is waiting, clear any errors, save the token as a cookie,
                // and start the process at the login endpoint.
                Response.Cookies.Delete("error");
                Response.Cookies.Append("token", token);
                return(Redirect("/api/link/login"));

            case AccountLinkService.LinkStatus.Invalid:
                // If it is invalid (or default), notify the user.
                return(BadRequest("Token is invalid or not found."));

            default:
                return(BadRequest("Token is invalid, not found, or an unknown error occoured."));
            }
        }
Exemple #2
0
        public async Task <IActionResult> GetTokenEndpoint(string token)
        {
            // Use the proivded token from the URL to check against the status of that tokens link
            var t = HttpUtility.HtmlDecode(token);

            switch (_linkService.GetLinkStatus(t))
            {
            case AccountLinkService.LinkStatus.Ready:
                // If it is ready (discord and steam account sign in completed)
                // then save the link, and tell the user.
                var reLogin = await _linkService.FinalizeLink(token);

                var res = await _signInManager.PasswordSignInAsync(reLogin.Item1, reLogin.Item2, reLogin.Item3, false);

                if (res.Succeeded)
                {
                    return(Redirect("~/"));
                }
                else
                {
                    return(Redirect("/Identity/Account/Login"));
                }

            case AccountLinkService.LinkStatus.Waiting:
                // If it is waiting, clear any errors, save the token as a cookie,
                // and start the process at the login endpoint.
                Response.Cookies.Delete("error");
                Response.Cookies.Append("token", token);
                return(Redirect("/api/link/login"));

            case AccountLinkService.LinkStatus.Invalid:
                // If it is invalid (or default), notify the user.
                return(BadRequest("Token is invalid or not found."));

            default:
                return(BadRequest("Token is invalid, not found, or an unkown error occoured."));
            }
        }