From 1660e9954bd75fe61648bd2a561e3800fdeb7561 Mon Sep 17 00:00:00 2001 From: Finn Date: Fri, 2 Sep 2016 15:01:36 +0100 Subject: [PATCH 1/4] Delete myapp.conf.example --- myapp.conf.example | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 myapp.conf.example diff --git a/myapp.conf.example b/myapp.conf.example deleted file mode 100644 index cfe9b86..0000000 --- a/myapp.conf.example +++ /dev/null @@ -1,6 +0,0 @@ -{ - foo => 'bar', - banana => 'monkey', -# Database connection details - dsn => "dbi:SQLite:dbname=foodloop.db", -}; From 2196641288256407b9ba96b772dc128dff7e23e8 Mon Sep 17 00:00:00 2001 From: Finn Date: Fri, 2 Sep 2016 15:02:05 +0100 Subject: [PATCH 2/4] Delete senddatatodb.pl.example --- senddatatodb.pl.example | 60 ----------------------------------------- 1 file changed, 60 deletions(-) delete mode 100755 senddatatodb.pl.example diff --git a/senddatatodb.pl.example b/senddatatodb.pl.example deleted file mode 100755 index 3b4b0ca..0000000 --- a/senddatatodb.pl.example +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env perl -# NOT READY FOR PRODUCTION - -use Mojolicious::Lite; -use Data::UUID; - -# connect to database -use DBI; - -my $config = plugin Config => {file => 'myapp.conf'}; -my $dbh = DBI->connect($config->{dsn},$config->{user},$config->{pass}) or die "Could not connect"; -use Devel::Dwarn; Dwarn $config; - -# shortcut for use in template -helper db => sub { $dbh }; - -# setup base route -#any '/' => 'index'; - -my $insert; -while (1) { - print "Checking if table exists"; - # create insert statement - $insert = eval { $dbh->prepare('INSERT INTO foodloop (username, company, currency, filename) VALUES (?,?,?,?)') }; - # break out of loop if statement prepared - last if $insert; - print "Make the table!"; -} - -# setup route which receives data and returns to / -post '/' => sub { - my $self = shift; -# Fetch parameters to write to DB - my $key = $self->param('key'); -# This will include an if function to see if key matches -# unless ($key eq $config->{key}) { -# print "key does not match!"; -# } - my $username = $self->param('username'); - my $company = $self->param('company'); - my $currency = $self->param('currency'); - my $file = $self->req->upload('file'); -# Get image type and check extension - my $headers = $file->headers->content_type; -# Is content type wrong? - if ($headers ne 'image/jpeg') { - print "Upload fail. Content type is wrong.\n"; - }; -# Rewrite header data - my $ext = '.jpg'; - my $uuid = Data::UUID->new->create_str; - my $filename = $uuid . $ext; -# send photo to image folder on server - $file->move_to('images/' . $filename); -# send data to foodloop db - $insert->execute($username, $company, $currency, $filename); - $self->render(text => 'It did not kaboom!'); -}; - -app->start; From 687b5489fe98aeb87c9b4cec9821395cb0e98434 Mon Sep 17 00:00:00 2001 From: Finn Date: Fri, 2 Sep 2016 15:02:15 +0100 Subject: [PATCH 3/4] Delete uploadimage.pl --- uploadimage.pl | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 uploadimage.pl diff --git a/uploadimage.pl b/uploadimage.pl deleted file mode 100644 index cc57a85..0000000 --- a/uploadimage.pl +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env perl -use Mojolicious::Lite; -use Mojo:Upload; - -# /?user=sebastian&pass=secr3t -any '/' => sub { - my $c = shift; - - # Query parameters - my $user = $c->param('user') || ''; - my $company = $c->param('company') || ''; - my $currency = $c->param('currency') || ''; - print "$user $company $currency\n"; - use Devel::Dwarn; - Dwarn $c->req; - # Failed - $c->render(text => 'db entry data upload failed.'); -}; - -# Uploading Image -post '/upload' => sub { - my $c = shift; - - my $upload = Mojo::Upload->new; - say $upload->filename; - $upload->move_to('images/' . $upload->filename); - -}; -app->start; From 9ae32896b4c3c943604e9c4ddd1104b7aa2267eb Mon Sep 17 00:00:00 2001 From: Finn Date: Fri, 2 Sep 2016 15:02:23 +0100 Subject: [PATCH 4/4] Delete senddatatodb.pl --- senddatatodb.pl | 55 ------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 senddatatodb.pl diff --git a/senddatatodb.pl b/senddatatodb.pl deleted file mode 100644 index 1d24b6d..0000000 --- a/senddatatodb.pl +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env perl - -use Mojolicious::Lite; -use Data::UUID; - -# connect to database -use DBI; -my $config = plugin Config => {file => 'myapp.conf'}; - -use Devel::Dwarn; Dwarn $config; - -my $dbh = DBI->connect($config->{dsn}) or die "Could not connect"; - -# shortcut for use in template -helper db => sub { $dbh }; - -# setup base route -#any '/' => 'index'; - -my $insert; -while (1) { - # create insert statement - $insert = eval { $dbh->prepare('INSERT INTO foodloop (user, company, currency, filename) VALUES (?,?,?,?)') }; - # break out of loop if statement prepared - last if $insert; - - # if statement didn't prepare, assume its because the table doesn't exist - warn "Creating table 'foodloop'\n"; - $dbh->do('CREATE TABLE foodloop (user varchar(255), company varchar(255), currency int, filename varchar(255));'); -} - -# setup route which receives data and returns to / -post '/' => sub { - my $self = shift; - # Fetch parameters to write to DB - my $user = $self->param('user'); - my $company = $self->param('company'); - my $currency = $self->param('currency'); - my $file = $self->req->upload('file'); - # Get image type and check extension - my $headers = $file->headers->content_type; - # Is content type wrong? - if ($headers ne 'image/jpeg') { - print "Upload fail. Content type is wrong.\n"; - }; - # Rewrite header data - my $ext = '.jpg'; - my $uuid = Data::UUID->new->create_str; - my $filename = $uuid . $ext; - $file->move_to('images/' . $filename); - $insert->execute($user, $company, $currency, $filename); - $self->render(text => 'It did not kaboom!'); -}; - -app->start;