", which r...">

Need help with routing in Mojolicious

I have a controller Pages using the method < show For "and" auths "with the parameter / strong>", which returns 1 if the user is authenticated. I have a page "default" ("/ profile").

I need to redirect / if the user is authenticated and redirect all pages to / from the authorization form if the user is not authenticated. My code does not want to work properly (auth based on FastNotes sample application) :(

auths # create_form - html-template with an authorization form.

    $r->route('/')       ->to('auths#create_form')   ->name('auths_create_form');
    $r->route('/login')      ->to('auths#create')    ->name('auths_create');
    $r->route('/logout')     ->to('auths#delete')    ->name('auths_delete');
    $r->route('/signup') ->via('get') ->to('users#create_form')   ->name('users_create_form');
    $r->route('/signup') ->via('post') ->to('users#create')    ->name('users_create');
    #$r->route('/profile') ->via('get') ->to('pages#show', id => 'profile') ->name('pages_profile');

    my $rn = $r->bridge('/')->to('auths#check');
    $rn->route        ->to('pages#show', id => 'profile') ->name('pages_profile');

 $rn->route('/core/:controller/:action/:id')
    ->to(controller => 'pages',
   action  => 'show',
   id   => 'profile')
    ->name('pages_profile');

 # Route to the default page controller
 $r->route('/(*id)')->to('pages#show')->name('pages_show');
+5
1

, , / . / , , .

/ ( , ).

my $r = $self->routes;
$r->get('/' => sub {
    my $self = shift;
    # Check whatever you set during authentication
    my $template = $self->session('user') ? '/profile' : '/login';
    $self->render( template => $template );
});

:

  • , Mojolicious:: Lite .
  • under bridge.
  • $r- > get (..) $r- > route (..) → (..)

, .

+11

All Articles