Beispiel #1
0
        /// <summary>
        /// Authenticate a user in PlayFab using an Email & Password combo
        /// </summary>
        protected virtual async Task AuthenticateEmailPassword()
        {
            //Check if the users has opted to be remembered.
            if (RememberMe && !string.IsNullOrEmpty(RememberMeId))
            {
                //If the user is being remembered, then log them in with a customid that was
                //generated by the RememberMeId property
                var customIdResult = await PlayFabClient.LoginWithCustomIDAsync(new LoginWithCustomIDRequest()
                {
                    TitleId               = PlayFabSettings.staticSettings.TitleId,
                    CustomId              = RememberMeId,
                    CreateAccount         = true,
                    InfoRequestParameters = this.InfoRequestParams
                }).ConfigureAwait(false);

                LoginResult(customIdResult);

                return;
            }
            else if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password))
            {
                //a good catch: If username & password is empty, then do not continue, and Call back to Authentication UI Display
                OnDisplayAuthentication.Invoke();
                return;
            }
            else
            {
                //We have not opted for remember me in a previous session, so now we have to login the user with email & password.
                var emailResult = await PlayFabClient.LoginWithEmailAddressAsync(new LoginWithEmailAddressRequest()
                {
                    TitleId  = PlayFabSettings.staticSettings.TitleId,
                    Email    = this.Email,
                    Password = this.Password,
                    InfoRequestParameters = this.InfoRequestParams
                }).ConfigureAwait(false);

                //Note: At this point, they already have an account with PlayFab using a Username (email) & Password
                //If RememberMe is checked, then generate a new Guid for Login with CustomId.
                if (RememberMe)
                {
                    RememberMeId = Guid.NewGuid().ToString();
                    AuthType     = AuthType.EmailAndPassword;

                    //Fire and forget, but link a custom ID to this PlayFab Account.
                    await PlayFabClient.LinkCustomIDAsync(new LinkCustomIDRequest()
                    {
                        CustomId  = RememberMeId,
                        ForceLink = ForceLink
                    }).ConfigureAwait(false);
                }

                LoginResult(emailResult);
            }
        }