diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2019-04-30 12:47:32 +0200 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2019-04-30 12:48:23 +0200 | 
| commit | 99aa3a4a0d467fd83ba78096cf34113df797f0d8 (patch) | |
| tree | 3a6e4dc9b7a7bcdb73fd3071dcca3e68c218702b /lib/Travelynx | |
| parent | 867a5d4afbb3a5c0ad0e5dfbc10d2516e3e9123f (diff) | |
Implement deletion of inactive accounts
Diffstat (limited to 'lib/Travelynx')
| -rw-r--r-- | lib/Travelynx/Command/database.pm | 12 | ||||
| -rw-r--r-- | lib/Travelynx/Command/maintenance.pm | 7 | ||||
| -rw-r--r-- | lib/Travelynx/Controller/Account.pm | 2 | ||||
| -rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 2 | 
4 files changed, 23 insertions, 0 deletions
| diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm index be5db72..05b43d6 100644 --- a/lib/Travelynx/Command/database.pm +++ b/lib/Travelynx/Command/database.pm @@ -412,6 +412,18 @@ my @migrations = (  			}  		);  	}, + +	# v8 -> v9 +	sub { +		my ($db) = @_; +		$db->query( +			qq{ +				alter table users rename column last_login to last_seen; +				drop table user_actions; +				update schema_version set version = 9; +			} +		); +	},  );  sub setup_db { diff --git a/lib/Travelynx/Command/maintenance.pm b/lib/Travelynx/Command/maintenance.pm index 2030705..8c07728 100644 --- a/lib/Travelynx/Command/maintenance.pm +++ b/lib/Travelynx/Command/maintenance.pm @@ -13,6 +13,7 @@ sub run {  	my $now = DateTime->now( time_zone => 'Europe/Berlin' );  	my $verification_deadline = $now->clone->subtract( hours => 48 );  	my $deletion_deadline     = $now->clone->subtract( hours => 72 ); +	my $old_deadline          = $now->clone->subtract( years => 1 );  	my $db = $self->app->pg->db;  	my $tx = $db->begin; @@ -80,6 +81,12 @@ sub run {  		{ deletion_requested => { '<', $deletion_deadline } } );  	my @uids_to_delete = $to_delete->arrays->map( sub { shift->[0] } )->each; +	$to_delete +	  = $db->select( 'users', ['id'], { last_seen => { '<', $old_deadline } } ); + +	push( @uids_to_delete, +		$to_delete->arrays->map( sub { shift->[0] } )->each ); +  	if ( @uids_to_delete > 10 ) {  		printf STDERR (  			"About to delete %d accounts, which is quite a lot.\n", diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm index 962a33a..dc3adb4 100644 --- a/lib/Travelynx/Controller/Account.pm +++ b/lib/Travelynx/Controller/Account.pm @@ -38,6 +38,7 @@ sub do_login {  	else {  		if ( $self->authenticate( $user, $password ) ) {  			$self->redirect_to( $self->req->param('redirect_to') // '/' ); +			$self->mark_seen( $self->current_user->{id} );  		}  		else {  			my $data = $self->get_user_password($user); @@ -535,6 +536,7 @@ sub account {  	my ($self) = @_;  	$self->render('account'); +	$self->mark_seen( $self->current_user->{id} );  }  sub json_export { diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index ee8d27d..0a7250f 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -13,6 +13,7 @@ sub homepage {  			with_autocomplete => 1,  			with_geolocation  => 1  		); +		$self->mark_seen( $self->current_user->{id} );  	}  	else {  		$self->render( 'landingpage', intro => 1 ); @@ -272,6 +273,7 @@ sub station {  			title   => "travelynx: $status->{station_name}",  		);  	} +	$self->mark_seen( $self->current_user->{id} );  }  sub redirect_to_station { | 
