Exemplo n.º 1
0
        private ActionResult ProcessSteamOpenIDResponse(IAuthenticationResponse response)
        {
            switch (response.Status)
            {
            case AuthenticationStatus.Authenticated:
                var   steamIDStr = response.FriendlyIdentifierForDisplay.Split('/').LastOrDefault();
                ulong steamID;
                if (ulong.TryParse(steamIDStr, out steamID))
                {
                    var referer = response.GetCallbackArgument("referer");
                    using (var db = new ZkDataContext())
                    {
                        var acc = db.Accounts.FirstOrDefault(x => x.SteamID == steamID);
                        if (acc != null)
                        {
                            FormsAuthentication.SetAuthCookie(acc.Name, true);
                            if (string.IsNullOrEmpty(referer))
                            {
                                referer = Url.Action("Index");
                            }
                            return(Redirect(referer));
                        }
                        else
                        {
                            return(Content("Please download the game and create an account in-game first"));
                        }
                    }
                }
                break;

            case AuthenticationStatus.Canceled:
                return(Content("Login was cancelled at the provider"));

            case AuthenticationStatus.Failed:
                return(Content("Login failed"));
            }
            return(View("HomeIndex"));
        }