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.
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.
This part is documented, see this page:http://www.concrete5.org/help/building_with_concrete5/developers/mv...
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.
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.
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.
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')")
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')")
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.
make the INSERT query, that was done by the CMS..
All i have done is what i have posted
All i have done is what i have posted
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
if you're not logged in, that one might be empty
$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);
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
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
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.
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.
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