AddUserToRoles Method
Syntax
Context.Security.AddUserToRoles as L (UserName as C, RoleNames as C)
Arguments
- UserNameCharacter
The user name.
- RoleNamesCharacter
The names of the roles to which the user will be added. Role names are separated by crlf.
Returns
- resultLogical
Returns .T. if the role was added; otherwise .F.
Description
Adds a user to the supplied roles
Discussion
Context.Security.AddUserToRoles() adds a user to the supplied roles. Check Context.Security.CallResult.Success before using the return value.
The example below is an excerpt from an A5W page. The example adds the user "[email protected]" to two roles: "Management" and "Staff". The result of the call to AddUserToRoles() is checked before outputting HTML to the page to display a success or failure message:
Example
<%a5
dim userName as C = "[email protected]"
' Add user to roles
' Note: Roles must exist before you can add a user to them
dim roles as c =<<%str%
Management
Staff
%str%
dim added as L = Context.Security.AddUserToRoles(userName,roles)
if (Context.Security.CallResult.Success) then
if (added) then
'' User added to roles
? userName + " added to roles: <br>" + strtran(roles,crlf(),"<br>") + "<br>"
else
'' User not added to roles
? "User was not added to roles."
end if
else
'' Something went wrong checking for role
error_generate(Context.Security.CallResult.Text)
end if
%>