From bd927eba6615a24587ee0ec566e34ee3972362dd Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 5 Nov 2013 13:13:02 +0100 Subject: [PATCH] Make sign in a modal dialog box rather than a separate page --- src/lib/Hydra/Controller/User.pm | 36 +++++++---------------------- src/root/layout.tt | 39 ++++++++++++++++++++++++++++++++ src/root/login.tt | 36 ----------------------------- src/root/topbar.tt | 2 +- 4 files changed, 48 insertions(+), 65 deletions(-) delete mode 100644 src/root/login.tt diff --git a/src/lib/Hydra/Controller/User.pm b/src/lib/Hydra/Controller/User.pm index 04109f11..49f67974 100644 --- a/src/lib/Hydra/Controller/User.pm +++ b/src/lib/Hydra/Controller/User.pm @@ -18,39 +18,19 @@ __PACKAGE__->config->{namespace} = ''; sub login :Local :Args(0) :ActionClass('REST::ForBrowsers') { } -sub login_GET { - my ($self, $c) = @_; - - my $baseurl = $c->uri_for('/'); - my $referer = $c->request->referer; - $c->session->{referer} = $referer if defined $referer && $referer =~ m/^($baseurl)/; - - $c->stash->{template} = 'login.tt'; -} - sub login_POST { my ($self, $c) = @_; - my $username; - my $password; + my $username = $c->stash->{params}->{username} // ""; + my $password = $c->stash->{params}->{password} // ""; - $username = $c->stash->{params}->{username}; - $password = $c->stash->{params}->{password}; + error($c, "You must specify a user name.") if $username eq ""; + error($c, "You must specify a password.") if $password eq ""; - if ($username && $password) { - if ($c->authenticate({username => $username, password => $password})) { - if ($c->request->looks_like_browser) { - backToReferer($c); - } else { - currentUser_GET($self, $c); - } - } else { - $self->status_forbidden($c, message => "Bad username or password."); - if ($c->request->looks_like_browser) { - login_GET($self, $c); - } - } - } + accessDenied($c, "Bad username or password.") + if !$c->authenticate({username => $username, password => $password}); + + $self->status_ok($c, entity => { }); } diff --git a/src/root/layout.tt b/src/root/layout.tt index 70236b17..2237e79b 100644 --- a/src/root/layout.tt +++ b/src/root/layout.tt @@ -146,6 +146,45 @@ [% END %] + [% IF !c.user_exists %] + + + + [% END %] + diff --git a/src/root/login.tt b/src/root/login.tt deleted file mode 100644 index 9963c497..00000000 --- a/src/root/login.tt +++ /dev/null @@ -1,36 +0,0 @@ -[% WRAPPER layout.tt title="Sign in" %] -[% PROCESS common.tt %] - -[% IF c.user_exists %] -

-You are already signed in as [% HTML.escape(c.user.username) %]. -

-[% ELSE %] - -
- -
-
- -
- -
-
- -
- -
- -
-
- -
- -
-
- -
- -[% END %] - -[% END %] diff --git a/src/root/topbar.tt b/src/root/topbar.tt index a5f7c3c1..a48038d5 100644 --- a/src/root/topbar.tt +++ b/src/root/topbar.tt @@ -128,7 +128,7 @@
  • - Sign in with a Hydra account + Sign in with a Hydra account
  • [% END %] [% END %]