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

Last change on this file since 861 was 861, checked in by nanardon, 13 years ago
  • reimport missing files from previous svn
File size: 4.1 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} = '';
42        return;
43    };
44    $c->stash->{value} = $obj->get_c_field($c->req->param('attr')) || '';
45}
46
47sub displayattr : Local {
48    my ($self, $c, $otype) = @_;
49    my $attribute = $c->model('Accounts')->db->attribute($otype,
50        $c->req->param('attr')) or return;
51    $c->stash->{value} = $attribute->display($c->req->param('id'));
52}
53
54sub attrvalues : Local {
55    my ($self, $c, $otype, $attr) = @_;
56
57    my $base = $c->model('Accounts')->db;
58    my $val = $c->req->param('val');
59    $c->stash->{'complete'} = $c->prototype->auto_complete_result([
60        grep { /^\Q$val\E/ } $base->attributes_summary($otype, $attr)
61    ]);
62
63}
64
65sub objexist : Local {
66    my ($self, $c, $otype) = @_;
67    my $base = $c->model('Accounts')->db;
68    my $val = $c->req->param('val');
69    my $obj = $base->get_object($otype, $val);
70
71    $c->stash->{'exists'} = join(', ', $obj->get_attributes($c->req->param('attr') ||
72            'displayName') || $obj->id) if($obj);
73}
74
75sub check_new_name : Local {
76    my ($self, $c, $otype) = @_;
77    my $base = $c->model('Accounts')->db;
78    my $val = $c->req->param('val');
79
80    warn $otype;
81    if ($c->stash->{validity} = (lc($otype) eq 'user' || lc($otype) eq 'group')
82        ? LATMOS::Accounts::Utils::check_ug_validity($val)
83        : LATMOS::Accounts::Utils::check_oid_validity($val)) {
84        warn $c->stash->{validity};
85        return;
86    }
87
88    if (my $obj = $base->get_object($otype, $val)) {
89        $c->stash->{validity} = "$val exists " .
90            ($obj->get_attributes('displayName') || '')
91    }
92}
93
94sub objattrexist : Local {
95    my ($self, $c, $otype, $attr) = @_;
96    my $base = $c->model('Accounts')->db;
97    my $attribute = $base->attribute($otype, $attr) or return;
98    my $val = $attribute->input($c->req->param('val'));
99    my @obj = $val ? $base->search_objects($otype, "$attr=$val") : ();
100
101    if (my $filter = $c->req->param('exclude')) {
102        @obj = grep { $_ ne $filter } @obj;
103    }
104    $c->stash->{'exists'} = join(', ', @obj);
105}
106
107sub cracklib : Local {
108    my ( $self, $c, $login ) = @_;
109    my $base = $c->model('Accounts')->db;
110    my ($password)  = $c->req->param('passwd');
111    my ($cpassword) = $c->req->param('cpasswd');
112    if (my $obj = $base->get_object('user', $login)) {
113        if ($password) {
114            if ((my $crl = $obj->check_password($password)) ne 'ok') {
115                $c->stash->{cracklib} = 'Mauvais mot de passe: ' . $crl;
116            } elsif ($cpassword) {
117                if ($password ne $cpassword) {
118                    $c->stash->{cracklib} = "Mot de passe différents";
119                } else {
120                    $c->stash->{cracklib} = 'ok';
121                }
122            } else {
123                $c->stash->{cracklib} = 'Confirmez le mot de passe';
124            }
125        }
126    }
127}
128
129sub check_ug_validity : Local {
130    my ( $self, $c ) = @_;
131    my $val = $c->req->param('val');
132    $c->stash->{validity} = LATMOS::Accounts::Utils::check_ug_validity($val);
133}
134
135sub select_freeip_select : Local {
136    my ($self, $c) = @_;
137
138}
139
140sub goto : Local {
141    my ($self, $c) = @_;
142
143    $c->res->redirect(
144        $c->uri_for('/' . $c->req->param('otype') . 's', $c->req->param('goto'),
145        $c->req->param('subform'))
146    );
147    $c->stash->{template} = 'no_object.tt';
148}
149
150
151sub end : Private {
152    my ( $self, $c ) = @_;
153    $c->forward($c->view('TTpart'));
154}
155
156=head1 AUTHOR
157
158Thauvin Olivier
159
160=head1 LICENSE
161
162This library is free software, you can redistribute it and/or modify
163it under the same terms as Perl itself.
164
165=cut
166
1671;
Note: See TracBrowser for help on using the repository browser.