Quantcast
Channel: DreamFactory Forum - Latest posts
Viewing all articles
Browse latest Browse all 5028

How to create users while registering with different roles via API?

$
0
0

Hi, @ramnew2006

I understand your scenario.
I follow a path that should have worked, I think may be a bug, @drewpearce could confirm this.

1 - I created an event script user.register.post.post_process

var lodash = require("lodash.min.js");

var role1Id = 2;
var role2Id = 3;

var appVendorId = 2;
var appCustomerId = 3;

if (!!event.request.payload.type && !!platform.session.user) {
  var userObject = platform.api.get('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id');

  lodash._.each(userObject.user_to_app_to_role_by_user_id, function(userApp) {
    switch (event.request.payload.type) {
      case 'customer':
        if (userApp.app_id === appCustomerId) {
          userApp.role_id = role1Id;
        }
        break;
      case 'vendor':
        if (userApp.app_id === appVendorId) {
          userApp.role_id = role2Id;
        }
        break;
     }
   });

  platform.api.patch('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id', userObject);
}

2 - In addition to the standard body of the user registration request, I added the 'type' attribute to JSON

{
  "email": "string",
  "first_name": "string",
  "last_name": "string",
  "display_name": "string",
  "new_password": "string",
  "type": "string"
}

3 - To be available section during script execution, the query string passed login = true

http://localhost/api/v2/user/register?login=true

4 - I configured a role to access via SCRIPT to the system / user with GET and PATCH. And it was here that something went wrong.

Follows the settings made:






If it is not a bug, I have no other idea how to do :pensive:


Viewing all articles
Browse latest Browse all 5028

Trending Articles