remove user account after a number of days

smilem

Joined: 2009-02-25
Posts: 118
Posted: Sat, 2010-02-13 17:59

How can I delete or deactivate user accounts after a number of days if the user does not log in?

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2010-02-13 21:01

I posted a module on here that does something similar - disable a user some days after they register. You could modify it. A search on this forum should turn it up.

 
smilem

Joined: 2009-02-25
Posts: 118
Posted: Fri, 2010-02-19 13:42

Well I searched for "delete or deactivate user accounts" and "deactivate user accounts" can't seem to find anything?

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2010-02-19 16:33
 
smilem

Joined: 2009-02-25
Posts: 118
Posted: Fri, 2010-02-19 21:30

Thanks, I should have used google for searching not forum search.

After isntalling I had to restore site from backup because I could not login even as admin.

As I understand these lines check and deny user login after 30 days if user is not admin:

if (!$isAdmin && $age > 86400 * 30)
$error[] = 'form[error][invalidPassword]';
$success = false;
}

Can you give me some hints on how to check for user inactivity instead of a flat line like 30days?
When deleting a user in gallery2 you can choose to

1. assign photos to another user
2. delete them.

I would like to make second choice have them just deleted,I have no idea how a delete user :(

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2010-02-19 23:14
Quote:
After isntalling I had to restore site from backup because I could not login even as admin.

Shouldn't be the case. Regardless in future see FAQ: How can I deactivate a module when I am unable to login?

Quote:
hints on how to check for user inactivity

Not sure if G2 actually records logins at all. Otherwise you'll have to write an event handler for the login event, build a db table to record logins, record them etc etc. Pretty straightforward if you're an experienced G2 programmer, massive task if you're not.

Quote:
I have no idea how a delete user

http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryCoreApi.html#methoddeleteEntityById
Follow the core code to see how it handles owned items on user deletion.

 
smilem

Joined: 2009-02-25
Posts: 118
Posted: Sat, 2010-02-20 00:08

When I click "Site Admin" -> "User Info"

I can see data like "This will display information about users when they Login, Logout, and Failed Login Attempts. "

ID, User ID, User Name, IP Address, Time Stamp (Sat 20 Feb 2010 01:58:44 AM EET ) and Action (Login) or (Failed Login) or (Logout).
So I think gallery2 has all the data that is required to check when user last logged out, or when last login was made.

Yes I'm not "experienced G2 programmer" but all I'm looking for is if it's possible for help on modifying perhaps this module for this task.
I'm not sure why I could not login after installing it, see attached image in my above post. The login buttons were gone, and pushing enter key did nothing.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2010-02-20 00:15

That'll be the userinfo module (http://codex.gallery2.org/Gallery2:Modules:userinfo), non-core, contributed by the community. I don't know much about it. Obviously you need to think carefully about introducing inter-module dependencies. Actually you may be better off hacking your code changes into that module, to reject an out-of-time login.

Also note that won't delete the user, and if you program it to, they won't get deleted until the next time they try to login. Gallery doesn't have an effective mechanism for doing actions at a prearranged time, everything is triggered by web page views, so you have to piggy-back off some other event.

Quote:
The login buttons were gone

Curious. That module isn't programmed to have that effect.

 
smilem

Joined: 2009-02-25
Posts: 118
Posted: Sat, 2010-02-20 01:10

Well my work flow is like this:

1. User registers
2. Gallery creates usernamefolder by using useralbums
3. User uploads photos for printing

4. I download the photos via ftp and delete them via admin
5. if user does not login back to the site within say 60days I'm looking for way to list this type of users and delete them.

I was thinking to try to list users in phpmyadmin but g_timeStamp fields has just numbers like "1256324867" what do they mean, how can get normal date view?

Quote:
SELECT * FROM g2_UserinfoMap where g_timeStamp = '>morethan60days???' ;

query

Quote:
SELECT
*
FROM
g2_UserinfoMap
WHERE
g_timeStamp >= DATE_SUB( NOW(), INTERVAL 7 DAY )

returned zero rows as I can't figure out how to request correct timestamp

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2010-02-20 01:16

The timestamp is a unix timestamp. You can google for that. You need to subtract the current system time and divide by 86400 to get the number of days. Check the code in the module I wrote and linked to above.

 
smilem

Joined: 2009-02-25
Posts: 118
Posted: Sat, 2010-02-20 01:47

I finally managed to build my sql for selecting users in phpmyadmin after certain date that are not an admin and last action was login:

Quote:
SELECT *
FROM g2_UserinfoMap
WHERE g_timeStamp >= UNIX_TIMESTAMP( '2010-02-01 00:00:00' ) && g_userName != 'admin' && g_action = 'Login'

I'm still puzzled how to make it into workable code for your script:

Quote:
if (!$isAdmin && $age > 86400 * 30)
$error[] = 'form[error][invalidPassword]';
$success = false;
}

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2010-02-20 01:56

That script isn't an appropriate place for what you're trying to do. The script I wrote is triggered on the login of an individual user, and allows/denies that user only. If you want to trawl the entire user list then you need to find another approach to the one I took.

 
smilem

Joined: 2009-02-25
Posts: 118
Posted: Sun, 2010-02-21 14:24

I have a table where user logins are registered

Table is called g2_UserinfoMap and it looks like this:

g_id | g_userId | g_userName | g_ipAddress | g_timeStamp | g_action

Records in table are added after each user login to the site:

Quote:

10 | 100 | user2 | 86.4.44.7 | 1256330245 | Login
10 | 100 | user1 | 86.5.44.8 | 1256330309 | Login
10 | 100 | user2 | 86.4.44.7 | 1256330317 | Login
10 | 100 | user2 | 86.4.44.7 | 1256331833 | Login
10 | 100 | mano3 | 86.55.2.45 | 1256331859 | Login
10 | 100 | user99 | 86.100.10.10 | 1256331864 | Login

I'm trying to make a a select query to show users that were not logged in the last 3 months to the site so I could delete them from site management interface manually by hand.

Unfortunately I'm not so good with SQL and my query above just lists users after certain date.

The unixtime field "g_timeStamp" is varchar for some reason.

I tried to filter users like this but get not what I need:

SELECT DISTINCT *
FROM g2_UserinfoMap
WHERE g_timeStamp < UNIX_TIMESTAMP('2010-01-31 22:07:42')

So perhaps anyone know how to build such quary, Any ideas?
I read perhaps it's required to use left join but how to use it?