source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Remote/PwReset.pm @ 1641

Last change on this file since 1641 was 1641, checked in by nanardon, 9 years ago

Add web call for password reset

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        return;
29    };
30
31    my $user = $c->model('Accounts')->db->get_object('user', $username) or do {
32        $c->stash->{data}{err} = 'No such user';
33        return;
34    };
35
36    if (!$user->_get_attributes('active')) {
37        $c->stash->{data}{err} = 'No such user';
38        return;
39    }
40
41    my $resetid = $c->req->param('id');
42    my $password = $c->req->param('password');
43
44    if (!$user->CheckPasswordResetId($resetid)) {
45        $c->stash->{data}{err} = 'Invalid request';
46        return;
47    }
48
49    my $error = $c->forward('/users/change_password', [ $username, $password ]);
50
51    if ($error) {
52        $c->stash->{data}{err} = $error;
53        return 
54    } else {
55        $user->DeletePasswordId($resetid);
56        $user->base->commit;
57        $c->stash->{data}{ok} = 'Done';
58        return 1;
59    }
60}
61
62
63
64=encoding utf8
65
66=head1 AUTHOR
67
68Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
69
70=head1 LICENSE
71
72This library is free software. You can redistribute it and/or modify
73it under the same terms as Perl itself.
74
75=cut
76
77__PACKAGE__->meta->make_immutable;
78
791;
Note: See TracBrowser for help on using the repository browser.