Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tons of great stuff: Use the actual base name and confirm deletes

  • Loading branch information...
commit f606dd8a6c4fb6bc7e021c4e08d3a60d06b2964c 1 parent 160add8
@kevinj kevinj authored
View
45 lib/App/VanTrash/Controller.pm
@@ -18,6 +18,7 @@ has 'mimetypes' => (is => 'ro', lazy_build => 1);
has 'http_module' => (is => 'ro', isa => 'Str', required => 1);
has 'http_args' => (is => 'ro', isa => 'HashRef', default => sub { {} });
has 'base_path' => (is => 'ro', isa => 'Str', required => 1);
+has 'request' => (is => 'rw', isa => 'HTTP::Engine::Request');
has 'logger' =>
(default => sub { App::VanTrash::Log->new }, handles => ['log']);
@@ -27,6 +28,8 @@ sub handle_request {
my $self = shift;
my $req = shift;
+ $self->request($req);
+
my $coord = qr{[+-]?\d+\.\d+};
my $path = $req->path;
@@ -385,24 +388,39 @@ sub put_reminder {
return $resp;
}
+sub _remove_slash {
+ (my $url = shift) =~ s{/$}{};
+ return $url;
+}
+
sub delete_reminder_html {
my $self = shift;
my $req = shift;
my $zone = shift;
my $id = shift;
- if (my $rem = $self->model->delete_reminder($id)) {
- my $resp = $self->process_template('zones/reminders/good_delete.html', {
- reminder => $rem,
- });
- $self->log("DELETE $zone $id");
- $resp->status(200);
+ my $rem = $self->model->reminders->by_id($id);
+ $rem->base_url(_remove_slash($req->base));
+ unless ($rem) {
+ $self->log("DELETE_FAIL $zone $id");
+ my $resp = $self->process_template(
+ 'zones/reminders/bad_delete.html'
+ );
+ $resp->status(404);
return $resp;
}
- $self->log("DELETE_FAIL $zone $id");
- my $resp = $self->process_template('zones/reminders/bad_delete.html');
- $resp->status(404);
+ my $template = 'zones/reminders/confirm_delete.html';
+ if ($req->params->{confirm}) {
+ $template = 'zones/reminders/good_delete.html';
+ $self->model->delete_reminder($id);
+ $self->log("DELETE $zone $id");
+ }
+
+ my $resp = $self->process_template($template, {
+ reminder => $rem,
+ });
+ $resp->status(200);
return $resp;
}
@@ -430,6 +448,8 @@ sub tell_friends {
template => 'tell-a-friend.html',
template_args => {
friend_email => $sender_email,
+ base => _remove_slash($self->request->base),
+ request_uri => $self->request->request_uri,
},
);
}
@@ -486,7 +506,10 @@ sub _build_engine {
sub _build_model {
my $self = shift;
- return App::VanTrash::Model->new( base_path => $self->base_path );
+ return App::VanTrash::Model->new(
+ base_path => $self->base_path,
+ base_url => _remove_slash($self->request->base),
+ );
}
sub process_template {
@@ -495,6 +518,8 @@ sub process_template {
my $param = shift;
my $html;
$param->{version} = $VERSION;
+ $param->{base} = _remove_slash($self->request->base);
+ $param->{request_uri} = $self->request->request_uri;
$self->template->process($template, $param, \$html)
|| die $self->template->error;
my $res = HTTP::Engine::Response->new(body => $html);
View
2  lib/App/VanTrash/Model.pm
@@ -19,6 +19,7 @@ use Data::Dumper;
use namespace::clean -except => 'meta';
has 'base_path' => (is => 'ro', isa => 'Str', required => 1);
+has 'base_url' => (is => 'ro', isa => 'Str', required => 1);
has 'areas' => (is => 'ro', isa => 'Object', lazy_build => 1);
has 'zones' => (is => 'ro', isa => 'Object', lazy_build => 1);
has 'pickups' => (is => 'ro', isa => 'Object', lazy_build => 1);
@@ -122,6 +123,7 @@ sub add_reminder {
$rem->{next_pickup} = $next_pickup_dt->epoch;
my $robj = eval { $self->reminders->add($rem) };
+ $robj->base_url($self->base_url);
my $err = "Unknown error";
if ($err = $@) {
warn "Error inserting reminder: " . Dumper($rem);
View
12 lib/App/VanTrash/Schema/Result/Reminder.pm
@@ -23,7 +23,9 @@ has 'nice_zone' => (is => 'ro', isa => 'Str', lazy_build => 1);
has 'confirm_url' => (is => 'ro', isa => 'Str', lazy_build => 1);
has 'delete_url' => (is => 'ro', isa => 'Str', lazy_build => 1);
has 'short_delete_url' => (is => 'ro', isa => 'Str', lazy_build => 1);
-has 'base_url' => (is => 'ro', isa => 'Str', lazy_build => 1);
+has 'zone_url' => (is => 'ro', isa => 'Str', lazy_build => 1);
+
+has 'base_url' => (is => 'rw', isa => 'Str', default => 'http://vantrash.ca');
sub _build_nice_name {
my $self = shift;
@@ -40,12 +42,12 @@ sub _build_nice_zone {
sub _build_confirm_url {
my $self = shift;
- return $self->base_url . $self->confirm_hash . '/confirm';
+ return join '/', $self->zone_url, $self->confirm_hash, 'confirm';
}
sub _build_delete_url {
my $self = shift;
- return $self->base_url . $self->id . '/delete';
+ return join '/', $self->zone_url, $self->id, 'delete';
}
sub _build_short_delete_url {
@@ -53,10 +55,10 @@ sub _build_short_delete_url {
return makeashorterlink($self->delete_url);
}
-sub _build_base_url {
+sub _build_zone_url {
my $self = shift;
my $type = shift || 'id';
- return 'http://vantrash.ca/zones/' . $self->zone . '/reminders/';
+ return join '/', $self->base_url, 'zones', $self->zone, 'reminders';
}
sub to_hash {
View
9 static/css/styles.css
@@ -237,12 +237,15 @@ a img {
}
.success {
- padding: 60px;
- font-size: 220%;
- background-color: #a5c880;
+ font-size: 120%;
}
.error {
color: #FF4949;
+ font-size: 120%;
+}
+
+.pad {
+ padding: 60px;
}
.wizard .slide {
View
2  template/email/notification.html
@@ -10,7 +10,7 @@
Click here to tell your friends about VanTrash:
- http://vantrash.ca/tell-a-friend.html
+ [% base %]/tell-a-friend.html
Cheers,
The VanTrash Team
View
4 template/email/reminder-success.html
@@ -14,9 +14,9 @@
If you're excited about the garbage pick-up reminder service (and we hope you are!) please tell your friends about us by clicking the link below:
- http://vantrash.ca/tell-a-friend.html
+ [% base %]/tell-a-friend.html
-Finally, if you think this service useful, please do consider supporting us: http://vantrash.ca/donate.html
+Finally, if you think this service useful, please do consider supporting us: [% base %]/donate.html
Cheers,
The VanTrash Team
View
2  template/email/tell-a-friend.html
@@ -11,7 +11,7 @@
It's a little service we created for our friends and thought we'd offer it
up to the citizens of Vancouver.
-Come visit us at: http://vantrash.ca
+Come visit us at: [% base %]
Cheers,
The VanTrash Team
View
2  template/zones/reminders/bad_confirm.html
@@ -1,5 +1,5 @@
[% WRAPPER wrapper.tt2 %]
- <div class="error">
+ <div class="pad error">
<p>
Sorry, we could not find a valid reminder at this address.<br />
</p>
View
2  template/zones/reminders/bad_delete.html
@@ -1,5 +1,5 @@
[% WRAPPER wrapper.tt2 %]
- <div class="error">
+ <div class="pad error">
<p>
Sorry, we couldn't find a reminder to delete at this location.
</p>
View
15 template/zones/reminders/good_confirm.html
@@ -1,10 +1,9 @@
[% WRAPPER wrapper.tt2 %]
- <div class="success">
- <p>
- Thank you for confirming your email, [% reminder.email %].
- </p>
- <p>
- I will send you an email with all the details. --VanTrash
- </p>
- </div>
+<div class="pad success">
+ <p>
+ Thank you for confirming your email,
+ <i>[% reminder.email %]</i>.
+ </p>
+ <p>You will soon receive an email with all the details.</p>
+</div>
[% END %]
View
2  template/zones/reminders/good_delete.html
@@ -1,5 +1,5 @@
[% WRAPPER wrapper.tt2 %]
- <div class="success">
+ <div class="pad success">
<p>
The following garbage reminder has been deleted:<br />
<ul>
Please sign in to comment.
Something went wrong with that request. Please try again.