package LATMOS::Accounts::Web::Controller::Remote::AskPwReset;
use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller'; }

=head1 NAME

LATMOS::Accounts::Web::Controller::Remote::AskPwReset - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index

=cut

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    my $url = $c->req->param('url');

    my $username = $c->req->param('user') or do {
        return;
    };

    my $user = $c->model('Accounts')->db->get_object('user', $username) or do {
        $c->stash->{data}{err} = 'No such user';
        $c->log->debug($c->stash->{data}{err});
        return;
    };

    if (!$user->_get_attributes('active')) {
        $c->stash->{data}{err} = 'No such user';
        $c->log->debug($c->stash->{data}{err});
        return;
    }

    if (!$user->SendPasswordReset($url)) {
        $c->stash->{data}{err} = 'unknown error';
        $c->log->debug($c->stash->{data}{err});
        return;
    } else {
        $c->stash->{data}{ok} = 'Done';
        $user->base->commit;
        return 
    }
}



=encoding utf8

=head1 AUTHOR

Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

1;
