source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Remote/PwReset.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::PwReset;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Remote::AskPwReset - 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 $resetid = $c->req->param('id');
43    my $password = $c->req->param('password');
44
45    if (!$user->CheckPasswordResetId($resetid)) {
46        $c->stash->{data}{err} = 'Invalid request';
47        return;
48    }
49
50    my $error = $c->forward('/users/change_password', [ $username, $password ]);
51
52    if ($error) {
53        $c->stash->{data}{err} = $error;
54        return 
55    } else {
56        $user->DeletePasswordId($resetid);
57        $user->base->commit;
58        $c->stash->{data}{ok} = 'Done';
59        return 1;
60    }
61}
62
63
64
65=encoding utf8
66
67=head1 AUTHOR
68
69Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
70
71=head1 LICENSE
72
73This library is free software. You can redistribute it and/or modify
74it under the same terms as Perl itself.
75
76=cut
77
78__PACKAGE__->meta->make_immutable;
79
801;
Note: See TracBrowser for help on using the repository browser.