Zbigniew Łukasiak > WebPrototypes-ResetPass > WebPrototypes::ResetPass

Download:
WebPrototypes-ResetPass-0.002.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.002   Source  

NAME ^

WebPrototypes::ResetPass - (Experimental) Plack application for sending a 'Reset password link' via email

VERSION ^

version 0.002

SYNOPSIS ^

    # connecting with DBIx::Class
    {
        package My::ResetPass;
        use parent 'WebPrototypes::ResetPass';
        use Plack::Util::Accessor qw( schema );

        sub find_user {
            my( $self, $name ) = @_;
            my $user = $schema->resultset( 'User' )->search({ username =>  $name })->next;
            return $user, $user->email, $user->pass_token if $user;
            return;
        }

        sub update_user {
            my( $self, $user, $attrs ) = @_;
            $user->update( $attrs ); 
        }

    }

    use Plack::Builder;

    my $app = My::ResetPass->new( schema => $schema );

    builder {
        mount "/forgotten_pass" => builder {
            $app->to_app;
        };
    };

DESCRIPTION ^

This application implements the common reset forgotten password mechanism in a storage independent way. The examples here are with DBIx::Class but they can be easily ported to other storage layers.

It has two pages. First page where the user enters his login details and if they are correct an email with a link (with a random verification token) to the password reset page is sent. Second page - the password reset page - checks the token - and lets the user to choose a new password.

This application uses the Template Method design pattern.

PURE VIRTUAL METHODS

These methods need to be overriden in subclass.

find_user ( name )

Should return a following tuple $user, $user_email, $verification_token

The $user is user object or user id - passed to the update_user method

update_user ( user, params )

Should update the user object with params. It is used for saving the new password and verification token.

VIRTUAL METHODS

These methods have defaults - but should probably be overriden anyway.

wrap_text ( text )

Should return the html page containing the passed text fragment. By default it just adds the html and body tags.

build_reply ( page_body )

Should return the PSGI response data structure.

build_email ( to_address, link_to_the_reset_page )

Should create the email containing the link.

send_mail ( mail )

Should send the mail (created by build_mail).

OTHER METHODS

call ( env )

SEE ALSO ^

Plack Plack::Middleware::Auth::Form

AUTHOR ^

Zbigniew Lukasiak <zby@cpan.org>

COPYRIGHT AND LICENSE ^

This software is Copyright (c) 2011 by Zbigniew Lukasiak <zby@cpan.org>.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
syntax highlighting: