The user login operation opens a communication channel between your game and your Server. When the login occurs without problems, the UniREST Server application replies with a set of data which is required for the next communication and for the correct functioning of the whole system. The server-side reply consists of:
- the ID of the user account;
- the security Tokens needed for authorizing the operations on your Server.
The login is performed by the Login() method. It just requires the user account username and password:
Parameter | Data-type | Description |
username | string | The user username. The maximum allowed length is 32 characters. |
password | string | The user password. |
callBack | Action<bool> | The function to call or the code to execute at operations completed. |
Returned value | Description |
bool | This method just returns true or false. |
If the user login occurs without problems, this method returns true. The system data received from the Server (user’s ID and tokens) gets integrated into the UniREST system.
If something goes wrong and the login fails, this method returns false.
_ = UniRESTClient.Async.Login("pluto", "planet9", (bool ok) =>
{
if (ok)
{
Debug.Log("Login done!");
}
else
{
Debug.Log("Login failed!");
}
});
User ID
The user account ID, that the UniREST Client receives after a successful login, is stored into the UniRESTClient class and is always available in the UserID property:
You can always refer to this property when you need to do something with the user ID (for example, you want to update a record that contains the user ID).
User Account details
Once the user logged-in, the UniRESTClient class userAccount property is initialized with the user account-related data.
userAccount property | Data-type | Description |
.username | string | The current user’s username. |
.password | string | The current user’s password. |
.lastLoginDate | string | The date of the last performed login. |
.registrationDate | string | The date when this account has been registered. |
_ = UniRESTClient.Async.Login("pluto", "planet9", (bool ok) =>
{
if (ok)
{
Debug.Log("Login done!");
Debug.Log("pluto is here from: " + UniRESTClient.userAccount.registrationDate);
Debug.Log("Last access: " + UniRESTClient.userAccount.lastLoginDate);
}
else
{
Debug.Log("Login failed!");
}
});