source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/About.pm @ 2002

Last change on this file since 2002 was 1692, checked in by nanardon, 8 years ago

Redirect / to user's page

File size: 1.9 KB
Line 
1package LATMOS::Accounts::Web::Controller::About;
2use strict;
3use warnings;
4use base 'Catalyst::Controller';
5
6use POSIX;
7use DateTime;
8use Date::Calc;
9use Date::Parse;
10
11=head1 NAME
12
13LATMOS::Accounts::Web::Controller::About - Catalyst Controller
14
15=head1 DESCRIPTION
16
17Catalyst Controller.
18
19=head1 METHODS
20
21=cut
22
23
24=head2 index
25
26=cut
27
28sub index :Path :Args(0) {
29    my ( $self, $c ) = @_;
30
31    $c->stash->{page}{title} = "A propos...";
32
33    if ($c->user) {
34        my $ouser = $c->model('Accounts')->db->get_object(
35            'user',
36            $c->user->{username},
37        );
38
39        my @cd = split('-', DateTime->from_epoch(
40            epoch => str2time(
41                $ouser->get_attributes('create'),
42            )
43        )->ymd('-'));
44        my @now = split('-', DateTime->now()->ymd('-'));
45
46        my ($Dy,$Dm,$Dd) = Date::Calc::N_Delta_YMD(@cd, @now);
47        $c->stash->{accountExists} = join(', ',
48            ($Dy ? $c->loc('[_1] years', $Dy)  : ()),
49            ($Dm ? $c->loc('[_1] months', $Dm) : ()),
50            ($Dd ? $c->loc('[_1] days', $Dd)   : ()),
51        );
52
53        if (my $expire = $ouser->get_attributes('expire')) {
54            my @ed = split('-', DateTime->from_epoch(
55                epoch => str2time(
56                    $expire
57                )
58            )->ymd('-'));
59
60            my ($Dy,$Dm,$Dd) = Date::Calc::N_Delta_YMD(@now, @ed);
61            $c->stash->{accountExpire} = join(', ',
62                ($Dy ? $c->loc('[_1] years', $Dy)  : ()),
63                ($Dm ? $c->loc('[_1] months', $Dm) : ()),
64                ($Dd ? $c->loc('[_1] days', $Dd)   : ()),
65            );
66        }
67    }
68}
69
70sub echo : XMLRPC {
71    my ( $self, $c, @args ) = @_;
72    return RPC::XML::fault->new( 400, "No input!"
73    ) unless @args;
74    return join ' ', @args;
75}
76
77=head1 AUTHOR
78
79Olivier Thauvin
80
81=head1 LICENSE
82
83This library is free software. You can redistribute it and/or modify
84it under the same terms as Perl itself.
85
86=cut
87
881;
Note: See TracBrowser for help on using the repository browser.