1
我剛剛開始與Dancer :: Session :: Cookie,我遇到了一些我並不期待的行爲。我將一個簡單的Perl Dancer應用程序放在一起,以使用Authen :: Simple :: ActiveDirectory進行身份驗證。我的路線如下。Perl Dancer Session Cookies
package auth;
use Dancer ':syntax';
our $VERSION = '0.1';
get '/' => sub {
template 'index', {user => session->{user}};
};
hook 'before' => sub {
if (! session('user') && request->path_info !~ m{^/login}) {
var requested_path => request->path_info;
request->path_info('/login');
}
};
get '/login' => sub {
# Display a login page; the original URL they requested is available as
# vars->{requested_path}, so could be put in a hidden field in the form
template 'login', { path => vars->{requested_path} };
};
post '/login' => sub {
# Validate the username and password they supplied
my $ad = Authen::Simple::ActiveDirectory->new(
host => 'host',
principal => 'example.com'
);
if ($ad->authenticate(params->{user}, params->{pass})) {
session user => params->{user};
redirect params->{path} || '/';
} else {
redirect '/login?failed=1';
}
};
get '/logout' => sub {
session->destroy;
redirect '/';
};
true;
我能夠成功登錄並創建一個會話。登錄後,我的用戶名被放置在主頁面上,並且有一個指向/ logout路徑的鏈接。當我點擊該鏈接時,路由被執行(我在調試器中確認了這一點),但是我仍然顯示我的用戶名並返回主頁面。我希望能夠返回到登錄頁面,因爲沒有會話存在。任何想法爲什麼舞者這樣做?我誤解了會議的工作方式嗎?