Skip to content

Commit 5fe354f

Browse files
[ADD] auth_saml: Improve login page
Make the login page compatible with auth_oauth by using a differently named variable. Render the button with the similar classes and HTML as what is done by auth_oauth. That includes using the default CSS and adding translation for the button text.
1 parent 012a447 commit 5fe354f

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

auth_saml/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "XCG Consulting, Odoo Community Association (OCA)",
1010
"website": "https://github.com/OCA/server-auth",
1111
"license": "AGPL-3",
12-
"depends": ["base_setup"],
12+
"depends": ["base_setup", "web"],
1313
"external_dependencies": {
1414
# Place an upper bound on cryptography version to be compatible with
1515
# pyopenssl 19 mentioned in Odoo 15's requirements.txt. If we don't do

auth_saml/controllers/main.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ def list_saml_providers(self, with_autoredirect: bool = False) -> models.Model:
6767
domain.append(("autoredirect", "=", True))
6868
providers = request.env["auth.saml.provider"].sudo().search_read(domain)
6969

70-
for provider in providers:
71-
# Compatibility with auth_oauth/controllers/main.py in order to
72-
# avoid KeyError rendering template_auth_oauth_providers
73-
provider.setdefault("auth_link", "")
7470
return providers
7571

7672
def _saml_autoredirect(self):
@@ -130,7 +126,7 @@ def web_login(self, *args, **kw):
130126
else:
131127
error = None
132128

133-
response.qcontext["providers"] = providers
129+
response.qcontext["saml_providers"] = providers
134130

135131
if error:
136132
response.qcontext["error"] = error

auth_saml/models/auth_saml_provider.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ class AuthSamlProvider(models.Model):
8787
css_class = fields.Char(
8888
string="Button Icon CSS class",
8989
help="Add a CSS class that serves you to style the login button.",
90+
default="fa fa-fw fa-sign-in text-primary",
91+
)
92+
body = fields.Char(
93+
string="Login button label", help="Link text in Login Dialog", translate=True
9094
)
91-
body = fields.Char(string="Button Description")
9295
autoredirect = fields.Boolean(
9396
"Automatic Redirection",
9497
default=False,

auth_saml/views/auth_saml.xml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@
22
<odoo>
33
<!-- login form button -->
44
<template id="auth_saml.providers" name="Auth SAML Providers">
5-
<t t-if="len(providers) &gt; 0">
5+
<t t-if="len(saml_providers) &gt; 0">
66
<em
77
t-attf-class="d-block text-center text-muted small my-#{len(providers) if len(providers) &lt; 3 else 3}"
88
>- or -</em>
9-
<div class="o_login_saml2 mt-1 mb-1 text-left">
10-
<t t-foreach="providers" t-as="p">
11-
<a
12-
t-att-href="'/auth_saml/get_auth_request?pid=%s'%p['id']"
13-
class="btn btn-outline-primary btn-block"
14-
>
15-
<i t-att-class="p['css_class']" />
16-
<t t-esc="p['body']" />
17-
</a>
18-
</t>
9+
<div class="o_login_saml2 list-group mt-1 mb-1 text-left">
10+
<a
11+
t-foreach="saml_providers"
12+
t-as="p"
13+
class="list-group-item list-group-item-action py-2"
14+
t-att-href="'/auth_saml/get_auth_request?pid=%s'%p['id']"
15+
>
16+
<i t-att-class="p['css_class']" />
17+
<t t-esc="p['body']" />
18+
</a>
1919
</div>
2020
</t>
2121
</template>
2222
<template id="auth_saml.login" inherit_id="web.login" name="Samlv2 Login buttons">
23-
<xpath expr="//div[hasclass('o_login_auth')]" position="after">
23+
<xpath expr="//form" position="before">
24+
<t t-set="form_small" t-value="True" t-if="len(saml_providers) &gt; 2" />
25+
</xpath>
26+
<xpath expr="//div[hasclass('o_login_auth')]" position="inside">
2427
<t t-call="auth_saml.providers" />
2528
</xpath>
2629
</template>

0 commit comments

Comments
 (0)