Added 'sidebar' content block and make login form part of Auth plugin
Change-Id: Iab9ef73bce0960336aa3821e6f4f390e96dca574
diff --git a/Changes b/Changes
index 46346ef..e384a95 100755
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@
- Made Authentication/Authorization a separated Kalamar::Plugin::Auth
(deprecated moth helpers from Kalamar::Plugin::KalamarUser).
- Introduced abstract 'korap_request' helper.
+ - Introduce 'sidebar' content_block.
0.30 2018-11-13
- Rewrote backend:
diff --git a/README.md b/README.md
index 91c8f2d..4bf15e1 100644
--- a/README.md
+++ b/README.md
@@ -168,9 +168,10 @@
Some sections of the user interface can be customized
by adding new
[content blocks](https://github.com/Akron/Mojolicious-Plugin-TagHelpers-ContentBlock).
-Currently the documented sections are in ```footer```,
-in the bottom line of the user interface,
-and ```loginInfo```, below the login form, if present.
+Currently the documented sections are in
+```footer```, in the bottom line of the user interface,
+```sidebar```, in the left part of the user interface if present,
+and ```loginInfo```, below the login form if present.
### Plugins
diff --git a/lib/Kalamar/Controller/Documentation.pm b/lib/Kalamar/Controller/Documentation.pm
index 1f6b5b9..ab314b4 100644
--- a/lib/Kalamar/Controller/Documentation.pm
+++ b/lib/Kalamar/Controller/Documentation.pm
@@ -20,8 +20,10 @@
push(@path, $page);
# Set navigation to sidebar
- $c->content_for(
- sidebar => '<nav>' . $c->doc_navi($c->config('navi')) . '</nav>'
+ $c->content_block(
+ sidebar => {
+ inline => '<nav>' . $c->doc_navi($c->config('navi')) . '</nav>'
+ }
);
# Render template
diff --git a/lib/Kalamar/Plugin/Auth.pm b/lib/Kalamar/Plugin/Auth.pm
index d61d77f..6fe30dd 100644
--- a/lib/Kalamar/Plugin/Auth.pm
+++ b/lib/Kalamar/Plugin/Auth.pm
@@ -12,6 +12,8 @@
sub register {
my ($plugin, $app, $param) = @_;
+ # Allow data section as template resources
+ push @{$app->renderer->classes}, __PACKAGE__;
# Load parameter from config file
if (my $config_param = $app->config('Kalamar-Auth')) {
@@ -64,6 +66,14 @@
});
+ # Add login frame to sidebar
+ $app->content_block(
+ sidebar => {
+ template => 'partial/auth/login'
+ }
+ );
+
+
# Inject authorization to all korap requests
$app->hook(
before_korap_request => sub {
@@ -269,3 +279,29 @@
};
1;
+
+__DATA__
+@@ partial/auth/login.html.ep
+%# # user not logged in
+% if (!stash('documentation') && !$embedded && !$c->auth->token) {
+% if (flash('handle_or_email') && !param('handle_or_email')) {
+% param(handle_or_email => flash('handle_or_email'));
+% };
+ <fieldset>
+ %= form_for 'login', class => 'login', begin
+ <legend><span><%= loc 'login' %></span></legend>
+ %= csrf_field
+ %= text_field 'handle_or_email', placeholder => loc('userormail')
+ %= hidden_field fwd => $c->url_with
+ <div>
+ %= password_field 'pwd', placeholder => loc('pwd')
+ <button type="submit"><span><%= loc 'go' %></span></button>
+ </div>
+ % end
+
+ %= content_block 'loginInfo', separator => '<hr />'
+
+ </fieldset>
+% }
+
+__END__
diff --git a/t/plugin/auth.t b/t/plugin/auth.t
index ff5988e..a81c06f 100644
--- a/t/plugin/auth.t
+++ b/t/plugin/auth.t
@@ -42,7 +42,9 @@
;
$t->get_ok('/')
- ->element_exists('form[action=/user/login] input[name=handle_or_email]');
+ ->status_is(200)
+ ->element_exists('form[action=/user/login] input[name=handle_or_email]')
+ ;
$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
->status_is(302)
diff --git a/templates/layouts/main.html.ep b/templates/layouts/main.html.ep
index 1ddb271..32dccb6 100644
--- a/templates/layouts/main.html.ep
+++ b/templates/layouts/main.html.ep
@@ -60,7 +60,6 @@
<body class="no-js<% if ($embedded) { %> embedded<% } %>" itemscope itemtype="http://schema.org/<%= stash('schematype') || 'WebApplication' %>">
<script>document.body.classList.remove('no-js');</script>
<div id="kalamar-bg"></div>
-
%= include 'partial/side', embedded => $embedded
@@ -68,7 +67,6 @@
%= include 'partial/header'
% }
-
<noscript>
<p id="activate"><%= loc 'activateJS' %></p>
</noscript>
diff --git a/templates/partial/side.html.ep b/templates/partial/side.html.ep
index d0a5470..ff2df26 100644
--- a/templates/partial/side.html.ep
+++ b/templates/partial/side.html.ep
@@ -1,34 +1,5 @@
-%# # user not logged in
-% if (!stash('documentation') && !$embedded && stash('auth_support') && !$c->auth->token) {
-% content_for 'sidebar', begin
-% if (flash('handle_or_email') && !param('handle_or_email')) {
-% param(handle_or_email => flash('handle_or_email'));
-% };
- <fieldset>
- %= form_for 'login', class => 'login', begin
- <legend><span><%= loc 'login' %></span></legend>
- %= csrf_field
- %= text_field 'handle_or_email', placeholder => loc('userormail')
- %= hidden_field fwd => $c->url_with
- <div>
- %= password_field 'pwd', placeholder => loc('pwd')
- <button type="submit"><span><%= loc 'go' %></span></button>
- </div>
- % end
-
- %= content_block 'loginInfo', separator => '<hr />'
-
- %# <ul>
- %# <li><%= link_to loc('register') => 'register' %></li>
- %# <li><%= link_to loc('pwdforgotten') => 'pwd_forgotten' %></li>
- %# </ul>
- </fieldset>
-% end
-% }
-
-% my $aside = content_for('sidebar');
-<aside tabindex="0" class="<% unless (length($aside) > 0) { %>off<% } elsif (stash('sidebar_active')) { %>active<% } %>">
+<aside tabindex="0" class="<% unless (content_block_ok('sidebar')) { %>off<% } elsif (stash('sidebar_active')) { %>active<% } %>">
<div>
- %= $aside
+%= content_block 'sidebar'
</div>
</aside>