Hey Randy,
You're not a dope - it's a non-intuitive. I integrated my user system with
the 4D system a couple of years ago. Allows me to keep the really
fine-grained permissions they know and love while letting 4D sweat the
login stuff. Plus gives me a *much* easier way to know who the user is
within server side processes. Anyway here is the key method I use for
synicing with the structure:
// Method: User_set_4Dproperties (c-obj) -> text
// $1 is c-obj of params
// $0 is errMsg
// Purpose: manage updating & creating users
// $1 must have an 'action': update / create
// created users are always Administrator owned
// create action:
*C_OBJECT*(*$1*)
*C_TEXT*(*$0*;$errMsg)
*C_LONGINT*($userID;$nbLogin;$groupOwner;$4DuserId)
*C_TEXT*($name;$startup;$password;$action;$errMethod)
*C_DATE*($lastLogin)
$action:=*OB Get*(*$1*;"action")
// everyone should have access to the plugins
*ARRAY LONGINT*($aMembership;1)
$aMembership{1}:=15002 // plugins
*Error_install_handler *("err_log_only")
*Case of *
*: *($action="update") // note: password may be blank
$4DuserId:=*OB Get*(*$1*;"4DuserId";Is longint)
$password:=*OB Get*(*$1*;"password")
$name:=*OB Get*(*$1*;"name")
$startup:=*OB Get*(*$1*;"startupMethod")
$nbLogin:=*OB Get*(*$1*;"numLogin";Is longint)
$lastLogin:=*OB Get*(*$1*;"lastLogin";Is date)
*Case of *
*: *($name="")
$errMsg:="The user name can not be blank."
*: *($4DuserId=0)
$errMethod:="The 4D user number is required for an update."
*Else *
// is this a new password?
*Case of *
*: *($password="")
*: *(*Validate password*($4DuserId;$password)) // not changed
*Else *
// put a note on the user record
*TABLE_SET_readWrite *(->*[USERS]*)
*QUERY*(*[USERS]*;[USERS]db_userNumber=$4DuserId)
*If *(*Not*(*RW_Locked *(->*[USERS]*;->$errMsg)))
// clear the temp PW - if any
[USERS]temp_pw:=""
[USERS]temp_pw_dts:=""
*NOTE_ADD_toField *(->[USERS]Notes;"Changed password";" - ")
*UNLOAD RECORD*(*[USERS]*)
*End if *
*TABLE_RESTORE_readWrite *(->*[USERS]*;*True*)
*End case *
$4DuserId:=*Set user properties*($4DuserId;$name;$startup;$password;$nbLogin
;$lastLogin;$aMembership)
*OB SET*(*$1*;"4DuserId";$4DuserId)
*End case *
*: *($action="create") & (*OB Get*(*$1*;"name")="")
$errMsg:="No user name!"
*: *($action="create") // created by Administrator
*If *(*OB Is defined*(*$1*;"password"))
$password:=*OB Get*(*$1*;"password")
*Else *
$errMsg:="Users must have a password."
*End if *
*If *($errMsg="")
$name:=*OB Get*(*$1*;"name";Is text)
$startup:=*OB Get*(*$1*;"startupMethod";Is text)
$nbLogin:=0
$lastLogin:=!00-00-00!
// note - if the native 4D user editor is open this will hang waiting
for it to close
$4DuserId:=*Set user properties*(-2;$name;$startup;$password;$nbLogin;
$lastLogin;$aMembership)
*If *(*error*#0)
$errMsg:="The 4D user couldn't be created.\r"
*If *(*error*=-9979)
$errMsg:=$errMsg+" '"+$name+"' is already being used. Make a different
name."
*Else *
$errMsg:=$errMsg+*4D_get_error_text *(*error*)
*End if *
*Else *
*OB SET*(*$1*;"4DuserId";$4DuserId)
*End if *
*End if *
*Else *
$errMsg:="No valid action for the user update."
*End case *
*Error_install_handler *
// --------------------------------------------------------
*$0*:=$errMsg
To create a new 4D user I call it like so:
*C_OBJECT*($obj)
*OB SET*($obj;"action";"create")
*OB SET*($obj;"name";$name)
*OB SET*($obj;"password";*Pass_generate_word *(5;2;1;0)) // temp PW
$errMsg:=*User_set_4Dproperties *($obj)
Be sure to take a look at USER TO BLOB and BLOB TO USERS as well.
On Thu, Nov 1, 2018 at 3:48 PM Randy Engle via 4D_Tech <[email protected]>
wrote:
> I haven't used "4D Users" in a "long.... time"
>
> ( I roll my own user system...but 4D Users need it now)
>
> Maybe I'm being a dope (likely), but I'm not seeing a way to create users
> programmatically.
>
> A shove in the right direction would be most appreciated.
>
> Gracious Thanks
>
> Randy Engle, Director
> XC2 Software LLC – XC2LIVE!
>
>
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive: http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub: mailto:[email protected]
> **********************************************************************
--
Kirk Brooks
San Francisco, CA
=======================
*We go vote - they go home*
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************