Permalink
Browse files

Add /logout

  • Loading branch information...
1 parent 1dad8de commit a34157a59b96539df28c7383cd46600e44e287ff @castaway committed Apr 27, 2012
Showing with 40 additions and 8 deletions.
  1. +38 −6 geotrader.cgi
  2. +2 −2 templates/map_page.tt
View
44 geotrader.cgi
@@ -14,18 +14,25 @@ use GoingPlaces::View;
has 'model' => (is => 'ro', lazy => 1, builder => '_build_model');
has 'view' => (is => 'ro', lazy => 1, builder => '_build_view');
+has 'host' => (is => 'ro', default => 'http://desert-island.me.uk');
+has 'base_uri' => (is => 'ro', default => '/cgi-bin/geotrader.cgi');
+has 'app_cwd' => ( is => 'ro', default => '/mnt/shared/projects/cardsapp');
+has 'static_uri' => ( is => 'ro', default => '/~castaway/cardsapp');
+
sub _build_model {
+ my ($self) = @_;
return GoingPlaces::Model->new(
- base_uri => '/cgi-bin/geotrader.cgi',
- app_cwd => '/mnt/shared/projects/cardsapp',
+ base_uri => $self->base_uri,
+ app_cwd => $self->app_cwd,
);
}
sub _build_view {
+ my ($self) = @_;
return GoingPlaces::View->new(
- base_uri => '/cgi-bin/geotrader.cgi',
- static_uri => '/~castaway/cardsapp',
- app_cwd => '/mnt/shared/projects/cardsapp',
+ base_uri => $self->base_uri,
+ static_uri => $self->static_uri,
+ app_cwd => $self->app_cwd,
);
}
@@ -57,12 +64,27 @@ sub dispatch_request {
if($user) {
# Turtles all the way down!
return ($self->set_authenticated($user),
- [ 200, [ 'Content-type', 'text/html' ], [ 'Login succeeded' ]]);
+ [ 303, [ 'Content-type', 'text/html',
+ 'Location', $self->host . $self->base_uri . '/map' ],
+ [ 'Login succeeded, back to <a href="' . $self->host . $self->base_uri . '/map' . '"></a>' ]]);
} else {
return [ 200, [ 'Content-type', 'text/html' ], [ 'Login failed' ]];
}
},
+ sub (GET + /logout) {
+ my ($self) = @_;
+
+ if($user) {
+ $user = undef;
+ }
+
+ return ($self->logout,
+ [ 303, [ 'Content-type', 'text/html',
+ 'Location', $self->host . $self->base_uri . '/map' ],
+ [ 'Login succeeded, back to <a href="' . $self->host . $self->base_uri . '/map' . '"></a>' ]]);
+ },
+
sub (POST + /create_user + %username=&password=&display=) {
my ($self, $usern, $passw, $display) = @_;
@@ -164,6 +186,16 @@ sub set_authenticated {
);
}
+sub logout {
+ my ($self) = @_;
+ return (
+ $self->ensure_session,
+ sub {
+ delete $_[PSGI_ENV]->{'psgix.session'}{user_info};
+ }
+ );
+}
+
sub check_authenticated {
my ($self) = @_;
my $user_ref = \$_[1];
View
4 templates/map_page.tt
@@ -11,13 +11,13 @@
<ul id="login">
<li>
[% IF !user %]
- <form method="post" action="/cgi-bin/geotrader.cgi/login">
+ <form method="post" action="[% base_uri %]/login">
Username <input type="text" id="profile" name="username">
Password <input type="password" id="profile" name="password">
<input type="submit" value="Login">
</form>
[% ELSE %]
- Hello again, [% user.display_name %] !
+ Hello again, [% user.display_name %] ! | <a href="[% base_uri %]/logout">Logout</a>
[% END %]
</li>
</ul>

0 comments on commit a34157a

Please sign in to comment.