[Angular+DSP] User Registration

Good Day,

This is my first post and I hope I categorized this into the correct section. I am very interested in DreamFactory for AngularJS and using it in my PhoneGap application. However, I am stuck on the registration procedure.

When I run:

	DreamFactory.api.user.register(data,
	     function(result) {
                     console.log(result);
             },
	     function(error) {
	         console.log(error);
	     }
         );

“data” is the information passed in an object. All is well and works great! What stumps me, is what comes next? All I get back from the result is:

Object {success: true}

How do I get a session? The API Docs say to include the boolean “login: true” and I tried that with a data such as:

	var data = {
            login: true,
            body: {
	        display_name: username,
                email: email,
                password: password
            }
	};

Any help would be greatly appreciated as to how I can get a session token or anything other than just a true boolean.

Many thanks!

Unless you’ve enabled Guest User access in the Config tab (which allows users assigned to a guest role to make API calls without authenticating), you need to first authenticate and get a session token. This session token must be passed on subsequent API calls.

Check out this link https://github.com/dreamfactorysoftware/dsp-core/wiki/Important-Information and some cURL examples https://github.com/dreamfactorysoftware/dsp-core/wiki/cURL-Examples which show both how to authenticate and pass the session token in your API calls.

Also check out this tutorial https://blog.dreamfactory.com/the-authenticated-app-with-angularjs-dreamfactory-user-management-module

There’s an Angular module for user management that will come in handy.

Thank you for the quick response! I see that register just returns success, so afterwards I made a subsequent request to login the user as you suggested. Now I am on on a slightly different issue. Sorry for all the questions!

I am trying to make authenticated calls to the database using the example below:

var record = {
    table_name: 'exampleTable',
    session_id: UserService.getUser().sessionId,
};

DreamFactory.api.db.getRecord(record,
    function(result) {
        console.log(result);	
    },
  function(error) {
      console.log(error);
  });

I already feel like I am passing the session_id incorrectly. I took a look at the in-depth authentication tutorial and it is very impressive. But a little too much of what I am looking for. The angular-dreamfactory module is just perfect for what I am trying to do.

When I run the above code I get:

TypeError: Cannot read property 'getRecord' of undefined

It is in fact defined as I dumped it into the console, console.log(DreamFactory);, and saw it in the object. It’s there, I just must not be using it right.

EDIT:

After scouring the web I landed on a pretty blatant fact - the API did not build yet! Makes sense haha. So I wrapped the call in:

$scope.$on('api:ready', function(event) { });

But now I am left with an unauthorized error with no valid session id. So, I must be passing this incorrectly.

Did you figure out your session ID problem? The AngularJS SDK should provide you a good example of receiving and passing session ID.