Page 1 of 1
[SOLVED] FEU > self change group (assignment) by user
Posted: Mon Jul 11, 2011 1:58 pm
by jack4ya
I have a FEU group members... (it's a free membership)
If a member wants out, they should be able to delete themselves.
However that might be tricky, so I have another approach. (Considering it might be by accident, et etc..) They should not be allowed to sign back in, which is covered by restricting access to pages by using the param (group = member) etc)
Approach:
Let them change for themselves the group from 'member' to 'nonmember'.
So I have the page: change settings (by FEU form name='changesettings')
But I have no idea how to add the group the currently (member) belong too.
Any ideas?
Re: FEU > self change group (assignment) by user
Posted: Mon Jul 11, 2011 7:03 pm
by Duketown
jack4ya,
Why not set the expiry date? You don't have to worry in this case to set up the groups exactly the same (I know export/import helps if it works).
Is that not enough since you want to select members and non members based upon the group.
Duketown
Re: FEU > self change group (assignment) by user
Posted: Tue Jul 12, 2011 8:58 am
by jack4ya
And how would the user be able to change that themselves?
I don't think its' possible.
Re: FEU > self change group (assignment) by user
Posted: Tue Jul 12, 2011 9:50 am
by Duketown
Maybe I'm thinking a bit too light about this:
- User signs in;
- A hyperlink (or button) is available that is connected to a UDT;
When the button is used the expiry date of the current user is set to today (or yesterday).
- User signs out and can't log in anymore since account expired (or at least tomorrow depending on the expiry date set).
The UDT will consist of a form that updates the table module_feusers_users. See function SetUser in FrontEndUsers.api.php.
Duketown
Re: FEU > self change group (assignment) by user
Posted: Tue Jul 12, 2011 10:22 am
by jack4ya
Nope, that actually would be perfect!
However, I am not a UDT (or php) coder, so I have no idea how to write the UDT...
Re: FEU > self change group (assignment) by user
Posted: Tue Jul 12, 2011 10:53 am
by jack4ya
I've had some help...
I have a tag/plugin that rewrites the users group assignment...
The UDT switches the group assignment.
I'd rather have the expirytime set, like you suggest, which would save me to problem of multiple group (and password protected pages, menus, files and forms).
Re: FEU > self change group (assignment) by user
Posted: Tue Jul 12, 2011 10:57 am
by Jos
can you post the tag that you have now? It may be a good start to change it.
Re: FEU > self change group (assignment) by user
Posted: Tue Jul 12, 2011 11:20 am
by jack4ya
Apparently: "there is no function to update the expires date but with SQL it can be done"
The code I recieved:
Code: Select all
<?php
// copy to plugins/updatefeugroup.php
function smarty_cms_function_updatefeugroup($params, &$smarty) {
if (!function_exists('MyGetModuleInstance'))
{
function &MyGetModuleInstance($module)
{
global $gCms;
if (isset($gCms->modules[$module]) &&
$gCms->modules[$module]['installed'] == true &&
$gCms->modules[$module]['active'] == true)
{
return $gCms->modules[$module]['object'];
}
// Fix only variable references should be returned by reference
$tmp = FALSE;
return $tmp;
}
}
global $gCms;
$feu = MyGetModuleInstance('FrontEndUsers');
if ($feu == FALSE)
{
return false;
}
//Get User
$feu_user = $feu->GetUserInfo($params['id']);
//$member_groups = $feu->GetMemberGroupsArray($params['id']);
// does this user really exists
if ($feu_user)
{
// we set the current user to the hardcoded: $grpids
$grpids[0] = '2';
$feu->SetUserGroups($params['id'], $grpids );
}
} // end updatefeugroup
?>
Re: FEU > self change group (assignment) by user
Posted: Tue Jul 12, 2011 11:23 am
by jack4ya
So *all* I need would be:
- get current user expiration time (A)
- get current day, set minus one day (B)
- (re)set current user's expiration time from A to B
Voila...

