1 | package LATMOS::Accounts::Task::Refreshexpired; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base qw(LATMOS::Accounts::Task); |
---|
6 | use LATMOS::Accounts; |
---|
7 | use LATMOS::Accounts::Log; |
---|
8 | use LATMOS::Accounts::Utils; |
---|
9 | |
---|
10 | =head1 NAME |
---|
11 | |
---|
12 | LATMOS::Accounts::Task::Refreshexpired - Task to disable expired users |
---|
13 | |
---|
14 | =head1 DESCRIPTION |
---|
15 | |
---|
16 | Some base doesn't handle accounts expiration. One way to do it is to synchronize |
---|
17 | user with value denying login (wrong UNIX shell, password entry set to false, |
---|
18 | ...). |
---|
19 | |
---|
20 | For performance issue, objects are not written at each synchronisation, only |
---|
21 | when they changes. |
---|
22 | |
---|
23 | This module find expired user and refresh modification time to ensure |
---|
24 | propagation to other database. |
---|
25 | |
---|
26 | =cut |
---|
27 | |
---|
28 | sub init { |
---|
29 | my ($self) = @_; |
---|
30 | my $LA = LATMOS::Accounts->new($self->{config}); |
---|
31 | my $labase = $self->{base} ? $LA->base($self->{base}) : $LA->base; |
---|
32 | $labase && $labase->load or die "Cannot load base"; |
---|
33 | |
---|
34 | $self->{_la} = $LA; |
---|
35 | $self->{_base} = $labase; |
---|
36 | |
---|
37 | 1; |
---|
38 | } |
---|
39 | |
---|
40 | sub run { |
---|
41 | my ($self) = @_; |
---|
42 | |
---|
43 | my $find = $self->{_base}->db->prepare( |
---|
44 | q{ |
---|
45 | SELECT * FROM "user" |
---|
46 | WHERE expire < now() and "date" < expire; |
---|
47 | } |
---|
48 | ); |
---|
49 | $find->execute(); |
---|
50 | my $upd = $self->{_base}->db->prepare( |
---|
51 | q{ |
---|
52 | UPDATE "user" SET date = now() where "name" = ? |
---|
53 | } |
---|
54 | ); |
---|
55 | while ( my $res = $find->fetchrow_hashref ) { |
---|
56 | la_log(LA_NOTICE, "Refresh user %s to take expiry into account", |
---|
57 | $res->{name}, |
---|
58 | ); |
---|
59 | $upd->execute($res->{name}); |
---|
60 | } |
---|
61 | |
---|
62 | $self->{_base}->commit; |
---|
63 | |
---|
64 | 1; |
---|
65 | } |
---|
66 | |
---|
67 | 1; |
---|
68 | |
---|
69 | __END__ |
---|
70 | |
---|
71 | =head1 SEE ALSO |
---|
72 | |
---|
73 | L<LATMOS::Accounts>, L<LATMOS::Accounts::Task> |
---|
74 | |
---|
75 | =head1 AUTHOR |
---|
76 | |
---|
77 | Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt> |
---|
78 | |
---|
79 | =head1 COPYRIGHT AND LICENSE |
---|
80 | |
---|
81 | Copyright (C) 2012 CNRS SA/CETP/LATMOS |
---|
82 | |
---|
83 | This library is free software; you can redistribute it and/or modify |
---|
84 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
85 | at your option, any later version of Perl 5 you may have available. |
---|
86 | |
---|
87 | =cut |
---|
88 | |
---|