source: LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm @ 754

Last change on this file since 754 was 754, checked in by nanardon, 14 years ago
  • don't show N/A in ajax query when attribute is empty
File size: 3.5 KB
Line 
1package LATMOS::Accounts::Web::Controller::Ajax;
2
3use strict;
4use warnings;
5use base 'LATMOS::Accounts::Web::Controller';
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Ajax - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub index : Private {
25    my ( $self, $c ) = @_;
26
27    $c->response->body('Matched LATMOS::Accounts::Web::Controller::Ajax in Ajax.');
28}
29
30sub rawattr : Local {
31    my ($self, $c, $otype) = @_;
32
33    my $base = $c->model('Accounts')->db;
34
35    if (!$c->req->param('id')) {
36        $c->stash->{value} = '';
37        return;
38    }
39
40    my $obj = $base->get_object($otype, $c->req->param('id')) or do {
41        $c->stash->{value} = 'N/A';
42        return;
43    };
44    $c->stash->{value} = $obj->get_c_field($c->req->param('attr')) || '';
45}
46
47sub attrvalues : Local {
48    my ($self, $c, $otype, $attr) = @_;
49
50    my $base = $c->model('Accounts')->db;
51    my $val = $c->req->param('val');
52    $c->stash->{'complete'} = $c->prototype->auto_complete_result([
53        grep { /^\Q$val\E/ } $base->attributes_summary($otype, $attr)
54    ]);
55
56}
57
58sub objexist : Local {
59    my ($self, $c, $otype) = @_;
60    my $base = $c->model('Accounts')->db;
61    my $val = $c->req->param('val');
62    my $obj = $base->get_object($otype, $val);
63
64    $c->stash->{'exists'} = join(', ', $obj->get_attributes($c->req->param('attr') ||
65            'displayName')) if($obj);
66}
67
68sub check_new_name : Local {
69    my ($self, $c, $otype) = @_;
70    my $base = $c->model('Accounts')->db;
71    my $val = $c->req->param('val');
72
73    warn $otype;
74    if ($c->stash->{validity} = (lc($otype) eq 'user' || lc($otype) eq 'group')
75        ? LATMOS::Accounts::Utils::check_ug_validity($val)
76        : LATMOS::Accounts::Utils::check_oid_validity($val)) {
77        warn $c->stash->{validity};
78        return;
79    }
80
81    if (my $obj = $base->get_object($otype, $val)) {
82        $c->stash->{validity} = "$val exists " .
83            ($obj->get_attributes('displayName') || '')
84    }
85}
86
87sub objattrexist : Local {
88    my ($self, $c, $otype, $attr) = @_;
89    my $base = $c->model('Accounts')->db;
90    my $val = $c->req->param('val');
91    my @obj = $val ? $base->search_objects($otype, "$attr=$val") : ();
92
93    if (my $filter = $c->req->param('exclude')) {
94        @obj = grep { $_ ne $filter } @obj;
95    }
96    $c->stash->{'exists'} = join(', ', @obj);
97}
98
99sub cracklib : Local {
100    my ( $self, $c, $login ) = @_;
101    my $base = $c->model('Accounts')->db;
102    my ($password)  = $c->req->param('passwd');
103    my ($cpassword) = $c->req->param('cpasswd');
104    if (my $obj = $base->get_object('user', $login)) {
105        if ($password) {
106            if ((my $crl = $obj->check_password($password)) ne 'ok') {
107                $c->stash->{cracklib} = 'Mauvais mot de passe: ' . $crl;
108            } elsif ($cpassword) {
109                if ($password ne $cpassword) {
110                    $c->stash->{cracklib} = "Mot de passe différents";
111                } else {
112                    $c->stash->{cracklib} = 'ok';
113                }
114            } else {
115                $c->stash->{cracklib} = 'Confirmez le mot de passe';
116            }
117        }
118    }
119}
120
121sub check_ug_validity : Local {
122    my ( $self, $c ) = @_;
123    my $val = $c->req->param('val');
124    $c->stash->{validity} = LATMOS::Accounts::Utils::check_ug_validity($val);
125}
126
127sub end : Private {
128    my ( $self, $c ) = @_;
129    $c->forward($c->view('TTpart'));
130}
131
132=head1 AUTHOR
133
134Thauvin Olivier
135
136=head1 LICENSE
137
138This library is free software, you can redistribute it and/or modify
139it under the same terms as Perl itself.
140
141=cut
142
1431;
Note: See TracBrowser for help on using the repository browser.