Skip to content

zby/WebPrototypes-ResetPass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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

About

A plack component implementing the common reset forgotten password mechanism

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages