From 867a5d4afbb3a5c0ad0e5dfbc10d2516e3e9123f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 30 Apr 2019 12:08:51 +0200 Subject: allow users to change their mail address Closes #6 --- lib/Travelynx/Command/database.pm | 21 ++++++++++++++++++++- lib/Travelynx/Command/maintenance.pm | 13 ++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'lib/Travelynx/Command') diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm index 62a470c..be5db72 100644 --- a/lib/Travelynx/Command/database.pm +++ b/lib/Travelynx/Command/database.pm @@ -378,7 +378,7 @@ my @migrations = ( }, # v6 -> v7 - # Add password_reset table to store data about pending password resets + # Add pending_passwords table to store data about pending password resets sub { my ($db) = @_; $db->query( @@ -393,6 +393,25 @@ my @migrations = ( } ); }, + + # v7 -> v8 + # Add pending_mails table to store data about pending mail changes + sub { + my ($db) = @_; + $db->query( + qq{ + alter table pending_mails rename to mail_blacklist; + create table pending_mails ( + user_id integer not null references users (id) primary key, + email varchar(256) not null, + token varchar(80) not null, + requested_at timestamptz not null + ); + comment on table pending_mails is 'Verification tokens for mail address changes'; + update schema_version set version = 8; + } + ); + }, ); sub setup_db { diff --git a/lib/Travelynx/Command/maintenance.pm b/lib/Travelynx/Command/maintenance.pm index 45969b3..2030705 100644 --- a/lib/Travelynx/Command/maintenance.pm +++ b/lib/Travelynx/Command/maintenance.pm @@ -34,13 +34,13 @@ sub run { ); my $pending - = $db->select( 'pending_mails', ['num_tries'], { email => $mail } ); + = $db->select( 'mail_blacklist', ['num_tries'], { email => $mail } ); my $pending_h = $pending->hash; if ($pending_h) { my $num_tries = $pending_h->{num_tries} + 1; $db->update( - 'pending_mails', + 'mail_blacklist', { num_tries => $num_tries, last_try => $reg_date @@ -50,7 +50,7 @@ sub run { } else { $db->insert( - 'pending_mails', + 'mail_blacklist', { email => $mail, num_tries => 1, @@ -69,6 +69,13 @@ sub run { printf( "Pruned %d pending password reset(s)\n", $rows ); } + $res = $db->delete( 'pending_mails', + { requested_at => { '<', $verification_deadline } } ); + + if ( my $rows = $res->rows ) { + printf( "Pruned %d pending mail change(s)\n", $rows ); + } + my $to_delete = $db->select( 'users', ['id'], { deletion_requested => { '<', $deletion_deadline } } ); my @uids_to_delete = $to_delete->arrays->map( sub { shift->[0] } )->each; -- cgit v1.2.3