[SOLVED] How to get id of just created user

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

[SOLVED] How to get id of just created user

Post 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
Last edited by nervino on Tue Jul 29, 2014 6:02 pm, edited 1 time in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: How to get id of just created user

Post 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']
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: How to get id of just created user

Post 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.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: How to get id of just created user

Post by Jo Morg »

I think you may need to handle a different event:
Self Registration Module -> onUserRegistered
Same set of parameters...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to get id of just created user

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: How to get id of just created user

Post 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!
Post Reply

Return to “Modules/Add-Ons”