Back-end stuff to get the URL field working
This commit is contained in:
parent
fb8cc6427e
commit
d9b114f9ea
|
@ -63,10 +63,11 @@ get '/' => sub ($c) {
|
||||||
any [qw{GET POST}], '/sign' => sub ($c) {
|
any [qw{GET POST}], '/sign' => sub ($c) {
|
||||||
if ($c->req->method() eq 'POST' && $c->param('message')) {
|
if ($c->req->method() eq 'POST' && $c->param('message')) {
|
||||||
my $name = $c->param('name') || 'Anonymous';
|
my $name = $c->param('name') || 'Anonymous';
|
||||||
|
my $url = $c->param('url');
|
||||||
my $message = $c->param('message');
|
my $message = $c->param('message');
|
||||||
my $answer = $c->param('answer');
|
my $answer = $c->param('answer');
|
||||||
|
|
||||||
$c->message->create_post($name, $message) if $answer;
|
$c->message->create_post($name, $message, $url) if $answer;
|
||||||
$c->redirect_to('index');
|
$c->redirect_to('index');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -93,7 +94,7 @@ app->secrets(app->config->{'secrets'}) || die $@;
|
||||||
app->message->max_posts(app->config->{'max_posts'})
|
app->message->max_posts(app->config->{'max_posts'})
|
||||||
if app->config->{'max_posts'};
|
if app->config->{'max_posts'};
|
||||||
|
|
||||||
app->pg->migrations->from_dir('migrations')->migrate(3);
|
app->pg->migrations->from_dir('migrations')->migrate(4);
|
||||||
|
|
||||||
app->asset->store->paths(['assets']);
|
app->asset->store->paths(['assets']);
|
||||||
app->asset->process('swagg.css', 'css/swagg.css');
|
app->asset->process('swagg.css', 'css/swagg.css');
|
||||||
|
|
|
@ -38,11 +38,19 @@ sub get_posts($self, $this_page = undef) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub create_post($self, $name, $message) {
|
sub create_post($self, $name, $message, $url = undef) {
|
||||||
$self->pg->db->query(<<~'END_SQL', $name, $message)
|
if ($url) {
|
||||||
INSERT INTO messages (message_date, visitor_name, message)
|
$self->pg->db->query(<<~'END_SQL', $name, $url, $message)
|
||||||
VALUES (NOW(), ?, ?);
|
INSERT INTO messages (message_date, visitor_name, homepage_url, message)
|
||||||
END_SQL
|
VALUES (NOW(), ?, ?, ?);
|
||||||
|
END_SQL
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$self->pg->db->query(<<~'END_SQL', $name, $message)
|
||||||
|
INSERT INTO messages (message_date, visitor_name, message)
|
||||||
|
VALUES (NOW(), ?, ?);
|
||||||
|
END_SQL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub max_posts($self, $value = undef) {
|
sub max_posts($self, $value = undef) {
|
||||||
|
|
2
migrations/4/down.sql
Normal file
2
migrations/4/down.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE messages
|
||||||
|
DROP COLUMN homepage_url;
|
2
migrations/4/up.sql
Normal file
2
migrations/4/up.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE messages
|
||||||
|
ADD homepage_url VARCHAR(256);
|
|
@ -10,6 +10,7 @@ my $script = curfile->dirname->sibling('guestbook-ng.pl');
|
||||||
my $t = Test::Mojo->new($script);
|
my $t = Test::Mojo->new($script);
|
||||||
my %form = (
|
my %form = (
|
||||||
name => 'swagg boi',
|
name => 'swagg boi',
|
||||||
|
url => 'http://localhost',
|
||||||
message => 'Ayy... lmao',
|
message => 'Ayy... lmao',
|
||||||
answer => 'false'
|
answer => 'false'
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user