Permalink
Browse files

Factor `Auth.login_form`, `.logout_form`

+ Reuse generic login and logout forms provided by package JNJ
  • Loading branch information...
tanzer committed Jun 11, 2015
1 parent 9e70190 commit 133a0673a31e606f783c811d0d45f955e434eb4f
@@ -32,7 +32,7 @@
#}
{%- import (html_version or "html/5.jnj") as X -%}
-{%- import "html/page_notifications.m.jnj" as PN with context %}
+{%- import "html/page_notifications.m.jnj" as PN with context %}
{%- import "html/media_fragments.jnj" as MF with context %}
{%- import "html/dashboard/app.m.jnj" as DB with context %}
{%- import "html/dashboard/edit.m.jnj" as DB_Edit with context %}
@@ -28,6 +28,8 @@
# 27-Jan-2015 (CT) Add rules for `.align-center`, `.align-left`,
# `.align-right`
# 1-Jun-2015 (CT) Add rules for `[data-action=undo]` and `tr.deleted`
+# 11-Jun-2015 (CT) Factor rules for `form.login` to `html/auth.m.jnj.media`
+# 11-Jun-2015 (CT) Rename `.logout` to `.Logout`
# ««revision-date»»···
#--
@@ -73,29 +75,6 @@ style_sheet = Style_Sheet \
)
)
)
- , Rule
- ( "form.login"
- , children =
- [ Rule
- ( "button[type=submit]"
- , border_radius = Em ( 1/4)
- , margin_left = Em ( 1.5)
- , width = Em (15.0)
- , children =
- [ Rule
- ( "i.fa"
- , float = "left"
- )
- ]
- )
- , Rule
- ( "legend"
- , font_size = Em (1.25)
- , font_weight = "bold"
- , margin_top = Rem (1.00)
- )
- ]
- )
, Rule
( "header"
, height = Rem (2.75)
@@ -165,7 +144,7 @@ style_sheet = Style_Sheet \
, vertical_align = "middle"
)
, Rule
- ( "form.logout"
+ ( "form.Logout"
, display = "inline-block"
, padding = 0
)
@@ -460,7 +439,7 @@ style_sheet = Style_Sheet \
, color = "#FFFFFF"
, children =
[ Rule
- ( ".logout"
+ ( ".Logout"
, border_radius = Em (0.25)
, background_color = "#E6E6E6"
, color = "#333333"
@@ -55,10 +55,13 @@
## 18-Mar-2015 (CT) Add guard for `objects` to `e_type_table`
## 7-Apr-2015 (CT) Add `data-etn` to `e_type_object` if `db_type.is_partial`
## 7-Apr-2015 (CT) Use localized `Div_Name_T`, not generic `Div_Name`
+## 11-Jun-2015 (CT) Use `Auth.logout_form`, not home-grown `logout_widget`
## ««revision-date»»···
##--
#}
+{%- import "html/auth.m.jnj" as AT with context %}
+
{%- macro action_button
( href, icon_name
, title = None
@@ -272,23 +275,6 @@
</table>
{%- endmacro -%} {#- e_type_table -#}
-{%- macro logout_widget (page) -%}
- {%- set Auth = page.SC.Auth -%}
- {%- set action = Auth.href_logout -%}
- <form action="{{ action }}" {# -#}
- class="Auth logout pure-form" {# -#}
- method="post" {# -#}
- >
- <button class="logout pure-button" {# -#}
- name="submit"
- title="{{ GTW._T ("Logout %s") % (page.user.person.FO, ) }}" {# -#}
- type="submit" {# -#}
- >{# -#}
- <i class="fa fa-sign-out"></i> {{ GTW._T ("Logout") -}}
- </button>{# -#}
- </form>
-{%- endmacro -%} {#- logout_widget -#}
-
{%- macro nav_menu_dashboard (page) -%}
{%- if page.request.user %}
<a href="/dashboard" class="dashboard pure-menu-heading">
@@ -350,7 +336,7 @@
{{ action_button
(db_page.db_user.abs_href, "cog", GTW._T ("Personal settings"), "settings")
-}}
- {{ logout_widget (page) }}
+ {{ AT.logout_form (page) }}
{%- elif page.abs_href != href_login %}
<a href="{{ href_login }}" class="login pure-button">
<i class="fa fa-sign-in"></i> {{ GTW._T ("Login") -}}
View
@@ -20,102 +20,21 @@
## 2-May-2014 (CT) Fix name of `Reset` button, add value
## 5-May-2014 (CT) Remove redefinition of `nav_block`
## 13-Mar-2015 (CT) Add `anti_csrf_token`
+## 11-Jun-2015 (CT) Factor `Auth.login_form`
## ««revision-date»»···
##--
#}
{%- import (html_version or "html/5.jnj") as X -%}
-
-{%- macro display_errors (errors, field_name) -%}
- {%- for err in errors.get (field_name, ()) %}
- <li class="Error-Message">
- {{ err }}
- </li>
- {% endfor -%}
-{%- endmacro -%} {#- display_errors -#}
+{%- import "html/auth.m.jnj" as Auth with context %}
{%- block app -%}
- {%- set Auth = page.SC.Auth -%}
- {%- set action = Auth.href_login -%}
- {%- set cc_href = page.cc_href %}
- {%- set next = "/dashboard" -%}
- {%- set request = page.request %}
- {%- set title = page.title or
- GTW._T ("Login for %s" % page.request.host)
- -%}
- <form action="{{ action }}" {# -#}
- class="Auth login pure-form pure-form-aligned" {# -#}
- method="post" {# -#}
- >
- <fieldset>
- <legend>
- {{ title }}
- </legend>
- <div class="Errors pure-controls">
- {{- display_errors (errors, None) -}}
- </div>
- {%- if cc_href %}
- <div class="pure-controls" title="{{ GTW._T ("Login with a previously created client certificate") }}">
- <a class="pure-button" href="{{ cc_href }}">{# -#}
- <i class="fa fa-certificate"></i> {{ GTW._T ("Certificate login") -}}
- </a>{# -#}
- </li>
- {% endif -%}
- <div class="pure-control-group" {# -#}
- title="{{ GTW._T ("Email address of your account") }}"{# -#}
- >
- <label for="F_username">{{ GTW._T ("Email") }}</label>
- {{ X.input.email
- ( id = "F_username"
- , name = "username"
- , maxlength = "30"
- , required = True
- )
- }}
- </div>
- <div class="Errors pure-controls">
- {{- display_errors (errors, "username") -}}
- </div>
- <div class="pure-control-group" {# -#}
- title="{{ GTW._T ("Password of your account") }}"{# -#}
- >
- <label for="F_password">{{ GTW._T ("Password") }}</label>
- {{ X.input.password
- ( id = "F_password"
- , name = "password"
- )
- }}
- </div>
- <div class="Errors pure-controls">
- {{- display_errors (errors, "password") -}}
- </div>
- <div class="pure-controls">
- <button class="pure-button pure-button-primary" {# -#}
- name="submit"
- title="{{ GTW._T ("Log into website") }}" {# -#}
- type="submit" {# -#}
- >{# -#}
- <i class="fa fa-sign-in"></i> {{ GTW._T ("Login") -}}
- </button>{# -#}
- </div>
- <div class="pure-controls">
- <button class="pure-button" {# -#}
- name="Reset"
- tabindex="-1" {# -#}
- title="{{ GTW._T ("I forgot my password; send me a temporary one to my email address") }}" {# -#}
- type="submit" {# -#}
- value="reset"
- >{# -#}
- <i class="fa fa-frown-o"></i> {{ GTW._T ("I forgot my password") -}}
- </button>{# -#}
- </div>
- {{ X.input.hidden (name = "next", value = next) }}
- {%- set anti_csrf_token = response and response.anti_csrf_token(action) %}
- {%- if anti_csrf_token %}
- {{ X.input.hidden (name = "F_ACT", value = anti_csrf_token) }}
- {% endif -%}
- </fieldset>
- </form>
+ {{ Auth.login_form
+ ( page
+ , next = "/dashboard"
+ , title = Auth.login_title (page)
+ )
+ -}}
{%- endblock app -%}
{#- __END__ jinja template: html/login.jnj -#}

0 comments on commit 133a067

Please sign in to comment.