Auto add new members to groups..

Permalink
I have spent the last few hours looking but can't find anything to help.

So I can manage permissions properly, I want all new members that join automatically go into a group called "members" without myself having to manually add each one to the group.

Is it possible to have an auto add feature to new registrations?

thanks in advance.

fad3duk2k
 
ScottC replied on at Permalink Reply
ScottC
that you want to look into the documentation regarding enabling application events.

I believe there is a user event that passes the newly created user object to a predefined class and thus a function.

It is in the documentation, again I haven't had the time or the requirement to look into this and enable some of this functionality, but this is something that certainly interests me :)

-Scott
Remo replied on at Permalink Reply
Remo
Maynar replied on at Permalink Reply
Maynar
There is a group called registered users where members are member of automatically. I think that's they way to go, if you don't want to write extra code.
fad3duk2k replied on at Permalink Reply
fad3duk2k
and so far I haven't been able to make it work.
This is what I have done so far:

I have added the
<?php define('ENABLE_APPLICATION_EVENTS', true); ?>
to the config/site.php

and then I have created a site_events.php with the following in it:

<?php Events::extend('on_user_add',
'ApplicationUser',
'setupUserGroup',
'models/application_new_user_group.php'); ?>

and I added code to the application_new_user_group.php page and EVERY time I try it out (and I have changed it quite a few times) I keep getting
Parse error: syntax error, unexpected T_VARIABLE in /home/*****/public_html/models/application_new_user_group.php on line 1

This is what is in the file atm.

<? php $g = Group::getByID(4);
$u = new User();
$u->enterGroup($g);
?>

I'm not too clued up with php, any suggestions to what I'm doing wrong?

*edit*
I know there is a registered users group but I want it to be in a custom group to make life easy when I want to change things.
fad3duk2k replied on at Permalink Reply
fad3duk2k
i put a space between <? and php. i removed that and now get the following error:

An unexpected error occurred.
mysql error: [1048: Column 'uID' cannot be null] in EXECUTE("INSERT INTO UserGroups (uID,gID,type,ugEntered) VALUES (NULL,'4','','2009-05-11 03:16:50')")
Maynar replied on at Permalink Reply
Maynar
You can't add the value NULL to uID, that has to be an ID and it's auto generated by the autoincrement function in the MySQL table. So remove the uID column and the NULL value from the INSERT query.
fad3duk2k replied on at Permalink Reply
fad3duk2k
make the INSERT query, that was done by the CMS..

All i have done is what i have posted
Remo replied on at Permalink Reply
Remo
can you do a print_r($u) just to be sure that there's an user id in that structure?

if you're not logged in, that one might be empty
Maynar replied on at Permalink Reply
Maynar
$g = Group::getByName("Administrators");

User selecting:
Current user:
$u = new User();

OR:
Based on ID:
$u = User::getByID($id);

But I am not sure... How to get the ID of the latest registered user?

And add to group:
$u->enterGroup($g);
fad3duk2k replied on at Permalink Reply
fad3duk2k
That's probs what's causing the issue that its not got the latest user id.

Well not to worry - I will use the default reg group atm and I'm sure I will come up with something lol

thanks for your help guys
Maynar replied on at Permalink Reply
Maynar
After the user is created the function add() returns the user ID in the user object, but I guess it's not send.

You could try


This will return a whole lot of stuff which should contain a user object, you could use that variable, but I am not sure. You should check this for yourself.