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

Last change on this file since 2454 was 2454, checked in by nanardon, 3 years ago

Fix remote password change

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->model('Accounts')->ChangeUserPassword(
53        $username, $password
54    );
55
56    if ($error) {
57        $c->stash->{data}{err} = $error;
58        return 
59    } else {
60        $user->base->commit;
61        $c->stash->{data}{ok} = 'Done';
62        return 1;
63    }
64}
65
66
67
68=encoding utf8
69
70=head1 AUTHOR
71
72Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
73
74=head1 LICENSE
75
76This library is free software. You can redistribute it and/or modify
77it under the same terms as Perl itself.
78
79=cut
80
81__PACKAGE__->meta->make_immutable;
82
831;
Note: See TracBrowser for help on using the repository browser.