Page 1 of 1

How to automatically create a ftp directory for each FrontEndUser?

Posted: Wed Jul 21, 2010 11:06 pm
by kjonix
Hi!

I have successfully uses Calguy's suggestion for individual file list for each front end user

Modified to:

{capture assign='dir'}medlemsdok/{$username}{/capture}
{file_list folder=$dir sort=d colheaders=1}


BUT:
If folder not excist for logged in user, the filelist shows a lot of warning messages (of course).
In my case i want a directory for each of my users and I want that directory to be created automatically.

How can this be done? I use selv registration combined with FEU.

To avoid manually have to create folder for old users, I think a good solution will be to create the folder when user log in and next time check if folder for user is already created, if yes: don't create a new folder.

But it may be easier to create the folder when the user register? It is possible for me to create folder for old user.

Appreciate any help or hints! ;-)

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Wed Jul 21, 2010 11:41 pm
by JeremyBASS
Just us a udt on the FEU events.. and the a little php to create the folder and one to delete the folder.. you have the username to work with.. Really straight forward.. HTH cheers -Jeremy

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 5:47 pm
by Peciura
Assign this UDT ("create_feu_dir") to event "Frontend User Management -> OnLogin". It should send you an email on failure.

Code: Select all

global $gCms;
$config = $gCms->GetConfig();

$subdir = 'front_end_users';
$user_dir = $params['username'];
$email = 'admin@**************';		/*your mail address*/
/*$user_dir = $params['id'];*/		/*sometimes it is better ideato create dir based on user id*/
$destdir = cms_join_path($config['uploads_path'], $subdir, $user_dir);

cge_dir::mkdirr($destdir);
if( !is_dir($destdir) ){
	$body = 'Directory "'.$destdir.'" was not created for user ('.$params['id'].') '.$params['username'];
	$subject = $body;
	$mail =& $gCms->modules['CMSMailer']['object'];
	$mail->AddAddress( $email );
	$mail->SetBody( $body );
	$mail->SetSubject( $subject );
	$mail->Send();
}

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 6:46 pm
by JeremyBASS
ay Peciura your not suppost to do the work for them hehe :D j/k nice little snippit

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 7:30 pm
by Peciura
JeremyBass: normally i would not, but i already thought about smth similar so i did it a bit earlier :).
Besides it is good thing to share some working examples with first-timers. That i know from personal experience :).

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 8:05 pm
by JeremyBASS
Oh I was only joking :D (the j/k is just kidding) I'm also one of the guilty to just pass over a script. :)

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 8:47 pm
by Peciura
Oh I was only joking  (the j/k is just kidding)
I don't know... :-\ You sounded so convincing...

I also put this UDT on our wiki (events page). So people who are reading docs will get a bit more help.

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 9:13 pm
by JeremyBASS
Peciura wrote:
Oh I was only joking  (the j/k is just kidding)
I don't know... :-\ You sounded so convincing...

I also put this UDT on our wiki (events page). So people who are reading docs will get a bit more help.
Oh that is why I thought I'd say I was joking.. didn't want you to think I was just some a$% :D ...

Side note.. you may want to note that in order to use this you must have CGextensions in case someone wants to try to uses this for some other reason that doesn't relate to FEU and to which wouldn't necessarily have CGext. due to that.  Also FYI there is a mkdirr in the core so you could use that.

One last thing @kjonix you should also make a udt to delete the user folder on the FEU event for user deletion.. you can also find a recursive deletion in the core too..

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 9:19 pm
by calguy1000
Side note.. you may want to note that in order to use this you must have CGextensions in case someone wants to try to uses this for some other reason that doesn't relate to FEU and to which wouldn't necessarily have CGext. due to that.  Also FYI there is a mkdirr in the core so you could use that.
FEU requires CGExtensions... so it's safe.

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 9:30 pm
by JeremyBASS
it was the
for some other reason that doesn't relate to FEU and to which wouldn't necessarily have CGext. due to that.
if they don't have FEU they may not have it is all I was saying, you know nobs and all hehe :D

*edit* I guess I should be clearer.. the thought was that if someone tries to do the create folder and email for some other event like on cataloger or some other module's event.  That thought is just me being a cautious nellie

Re: How to automatically create a ftp directory for each FrontEndUser?

Posted: Fri Jul 23, 2010 9:43 pm
by Peciura
I decided not to mention that UDT depends on CGE and CMSMailer, since FEU depends on both of them. But i guess it it is better to keep it crystal-clear on wiki.

and almost forgot:
kjonix, do folder deletion UDT yourself. Not kidding  >:(.