Page 1 of 1

[SOLVED] How to get id of just created user

Posted: Tue Jul 29, 2014 3:41 pm
by nervino
I'm trying to set the expiry date of a user when he confirms his registration with SelfRegistration.

I made this UDT, fired by the FEU's OnCreateUser event.

I can't get the user id. (if I set the id by hand, it works).

Ideas..?

Thanks

UDT

Code: Select all

$gCms = cmsms();

$feusers = $gCms->GetModuleInstance("FrontEndUsers");
if( $feusers ) {
$user_id = $params['user_id'];// (I've tried $params['userid'..'uid' ecc..)

$username = $feusers->GetUserName($user_id);

$currentyear = date("Y");
$expydate = $currentyear."-12-31 23:59:59";

$feusers->SetUser($user_id, $username, $password, $expydate);
}
___________________
CMSMS 1.11.10
FrontEndUsers 1.23.5
SelfRegistration 1.8.2

Re: How to get id of just created user

Posted: Tue Jul 29, 2014 3:49 pm
by Jo Morg
Go to Event Manager -> FEU -> OnCreateUser -> Help
OnCreateUser

An event generated when a user is created
Parameters

name - The user name
id - The user id
$params['id']

Re: How to get id of just created user

Posted: Tue Jul 29, 2014 4:13 pm
by nervino
Thank you Jo.

I had already tried it but didn't work...

Here is my UDT with the correct param but it still doesn't update the expiry field:

Code: Select all

$gCms = cmsms();

$feusers = $gCms->GetModuleInstance("FrontEndUsers");
if( $feusers ) {
$user_id = $params['id'];

$username = $feusers->GetUserName($user_id);

$currentyear = date("Y");
$expydate = $currentyear."-12-31 23:59:59";

$feusers->SetUser($user_id, $username, $password, $expydate);
}
How can I debug this UDT? If I run it setting a numeric user id, it works. But I don't know how debug it during the actual confirmation process of the user, to see what's going on.

Re: How to get id of just created user

Posted: Tue Jul 29, 2014 4:28 pm
by Jo Morg
I think you may need to handle a different event:
Self Registration Module -> onUserRegistered
Same set of parameters...

Re: How to get id of just created user

Posted: Tue Jul 29, 2014 4:30 pm
by calguy1000
nervino wrote:I'm trying to set the expiry date of a user when he confirms his registration with SelfRegistration.

I made this UDT, fired by the FEU's OnCreateUser event.
The OnCreateUser event is not fired when a user is created via SelfRegistration. Only when the user is created manually in the FEU admin console.

Re: How to get id of just created user

Posted: Tue Jul 29, 2014 6:01 pm
by nervino
Wonderful!
Switching to Self Registration Module -> onUserRegistered fixed my problem. (In this event's help only the username parameter is listed. I'll file a minor bug report).

Thank you both!