question

Chethan V avatar image
Chethan V asked

How do I restrict users from login in if they have not verified their email id

Hi I have successfully able to create a signup system and send a verification mail on signup after following this guide.(I am asking here because the same question elsewhere is in moderation forever)

I know that contact email and playfab login email are different, but while signup I have made sure that contact email is same as playfab login email.

Now my question is how do I restrict the user from logging in if he/she has not yet verified the email. I found this code in this post, but I dont understand where and how do you run this code. If somehow I can run a piece of code and get what is the verification status under contact email (because it is "pending" if the link is not clicked and "confirmed" if the link is clicked) my job is done, but how do I do it?

By the way the login I have implemented is via username and password.You can find the code here

private void LoginWithUserNamePassword()//earlier LoginWithCustomID function was used
    {
        Debug.Log($"Login to PlayFab as {UserNameInput.text}");
        var request = new LoginWithPlayFabRequest
        {
            Username = UserNameInput.text,
            Password = passwordInput.text,
        };
        PlayFabClientAPI.LoginWithPlayFab(request, OnLoginUserNamePasswordSuccess, onFailure);
    }
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

You can try the code below to get the verification status.

PlayFabClientAPI.LoginWithPlayFab(new LoginWithPlayFabRequest
        {
            Username = "Gosen",
            Password = "123456",
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
            {
                GetPlayerProfile = true,
                ProfileConstraints = new PlayerProfileViewConstraints
                {
                    ShowContactEmailAddresses = true
                }
            }
        }, result=> {
            Debug.Log(result.InfoResultPayload.PlayerProfile.ContactEmailAddresses[0].VerificationStatus);
        }, error=>{
            Debug.LogError(error.GenerateErrorReport());
        });

If you find the status is Unverified, you can remove the SessionCookie and EntityToken then tell the player to verify the email.

Please note that PlayFab doesn't allow the client to get the contact email address by default. To get it, you can navigate to [Game Manager]->[Title Settings]->[Client Profile Options], and enable the Contact email address.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Chethan V avatar image Chethan V commented ·

@Gosen Gao first, sorry for the late response......your answer works perfectly. Thats really awesome and many many thanks for the same.

But still one question, to remove the SessionCookie and EntityToken ,

 PlayFabClientAPI.ForgetAllCredentials();

right? because as you know Playfab is a stateless or you need to do something else

0 Likes 0 ·
Chethan V avatar image Chethan V Chethan V commented ·

@Gosen Gao r u there reading this?

0 Likes 0 ·
Chethan V avatar image Chethan V commented ·

run that command

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.