-
-
Save ufobat/72aceef40b683339a38e88336d6be3e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test; | |
use Bailador::App; | |
use Bailador::Route; | |
use Bailador::Test; | |
plan 8; | |
class MyOwnWebApp is Bailador::App { | |
submethod BUILD(|) { | |
# config | |
self.sessions-config.cookie-expiration = 5; | |
# routes | |
self.post: '/login/:user' => sub { | |
my $user = @_[0]; | |
my $session = self.session; | |
$session<user> = $user; | |
diag "session: " ~ $session; | |
self.render: "logged in"; | |
} | |
my $route = Bailador::Route.new: path => /.*/, code => sub { | |
# go deeper into the nested routes | |
my $session = self.session; | |
if self.session<user> { | |
diag "condition route: session available"; | |
return True | |
} | |
# go to a next route that matches the request | |
diag "condition route: no session available"; | |
return False; | |
}; | |
$route.get: '/app/something' => sub { | |
self.render: "no need to check if we're logged in"; | |
}; | |
$route.get: '/logout' => sub { | |
self.session-delete; | |
self.render: "logged out"; | |
}; | |
self.add_route: $route; | |
# catch all route | |
self.get: /.*/ => sub { | |
self.session-delete; | |
self.render: "this is the login page / catch all route"; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment