168
Views
4
Comments
Assigning a role to a user on runtime
Question
Hi all,

I wanted to know if its possible to create a user and assign a role to said user, all during runtime?

2012-03-16 12-21-09
João Rosado
Staff
Hi Pedro,

Check the How2UserRegistration application in the forge.
It's an example on how to do exaclty what you want.

Not sure if I like the GrantUserManagerRole/RevokeUserManagerRole in the example though.
You don't need that if you are creating a user when your current user already has permissions to do it. (The example is for self registration and the User_Create action from users makes a permission check)

The only thing the User_Create is to check for existing username and call the entity CreateUser action.
It's probably better to do that directly instead of giving the UserManagerRole temporarily to a new user just to be able to call User_Create.


Regards,
João Rosado
2016-04-21 20-09-55
J.
 
MVP
In short, yes :)



2015-09-15 16-46-08
PBrito
Man this what I'm loving about Outsystems, there's a module for everything! :)
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
For those finding this topic and not wanting to check the forge application, here are the steps:

1) Create a user by referencing the User system table and call the CreateUser entity action (filling in the right attributes etc. Use the EncryptPassword function from the Users eSpace to encrypt the password);
2) Grant roles to that user by calling the appropriate GrantXxxRole actions (where Xxx is the role name). You can find these below the Roles themselves. (Unfortunately, there's no generic action that lets you grant a role based purely on its name.)
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.