summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-04-29 20:12:59 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-04-29 20:12:59 +0200
commit25d0530e860e2103fd28f556ac728c4f72fcd45a (patch)
tree0e42e748071ad2e6554c3a3ab16c0dd929da80d4 /lib/Travelynx/Command
parent6ff397c9b3b702805e248783243368a5dc5388b4 (diff)
Add password reset functionality
Closes #5
Diffstat (limited to 'lib/Travelynx/Command')
-rw-r--r--lib/Travelynx/Command/database.pm17
-rw-r--r--lib/Travelynx/Command/maintenance.pm7
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index 393564b..62a470c 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -376,6 +376,23 @@ my @migrations = (
}
);
},
+
+ # v6 -> v7
+ # Add password_reset table to store data about pending password resets
+ sub {
+ my ($db) = @_;
+ $db->query(
+ qq{
+ create table pending_passwords (
+ user_id integer not null references users (id) primary key,
+ token varchar(80) not null,
+ requested_at timestamptz not null
+ );
+ comment on table pending_passwords is 'Password reset tokens';
+ update schema_version set version = 7;
+ }
+ );
+ },
);
sub setup_db {
diff --git a/lib/Travelynx/Command/maintenance.pm b/lib/Travelynx/Command/maintenance.pm
index 3b2462c..b3702b4 100644
--- a/lib/Travelynx/Command/maintenance.pm
+++ b/lib/Travelynx/Command/maintenance.pm
@@ -62,6 +62,13 @@ sub run {
printf( "Pruned unverified user %d\n", $user->{id} );
}
+ my $res = $db->delete( 'pending_passwords',
+ { requested_at => { '<', $verification_deadline } } );
+
+ if ( my $rows = $res->rows ) {
+ printf( "Pruned %d pending password reset(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;