MKDoc::Auth::Plugin::Recover_Login - Let users recover their account login.


MKDoc-Auth documentation Contained in the MKDoc-Auth distribution.

Index


Code Index:

NAME

Top

MKDoc::Auth::Plugin::Recover_Login - Let users recover their account login.

SUMMARY

Top

If a user has forgotten their login detail, they can visit /.recover-login.html and enter their email address.

The plugin will select all the user accounts matching the supplied email address and send an email containing matching account information.

INHERITS FROM

Top

MKDoc::Core::Plugin

API

Top

$self->location();

Returns the PATH_INFO which will trigger this plugin.

$self->uri_hint();

Helps deciding what the URI of this plugin should be.

By default, returns 'recover-login.html'.

Can be overriden by setting the MKD__AUTH_RECOVER_LOGIN_URI_HINT environment variable or by subclassing.

$self->http_post();

Selects all the user account matching the supplied email address.

Constructs and sends an email with those account details.

$self->send_mail();

Constructs and sends the email.

TEMPLATE METHODS

Top

self/email

The user supplied email.

self/matching_users

A list of user accounts which match the user supplied emails.


MKDoc-Auth documentation Contained in the MKDoc-Auth distribution.
package MKDoc::Auth::Plugin::Recover_Login;
use MKDoc::Core::Request;
use MKDoc::Auth::TempUser;
use Crypt::PassGen;
use Petal::Mail;
use strict;
use warnings;
use base qw /MKDoc::Core::Plugin/;


sub location
{
    my $self = shift;
    return '/.' . $self->uri_hint();
}


sub uri_hint
{
    return $ENV{MKD__AUTH_RECOVER_LOGIN_URI_HINT} || 'recover-login.html';
}


sub http_post
{
    my $self  = shift;
    $self->{is_post} = '1';

    my $req = MKDoc::Core::Request->instance();

    my $email = $req->param ('email') or do {
        new MKDoc::Core::Error 'auth/plugin/recover_login/email_empty';
        return $self->http_get (@_);
    };
    
    $self->set_email ($email);
    my @users = $self->matching_users();
    scalar @users or do {
        new MKDoc::Core::Error 'auth/plugin/recover_login/no_match';
        return $self->http_get (@_);
    };

    $self->send_mail();
    return $self->http_get (@_);
}


sub send_mail
{
    my $self = shift;
    eval
    {
        my $mail = new Petal::Mail (
            language => $self->language(),
            file     => 'auth/emails/recover_login',
        );

        $mail->send (self => $self);
    };

    $@ and do {
        warn $@;
        new MKDoc::Core::Error 'auth/email/cannot_send';
        return 0;
    };

    return 1;
}


sub set_email
{
    my $self = shift;
    $self->{'.email'} = shift;
}



sub email
{
    my $self = shift;
    return $self->{'.email'};
}


sub matching_users
{
    my $self  = shift;
    my $email = $self->email() || return;
    my $class = $::MKD_Auth_User_CLASS || 'MKDoc::Auth::User';
    my @res   = $class->find_from_email ($email);
    return wantarray ? @res : \@res;
}

 
1;