Added check to see if key has been used
This commit is contained in:
parent
f9e850dff9
commit
45bfa2878c
2 changed files with 21 additions and 15 deletions
26
senddatatodb.pl.example
Normal file → Executable file
26
senddatatodb.pl.example
Normal file → Executable file
|
@ -24,37 +24,35 @@ while (1) {
|
|||
$insert = eval { $dbh->prepare('INSERT INTO foodloop (username, company, currency, filename) VALUES (?,?,?,?)') };
|
||||
# break out of loop if statement prepared
|
||||
last if $insert;
|
||||
print "Creating new Table";
|
||||
# if statement didn't prepare, assume its because the table doesn't exist
|
||||
# warn "Creating table 'foodloop'\n";
|
||||
# $dbh->do('CREATE TABLE foodloop (
|
||||
# username varchar(255),
|
||||
# company varchar(255),
|
||||
# currency integer,
|
||||
#filename varchar(255)
|
||||
#);'
|
||||
);
|
||||
print "Make the table!";
|
||||
}
|
||||
|
||||
# setup route which receives data and returns to /
|
||||
post '/' => sub {
|
||||
my $self = shift;
|
||||
# Fetch parameters to write to DB
|
||||
# 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
|
||||
# Get image type and check extension
|
||||
my $headers = $file->headers->content_type;
|
||||
# Is content type wrong?
|
||||
# Is content type wrong?
|
||||
if ($headers ne 'image/jpeg') {
|
||||
print "Upload fail. Content type is wrong.\n";
|
||||
};
|
||||
# Rewrite header data
|
||||
# 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!');
|
||||
};
|
||||
|
|
Reference in a new issue