source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Remote/ChangePw.pm @ 1852

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

Add error message

File size: 1.5 KB
Line 
1package LATMOS::Accounts::Web::Controller::Remote::ChangePw;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Remote::ChangePw - 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 :Path :Args(0) {
25    my ( $self, $c ) = @_;
26
27    my $username = $c->req->param('user') or do {
28        $c->stash->{data}{err} = 'Invalid request';
29        return;
30    };
31
32    my $user = $c->model('Accounts')->db->get_object('user', $username) or do {
33        $c->stash->{data}{err} = 'No such user';
34        return;
35    };
36
37    if (!$user->_get_attributes('active')) {
38        $c->stash->{data}{err} = 'No such user';
39        return;
40    }
41
42    my $oldpassword = $c->req->param('oldpassword');
43    my $password = $c->req->param('password');
44
45    if (!$c->model('Accounts')->db->authenticate_user(
46            $username, $oldpassword
47        )) {
48        $c->stash->{data}{err} = 'Invalid request';
49        return;
50    }
51
52    my $error = $c->forward('/users/change_password', [ $username, $password ]);
53
54    if ($error) {
55        $c->stash->{data}{err} = $error;
56        return 
57    } else {
58        $user->base->commit;
59        $c->stash->{data}{ok} = 'Done';
60        return 1;
61    }
62}
63
64
65
66=encoding utf8
67
68=head1 AUTHOR
69
70Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
71
72=head1 LICENSE
73
74This library is free software. You can redistribute it and/or modify
75it under the same terms as Perl itself.
76
77=cut
78
79__PACKAGE__->meta->make_immutable;
80
811;
Note: See TracBrowser for help on using the repository browser.