Re: FEU > self change group (assignment) by user
Posted: Tue Jul 12, 2011 1:16 pm
by Duketown
jack4ya,
I think that you can use the following UDT (works like a charm on my 1.9.4.1 site).
Create a UDT with the name 'ExpireFEUUser' with the following as content:
Code: Select all
/*
Push {ExpireFEUUser} on a new page
Make link to this new page. User will go to page via the hyperlink and FEU user will be set to expired
Duketown July 2011
*/
$gCms = cmsms();
$feusers =& $gCms->modules['FrontEndUsers']['object'];
// Initiate the parameters
$uid = $feusers->LoggedInID();
$username = $feusers->LoggedInName();
// Calculate yesterday
// $expires = date('Y-m-d H:i:s', strtotime('-1 day'));
// or expire the account now (handy if you want to know when exactly the user used this function.
$expires = time();
// Expire the user
$userexpired = $feusers->SetUser( $uid, $username, '', $expires);
if ($userexpired[0]) {
echo 'Your account has been set to expired';
}
else {
echo 'Expiring your account resulted in an error. Please contact the webmaster';
}
Duketown
PS. I have not tested the expire yesterday situation (you might end in registering today, but expired yesterday which is weird

)
Re: FEU > self change group (assignment) by user
Posted: Wed Jul 13, 2011 12:55 pm
by jack4ya
Got help from (so credits go to) Arnoud, however the approach by using expiry time came from Duketown, so kudos... This is synergy!
Code: Select all
<?php
// copy to plugins/updatefeuexpires.php
/*
{updatefeuexpires id=1}
{global_content name='updatefeuexpires'}
{if $ccuser->loggedin() && $ccuser->memberof('active_users')}
{* change user(id) expires to now() *}
{updatefeuexpires id=$ccuser->_uid}
{/if}
*/
function smarty_cms_function_updatefeuexpires($params, &$smarty) {
if(!is_object(cmsms())) exit;
if (!function_exists('MyGetModuleInstance')) {
function &MyGetModuleInstance($module) {
if (isset(cmsms()->modules[$module]['object']) &&
cmsms()->modules[$module]['installed'] == true &&
cmsms()->modules[$module]['active'] == true) {
return cmsms()->modules[$module]['object'];
}
// Fix only variable references should be returned by reference
$tmp = FALSE;
return $tmp;
}
}
$feu = MyGetModuleInstance('FrontEndUsers');
$db = cmsms()->GetDb();
if ($feu == FALSE) {
return false;
}
if ($db == FALSE) {
return false;
}
//Get User
$feu_user = $feu->GetUserInfo($params['id']);
// does this user really exists
if ($feu_user) {
// logout the user
$feu->LogoutUser($params['id']);
// change the expires date
$query = "UPDATE ".cms_db_prefix()."module_feusers_users
SET expires = NOW()
WHERE id = ?";
$db_result = $db->Execute($query, array($params['id']));
}
} // end updatefeuexpires
?>
Re: [SOLVED] FEU > self change group (assignment) by user
Posted: Wed Jul 11, 2012 9:03 pm
by Duketown
I know the original post is a bit older.
I wanted to self change the group as well for a customer of mine and I used the following UDT (in combination with CustomContent):
Code: Select all
/*
Push {MoveMemberToNewGroup} in custom content part where member is logged in
Duketown July 2012
*/
// In case CMSMS version < 1.10 use
$gCms = cmsms();
$feusers =& $gCms->modules['FrontEndUsers']['object'];
/*
If CMSMS version >= 1.10 use:
$gCms = cmsms();
$modops = cmsms()->GetModuleOperations();
$feusers = $modops->get_module_instance('FrontEndUsers');
*/
// Initiate the parameters
$uid = $feusers->LoggedInID();
$username = $feusers->LoggedInName();
// Move the user to other group
$newgroupid = 2; // This is the group id of the new group that will get no information
$usermoved = $feusers->SetUserGroups( $uid, array($newgroupid));
if ($usermoved[0]) {
// Logout the user
$feusers->LogoutUser($uid);
echo 'You have been removed as a member';
}
else {
echo 'Something went wrong, please get in contact with the webmaster.';
}
Get the group id of the new group from the list of available groups in FEU.
Actually function SetUserGroups allows you to move member to multiple other groups as well. If you want to this is the, not tested, code:
Code: Select all
$usermoved = $feusers->SetUserGroups( $uid, array(2, 6, 8));
You may remove the line with '$newgroupid = 2;' when you use this example.
This will mean that the member will end up in three groups at the end.
Happy UDT-ing,
Duketown
Re: [SOLVED] FEU > self change group (assignment) by user
Posted: Fri May 09, 2014 2:37 pm
by slabbe
I know i bring up an old post but this is exactly what I need to do. I'm just not sure the way to do it.
I have 3 groups:
useradmin
pending
user
Everything goes on via the frontend cause the client doesn't want their useradmin having access to the backend.
So i have page with all the differents users listed only available for the useradmin. The listing is generated via CGUserDirectory. I want to be able to let the admin, by clicking on the button at the end of the row to move a user from pending to user group. I know that UDT do this but i'm not sure how to integrate it...