This file is indexed.

/usr/share/perl5/Jifty/Plugin/Authentication/Bitcard/Dispatcher.pm is in libjifty-plugin-authentication-bitcard-perl 0.053-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
use strict;
use warnings;

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

our $VERSION = '0.053';

=head1 NAME

Jifty::Plugin::Authentication::Bitcard::Dispatcher - Bitcard plugin dispatcher

=head1 DESCRIPTION

All the dispatcher rules jifty needs to support L<Jifty::Authentication::Bitcard/>

=head1 RULES

=head2 before /logout

Logout and return home.

=cut

before qr{^/logout} => run {
    unless (Jifty->web()->current_user()->id()) {
        redirect(Jifty->web()->request()->argument('return') ? Jifty->web()->request()->argument('return') : '/');
    }

    my $return_url = Jifty->web()->url();
    $return_url =~ s{/$}{};
    $return_url .= Jifty->web()->request()->argument('return');

    Jifty->web()->current_user(undef);
    my ($plugin) = Jifty->find_plugin('Jifty::Plugin::Authentication::Bitcard');
    Jifty->web()->_redirect($plugin->api()->logout_url(
        r => $return_url,
    ));
};

=head2 before *

Setup the navigation menu for login or logout.

=cut

before '*' =>  run {
    if (Jifty->web()->current_user()->id()) {
        logged_in_nav();
    }
    else {
        not_logged_in_nav();
    }
};

=head2 on /signup

Redirect to home if logged in already.

Signup for an account otherwise.

=cut

before qr{^/signup$} => run {
    if (Jifty->web()->current_user()->id()) {
        redirect(Jifty->web()->request()->argument('return') ? Jifty->web()->request()->argument('return') : '/');
    }

    my ($plugin) = Jifty->find_plugin('Jifty::Plugin::Authentication::Bitcard');

    Jifty->web()->_redirect($plugin->api()->register_url(
        r => Jifty->web()->url(path => '/bitcard_signup?return=' . Jifty->web()->request()->argument('return')),
    ));
};

=head2 on /login

Redirect to home if logged in already.

Redirecto to Bitcard, otherwise.

=cut

before '/login' => run {
    if (Jifty->web()->current_user()->id()) {
        redirect(Jifty->web()->request()->argument('return') ? Jifty->web()->request()->argument('return') : '/');
    }

    my ($plugin) = Jifty->find_plugin('Jifty::Plugin::Authentication::Bitcard');

    Jifty->web()->_redirect($plugin->api()->login_url(
        r        => Jifty->web()->url(path => '/bitcard_login?return=' . Jifty->web()->request()->argument('return')),
    ));
};

=head2 before /bitcard_(login|signup)

Verify the bitcard login.

=cut

before qr{^/bitcard_(?:login|signup)} => run {
    if (Jifty->web()->current_user()->id()) {
        redirect(Jifty->web()->request()->argument('return') ? Jifty->web()->request()->argument('return') : '/');
    }

    my ($plugin) = Jifty->find_plugin('Jifty::Plugin::Authentication::Bitcard');
    my $verified = $plugin->api()->verify(Jifty->handler()->cgi());

    unless (defined $verified) {
        redirect(Jifty->web()->request()->argument('return') ? Jifty->web()->request()->argument('return') : '/');
    }


    my $bitcard_id = $verified->{'id'};
    my $username   = $verified->{'username'};
    my $name       = $verified->{'name'};
    my $email      = $verified->{'email'};

    my $user = Jifty->app_class("Model", "User")->new(current_user => Jifty->app_class("CurrentUser")->superuser );

    $user->load_by_cols( bitcard_id => $bitcard_id );

    if ( $user->id ) {
        $user->__set(column => 'email', value => $email);
        $user->__set(column => 'name', value => $name);
    }
    else {
        $user->create(
            bitcard_id       => $bitcard_id,
            bitcard_username => $username,
            name             => $name,
            email            => $email,
        );
    }

    my $current_user = Jifty->app_class("CurrentUser")->new( bitcard_id => $bitcard_id );

    # Actually do the signin thing.
    Jifty->web()->current_user($current_user);
    Jifty->web()->session()->expires(undef);
    Jifty->web()->session()->set_cookie();

    redirect(Jifty->web()->request()->argument('return') ? Jifty->web()->request()->argument('return') : '/');
};

=head2 not_logged_in_nav

Adds the login and signup links to the navigation menu.

=cut

sub not_logged_in_nav {
    my $current_path = Jifty->web()->request()->path();

    Jifty->web->navigation->child(
        'Signup',
        label        => _('Signup'),
        url          => "/signup?return=$current_path",
        sort_order   => '950',
    );
    Jifty->web->navigation->child(
        'Login',
        label        => _('Login'),
        url          => "/login?return=$current_path",
        sort_order   => '999',
    );
}

=head2 logged_in_nav

Adds the logout link to the navigation menu.

=cut

sub logged_in_nav {
    my $current_path = Jifty->web()->request()->path();

    Jifty->web->navigation->child(
        'Logout',
        label      => _('Logout'),
        url        => "/logout?return=$current_path",
        sort_order => '999'
    );
}

=head1 SEE ALSO

L<Jifty::Plugin::Authentication::Bitcard>,

=head1 COPYRIGHT

Copyright 2008 Jacob Helwig.
Distributed under the same terms as Perl itself.

=cut

1;