App42 create user in unity

416 views Asked by At

I'm totally new in this, anyway I have downloaded the sample file for unity and I have passed the API key and secret key in constant file.

when I run the file in the unity editor I got many buttons, I tried to click (create user) but I got this error

App42Exception: EmailAddress is Not Valid com.shephertz.app42.paas.sdk.csharp.util.Util.ThrowExceptionIfEmailNotValid (System.Object obj, System.String name) com.shephertz.app42.paas.sdk.csharp.user.UserService.CreateUser (System.String uName, System.String pwd, System.String emailAddress, App42CallBack callBack) UserTest.OnGUI () (at Assets/scripts/UserTest.cs:49)

======================================

I have change

public string emailId = ""; // EmailId for the user creation

constant.cs script file

and this should work without error. well I tried this and I still gets the same error.

======================================

Do you know where can I find a sample file to create a user that contain three input field to put an email, user and password and a button to create a user. I want a sample unity file that contain all the code required to do that, the only thing I have to modify is the secret and API key.

I just want to know how this works, I found sample file that came with the SDK complicated. So I want a sample file that have "create user" to use it in Unity (C#).

I'm trying to create a simple 2D game in unity that required the user to create an account (username, email, password), but I didn't find enough tutorials and instructions to do that. I'm new in programming so please bear with me.

1

There are 1 answers

3
Cenkisabi On

In documentation of App42, if you don't start from the "Getting Started" you miss a lot of things.

If you want to create user, firstly you should import

using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.user;

then there is a simple code that I used

public class App42Manager : MonoBehaviour {

    private const string apiKey = "******";
    private const string secretKey = "*****";

    //Service for creating, authenticating, deleting, updating User.
    private UserService userService;

    //User object that keeps informations about user.
    public static User user = new User();

    string username = "";
    string password = "";
    string email = "";

    void Start () {
        App42API.Initialize(apiKey,secretKey);
        userService = App42API.BuildUserService();  
    }

    // call this function when user enter all informations and click button
    void CreateUser(string usrnm,string psswrd, string eml) 
    {
        username = usrnm;
        password = psswrd;
        email = eml;

        //You can write your own conditions here.
        if(!username.Equals("") && !password.Equals("") && !email.Equals("")
            userService.CreateUser(username,password,email,CreateUserCallBack());
    }
}

public class CreateUserCallBack : App42CallBack
{
    public void OnSuccess(object response)
    {
        User user = (User)response;
        /* This will create user in App42 cloud and will return User object */

        Debug.Log("CreateUser: userName is" + user.GetUserName());
        Debug.Log("CreateUser: email is" + user.GetEmail());

        App42Manager.user = this.user;
    }

    public void OnException(System.Exception e)
    {
        Debug.Log("CreateUser: Exception : " + e);
    }
}