diff --git a/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs index 1bc3b55..6288dd1 100644 --- a/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs +++ b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs @@ -167,5 +167,19 @@ public async Task DeleteAccount(string currentPassword) await _sessionManager.ClearSession(); } + + public async Task MigrateAccount(string currentPassword, string service, string identifier) + { + var uri = new Uri($"{baseUrl}/migrate"); + string content = JsonUtility.ToJson(new PlayerAuthMigrateAccountRequest { + currentPassword = currentPassword, + service = service, + identifier = identifier + }); + var json = await Call(uri, "POST", content); + + var res = JsonUtility.FromJson(json); + await _sessionManager.HandleAccountMigrated(res); + } } } diff --git a/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerAuthMigrateAccountRequest.cs b/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerAuthMigrateAccountRequest.cs new file mode 100644 index 0000000..ac0d541 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerAuthMigrateAccountRequest.cs @@ -0,0 +1,10 @@ +namespace TaloGameServices +{ + [System.Serializable] + public class PlayerAuthMigrateAccountRequest + { + public string currentPassword; + public string service; + public string identifier; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerAuthMigrateAccountRequest.cs.meta b/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerAuthMigrateAccountRequest.cs.meta new file mode 100644 index 0000000..f2bf1c9 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Requests/PlayerAuthMigrateAccountRequest.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: da0b6376123d24cd1b0afd97c6144877 \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerAuthMigrateAccountResponse.cs b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerAuthMigrateAccountResponse.cs new file mode 100644 index 0000000..8cd4eeb --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerAuthMigrateAccountResponse.cs @@ -0,0 +1,8 @@ +namespace TaloGameServices +{ + [System.Serializable] + public class PlayerAuthMigrateAccountResponse + { + public PlayerAlias alias; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerAuthMigrateAccountResponse.cs.meta b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerAuthMigrateAccountResponse.cs.meta new file mode 100644 index 0000000..0faea94 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Responses/PlayerAuthMigrateAccountResponse.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: dc41a5cdf5fc940658d7a99cec0bcd7c \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/Utils/PlayerAuthException.cs b/Assets/Talo Game Services/Talo/Runtime/Utils/PlayerAuthException.cs index 9852771..565b7b2 100644 --- a/Assets/Talo Game Services/Talo/Runtime/Utils/PlayerAuthException.cs +++ b/Assets/Talo Game Services/Talo/Runtime/Utils/PlayerAuthException.cs @@ -15,7 +15,8 @@ public enum PlayerAuthErrorCode { PASSWORD_RESET_CODE_INVALID, VERIFICATION_EMAIL_REQUIRED, INVALID_EMAIL, - NEW_IDENTIFIER_MATCHES_CURRENT_IDENTIFIER + NEW_IDENTIFIER_MATCHES_CURRENT_IDENTIFIER, + INVALID_MIGRATION_TARGET } public class PlayerAuthException : Exception diff --git a/Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs b/Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs index 6ac0fab..3fba573 100644 --- a/Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs +++ b/Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs @@ -26,11 +26,14 @@ private void SaveSession(string sessionToken) SetIdentifierPlayerPref(); } - public async Task ClearSession() + public async Task ClearSession(bool resetSocket = true) { Talo.CurrentAlias = null; PlayerPrefs.DeleteKey("TaloSessionToken"); - await Talo.Socket.ResetConnection(); + if (resetSocket) + { + await Talo.Socket.ResetConnection(); + } } public string GetSessionToken() @@ -48,11 +51,23 @@ public bool CheckForSession() return !string.IsNullOrEmpty(GetSessionToken()); } + private void SetNewAlias(PlayerAlias alias) + { + Talo.CurrentAlias = alias; + alias.WriteOfflineAlias(); + } + public void HandleIdentifierUpdated(PlayerAuthChangeIdentifierResponse res) { - Talo.CurrentAlias = res.alias; - Talo.CurrentAlias.WriteOfflineAlias(); + SetNewAlias(res.alias); SetIdentifierPlayerPref(); } + + public async Task HandleAccountMigrated(PlayerAuthMigrateAccountResponse res) + { + await ClearSession(false); + SetNewAlias(res.alias); + Talo.Players.InvokeIdentifiedEvent(); + } } }