【发布时间】:2023-04-01 19:42:01
【问题描述】:
我有带有“show”方法的“Pages”控制器和带有“checkAuths”控制器/strong>" 方法,如果用户通过身份验证,则返回 1。 我有“默认”页面(“/profile”)。
如果用户通过身份验证,我需要重定向到 /,如果用户未通过身份验证,我需要使用授权表单将所有页面重定向到 /。我的代码不想正常工作(基于 FastNotes 示例应用程序的身份验证):(
auths#create_form - 带有授权表单的 html 模板。
$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');
【问题讨论】:
-
您能解释一下“不想正常工作”是什么意思吗?您已经解释了它应该做什么,但没有解释实际发生的情况。
-
你确定 check() 在预期的时候返回 true 吗?
标签: perl authentication routing mojolicious