adding a user timestamp

natehess

Joined: 2009-08-10
Posts: 7
Posted: Thu, 2009-10-22 11:39

Hello All,

I'm building a gallery that requires 30-day limits of user accounts. It seems to me that it'd be a big pain to rewrite a time-limit into the registration module, or make a new module from scratch, so I'm thinking that the best method might be to simply add a timestamp to each user upon registration or account activation. this way, i could simply check my users list and delete them based on their timestamps.

I'm a php novice, but i understand the structure of gallery2 very well and adding a timestamp to each user doesn't seem impossible to me. could anyone point me in the right direction? Of course, I'll take a stab at it on my own, but I think the PHP experts on these boards could come up with a better solution.

Thanks and Best,

Nathan Hess

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16502
Posted: Sun, 2009-10-25 09:00

Someone possibly did something here:
http://gallery.menalto.com/node/74575

That's the only mention I can see of someone doing or requesting this feature.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
alecmyers

Joined: 2006-08-01
Posts: 4338
Posted: Sun, 2009-10-25 12:09

It's done for you - g2 users are subclasses of GalleryEntity that already has a creationTimestamp propery.

However I would write a module to extract/display the information, and hilight users over the 30 day limit - it's easy, and instructive. You could even have a link to the correct url to delete them, from that same page.

Alternatively, I wonder if there's Gallery Event when a user logs in - you could write a module with an event handler to check the age of the user account and take appropriate action - like displaying an "account expired" page and logging them out again.

By the way - a new module requires only 7 (I think) lines of code, and can easily be contained in a single file.

 
natehess

Joined: 2009-08-10
Posts: 7
Posted: Sun, 2009-10-25 17:09

thanks a lot for the info. any chance you could write me a basic example of the module with event handler? doesn't have to work, but like i said. i'm a novice.

regardless, thanks a lot. this will get me over the hump.

 
alecmyers

Joined: 2006-08-01
Posts: 4338
Posted: Sun, 2009-10-25 17:57

I don't know if there is a login event - you'll have to investigate. If there is, you could write an event handler along the lines of the code in this post:
http://gallery.menalto.com/node/91847#comment-324342

Obviously you need to change relevant names, etc.

EDIT: looks like you're in luck. There's a Gallery:Login event posted every time a user logs in, see line 141 of modules/coreUserLogin.inc. The API permits you to return a redirect from the event handler (typically so you can send the user directly to their own gallery if you want) but I'm sure you can redirect them to an "account expired" Controller that logs them out and gives a message to that effect.

 
alecmyers

Joined: 2006-08-01
Posts: 4338
Posted: Sun, 2009-10-25 18:11

Alternatively, and even better, write a GalleryValidationPlugin plugin, which generates a validation error for users beyond the time limit. Read the code in modules/coreUserLogin.inc from lines 106 onwards for the idea. You may have to change a template to say "this user is invalid or expired" instead of just "invalid" or whatever it says now.

Challenge: 25 lines of code, or fewer.

 
alecmyers

Joined: 2006-08-01
Posts: 4338
Posted: Sun, 2009-10-25 20:57

I'm feeling generous: try this module, which fails the login for any user older than 31 days who is not an admin user. Better test it out, first, too.

EDIT: new code, I fixed a bug.

EDIT: code removed - see later post for new code.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22883
Posted: Sun, 2009-10-25 21:25

Thanks for your contribution yet again alecmyers!

http://codex.gallery2.org/Gallery2:Modules:timevalidation

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
natehess

Joined: 2009-08-10
Posts: 7
Posted: Mon, 2009-10-26 14:11

one word: heroic

but oddly enough it's not working for me. the code makes sense, but when i lower the expiration age to 1 * 31, i'm still able to log in fine. any ideas?

 
alecmyers

Joined: 2006-08-01
Posts: 4338
Posted: Mon, 2009-10-26 13:49

I count about 35-40 lines - 'heroic' would have been fewer than 20. Have you checked it works ok yet?

 
alecmyers

Joined: 2006-08-01
Posts: 4338
Posted: Mon, 2009-10-26 14:18
Quote:
1 * 31

That makes no sense (it corresponds to 31 seconds). If you want 1 day, it should be 1 * 86400.
Are you sure you're not testing with an admin user? Admin users can always log in, otherwise you could have problems uninstalling the module.

 
natehess

Joined: 2009-08-10
Posts: 7
Posted: Mon, 2009-10-26 15:57

yeah i wanted it to be 31 seconds, instantly expired basically. still didn't work. i'm sure i tried a non-admin, i even made a new user to test it, and still no dice.

thanks

 
alecmyers

Joined: 2006-08-01
Posts: 4338
Posted: Mon, 2009-10-26 17:30

Try this file, writes some debug to the screen so you can see what's going on. It still appears to work perfectly for me. (I've also fixed an omitted return status check, but that's not significant.)

AttachmentSize
TimeValidationPlugin.zip1.22 KB
 
alecmyers

Joined: 2006-08-01
Posts: 4338
Posted: Tue, 2009-11-10 11:55

Here is the latest version of this module.

AttachmentSize
timevalidation.zip2.24 KB