Skip to content

Instantly share code, notes, and snippets.

@pavelsr
Last active April 12, 2020 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavelsr/ab24ac5972df2ac9b6983e3b501252f6 to your computer and use it in GitHub Desktop.
Save pavelsr/ab24ac5972df2ac9b6983e3b501252f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# Demo of 'CSRF token validation failed' error
use Mojolicious::Lite;
use Mojo::SQLite;
helper sqlite => sub {
state $path = app->home->child( 'data.db' );
state $sqlite = Mojo::SQLite->new( 'sqlite:' . $path );
return $sqlite;
};
app->sqlite->auto_migrate(1)->migrations->from_data;
plugin Yancy => {
backend => { Sqlite => app->sqlite },
read_schema => 1
};
get '/' => sub {
my ( $c ) = @_;
$c->render( template => 'index');
};
app->routes->post( '/cu' )->to( 'yancy#set', schema => 'users' );
app->start;
__DATA__
@@ migrations
-- 1 up
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY,
email VARCHAR UNIQUE,
is_admin BOOLEAN DEFAULT FALSE,
password VARCHAR
);
@@ index.html.ep
% layout 'default';
% title 'Demo of issue #95';
%= app->yancy->form->form_for( 'users', properties => [ qw/email password/ ], action => '/cu' )
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment