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

Last change on this file since 585 was 585, checked in by nanardon, 14 years ago
  • website check password over cracklib
File size: 2.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')) || 'N/A';
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 objattrexist : Local {
69    my ($self, $c, $otype, $attr) = @_;
70    my $base = $c->model('Accounts')->db;
71    my $val = $c->req->param('val');
72    my @obj = $val ? $base->search_objects($otype, "$attr=$val") : ();
73
74    if (my $filter = $c->req->param('exclude')) {
75        @obj = grep { $_ ne $filter } @obj;
76    }
77    $c->stash->{'exists'} = join(', ', @obj);
78}
79
80sub cracklib : Local {
81    my ( $self, $c, $login ) = @_;
82    my $base = $c->model('Accounts')->db;
83    my ($password)  = $c->req->param('passwd');
84    my ($cpassword) = $c->req->param('cpasswd');
85    if ($password && $cpassword && $password ne $cpassword) {
86        $c->stash->{cracklib} = "Mot de passe différents";
87    } elsif ($password && (my $obj = $base->get_object('user', $login))) {
88        $c->stash->{cracklib} = $obj->check_password($password);
89    }
90}
91
92sub end : Private {
93    my ( $self, $c ) = @_;
94    $c->forward($c->view('TTpart'));
95}
96
97=head1 AUTHOR
98
99Thauvin Olivier
100
101=head1 LICENSE
102
103This library is free software, you can redistribute it and/or modify
104it under the same terms as Perl itself.
105
106=cut
107
1081;
Note: See TracBrowser for help on using the repository browser.