Hello
How can I add custom data such as "Phone" or "name" to the registration form, from the app in unity?
Thanks!!!
Hi, first of all I suggest to create your own user class inheriting from Combu.User, you can see an example in the API documentation and inside the demo class CombuDemoUser (basically you'll create a class inheriting from User and add properties to easily wrap around the customData).
An example of class could be:
public class YourUserClass : Combu.User { string _name = ""; string _phone = ""; public string Name { get { return _name; } set { _name = value; customData["name"] = _name; } } public string Phone { get { return _phone; } set { _phone = value; customData["phone"] = _phone; } } public YourUserClass() { Name = ""; Phone = ""; } public override void FromHashtable (Hashtable hash) { // Set User class properties base.FromHashtable (hash); // Set our own custom properties that we store in customData if (customData.ContainsKey("name")) _name = customData["name"].ToString(); if (customData.ContainsKey("phone")) _phone = customData["phone"].ToString(); } }
Add the UI fields to the Canvas, then create a script similar to /Combu/Demo/Scripts/CombuDemo (we suggest to create your own scripts copying the code from CombuDemo and CombuDemoScene script instead of modifying the original files), add the properties for the new fields in your script (for example: public InputField registerName and public InputField registerPhone) and drag the UI fields to these properties in the Inspector panel of Unity editor, finally add the code to set your Name and Phone properties in your UserRegister method before calling update (for example after the setting of user.userName and user.password from their input fields):
public void UserRegister() { if (string.IsNullOrEmpty(registerUsername.text) || string.IsNullOrEmpty(registerPassword.text)) { registerError.text = "Enter your credentials"; return; } YourUserClass user = new YourUserClass(); user.userName = registerUsername.text; user.password = registerPassword.text; user.Name = registerName.text; user.Phone = registerPhone.text; registerError.text = "Loading..."; user.Update((bool success, string error) => { registerError.text = ""; if (success) { registerUsername.text = ""; registerPassword.text = ""; registerName.text = ""; registerPhone.text = ""; registerError.text = "Account created!"; } else { registerError.text = "Registration failed: " + error; } }); }
In your login function (you can see an example in CombuDemoScene.UserLogin) remember to use the overload CombuManager.platform.Authenticate< YourUserClass >() to authenticate the user (like you see in the API page linked above), so that you can later safely cast CombuManager.localUser to YourUserClass after the user has been authenticated.
FRANCESCO CROCETTI @ SKARED CREATIONS