Jifty::Plugin::Authentication::Password::Dispatcher - password plugin dispatcher


Jifty documentation Contained in the Jifty distribution.

Index


Code Index:

NAME

Top

Jifty::Plugin::Authentication::Password::Dispatcher - password plugin dispatcher

DESCRIPTION

Top

All the dispatcher rules jifty needs to support Jifty::Authentication::Password/

RULES

Top

before logout

Logout and return home.

See Jifty::Plugin::Authentication::Password::Action::Logout.

before *

Setup the navigation menu for login or logout.

on qr/^(?:signup|lost_password)$/

Redirect to home if logged.

Request a password reminder or signup for an account otherwise.

on login

Redirect to home if logged.

Show the login form otherwise.

before reset_lost_password

Request a password reset.

before passwordreminder

Request a new password reminder to be sent by email.

See Jifty::Plugin::Authentication::Password::Action::SendPasswordReminder.

before signup

Sign up for an account.

See Jifty::Plugin::Authentication::Password::Action::Signup.

before login

Login to your account.

See Jifty::Plugin::Authentication::Password::Action::Login.

not_logged_in_nav

Adds the login and signup links to the navigation menu.

logged_in_nav

Adds the logout link to the navigation menu.

SEE ALSO

Top

Jifty::Plugin::Authentication::Password, Jifty::Plugin::Authentication::Password::View

COPYRIGHT

Top


Jifty documentation Contained in the Jifty distribution.
use strict;
use warnings;

package Jifty::Plugin::Authentication::Password::Dispatcher;
use Jifty::Dispatcher -base;

before 'logout' => run {
    Jifty->web->new_action( class => 'Logout', moniker => 'logout')->run;
    redirect '/';
};

# Make sure tangents work 
# Before password reminders, login or signup, let's push the user off to the homepage if they're logged in

before '*' =>  run {
    my ($ap) = Jifty->find_plugin('Jifty::Plugin::Authentication::Password')
        or return;

    return unless $ap->nav_menu;

    if ( Jifty->web->current_user->id ) {
        logged_in_nav();
    } else {
        not_logged_in_nav();

    }

};

before qr'^/(?:signup|lost_password)$' => run {
    redirect('/') if ( Jifty->web->current_user->id );
    set 'next' => Jifty->web->request->continuation || Jifty::Continuation->new( request => Jifty::Request->new( path => "/login" ) );
};

before qr|^/(?:login)$| => run {
    redirect('/') if ( Jifty->web->current_user->id );
    set 'next' => Jifty->web->request->continuation || Jifty::Continuation->new( request => Jifty::Request->new( path => "/" ) );
};

before qr|(?:reset_lost_password)| => run {
    set 'next' => Jifty->web->request->continuation || Jifty::Continuation->new( request => Jifty::Request->new( path => "/" ) );
};
# Send a password reminder for a lost password

before 'passwordreminder' => run {
    set 'action' => Jifty->web->new_action( class => 'SendPasswordReminder', moniker => 'password_reminder');
};


before 'signup' => run {
    set 'action' => Jifty->web->new_action( class => 'Signup');

};

before 'login' => run {
    set 'action' => Jifty->web->new_action( class => 'Login');
};

sub not_logged_in_nav {
    Jifty->web->navigation->child(
        'Login',
        link => Jifty->web->tangent(
            label => _('Login'),
            url   => '/login'
        ),
        sort_order => '999'
    );
    Jifty->web->navigation->child(
        'Signup',
        link => Jifty->web->tangent(
            label => _('Sign up'),
            url   => '/signup'
        ),
        sort_order => '950'
    );
}

sub logged_in_nav {
    Jifty->web->navigation->child(
        Logout  => label => _('Logout') =>
            url => '/logout',
        sort_order => '999'
    );

}

1;