Lance Wicks
lancew@cpan.org
Hi !
This is a workshop for beginners, no advanced content here.
We will go from zero to full site up, running and ready for users.
All steps including a virtual box appliance with all pre-requisites:
3 x USB Sticks are available
You might want to try installing Perl6 with chocolatey
choco install rakudostar
zef install Bailador
apt get rakudo
packer -S rakudo
From your distro
use v6; use Bailador; get '/' => sub { "hello london" } baile();
c63e1081b71706244fe8a594d060402f22ae49d6
$ bailador watch hello_london.pl6
or
$ perl6 hello_london.pl6
$ bailador new lpw2017
08153d854eedbe8f881077fbad05070e739ea153
/bin/app.pl6
/views
/t
<%= $foo %>
Lets make it look a bit prettier and serve some static content:
/static
/static/favicon.ico
/static/css
/static/js
static-dir / (.+) / => 'static/';
03b74e0101f74986e7d3961929b0f6a3fe4c7993
Start using a layout
/layout
/layout/main.tt
Simpler template
81ea6f5976fb7b3618736c485609c99230540a09
Create a login route
+post '/login' => sub {
+ my %params = request.params;
+ if (
+ %params<email> eq 'lancew@cpan.org'
+ && %params<password> eq 'london'
+ ) {
+ return 'Logged in';
+ } else {
+ return 'not logged in';
+ }
+};
46f960bd6ed4a0cdda2d165281c361445ba460b2
Sessions
kludge to show login or logout depending on session.
Perl6 in templates:
+% use Bailador;
+% my $session = session;
+ % if ( $session<user_email>:exists ) {
dbf1a07368b5bb06b1e6f3a5093fb33026978c34
/register route
+ my $dbh = DBIish.connect("SQLite", :database<db/lpw2017.db>);
+
+ my $sth = $dbh.prepare(q:to/STATEMENT/);
+ INSERT INTO users
+ (username,password_hash)
+ VALUES (?,?)
+ STATEMENT
+
+ my $hash = bcrypt-hash(%params<password>);
+ $sth.execute(%params<email>,$hash);
401359f9c7da2ac5232834a8ebbdd41a11651fa4
Database a bcrypt based login
+ if ( bcrypt-match(%params<password>, $hash) ) {
+ $password_is_correct = True;
+ }
dfedd783db1e8ca4d347cf384a86ba1c9adc2f3b