forked from lix-project/hydra
Make sign in a modal dialog box rather than a separate page
This commit is contained in:
parent
299ac07cbc
commit
bd927eba66
|
@ -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 => { });
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -146,6 +146,45 @@
|
|||
</script>
|
||||
[% END %]
|
||||
|
||||
[% IF !c.user_exists %]
|
||||
<div id="hydra-signin" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<form class="form-horizontal">
|
||||
<div class="modal-body">
|
||||
<div class="control-group">
|
||||
<label class="control-label">User name</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="span3" name="username" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Password</label>
|
||||
<div class="controls">
|
||||
<input type="password" class="span3" name="password" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="do-signin" class="btn btn-primary">Sign in</button>
|
||||
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$("#do-signin").click(function() {
|
||||
requestJSON({
|
||||
url: "[% c.uri_for('/login') %]",
|
||||
data: $(this).parents("form").serialize(),
|
||||
type: 'POST',
|
||||
success: function(data) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
[% END %]
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
[% WRAPPER layout.tt title="Sign in" %]
|
||||
[% PROCESS common.tt %]
|
||||
|
||||
[% IF c.user_exists %]
|
||||
<p class="alert alert-info">
|
||||
You are already signed in as <tt>[% HTML.escape(c.user.username) %]</tt>.
|
||||
</p>
|
||||
[% ELSE %]
|
||||
|
||||
<form class="form-horizontal" method="post" action="[% c.uri_for('/login') %]">
|
||||
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<label class="control-label">User name</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="span3" name="username" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label">Password</label>
|
||||
<div class="controls">
|
||||
<input type="password" class="span3" name="password" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<input type="submit" name="login" value="Sign in" class="btn btn-primary" />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
</form>
|
||||
|
||||
[% END %]
|
||||
|
||||
[% END %]
|
|
@ -128,7 +128,7 @@
|
|||
</li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<a href="[% c.uri_for('/login') %]">Sign in with a Hydra account</a>
|
||||
<a href="#hydra-signin" data-toggle="modal">Sign in with a Hydra account</a>
|
||||
</li>
|
||||
[% END %]
|
||||
[% END %]
|
||||
|
|
Loading…
Reference in a new issue