Skip to content

Commit

Permalink
Add button style config options
Browse files Browse the repository at this point in the history
  • Loading branch information
blagojabozinovski committed Feb 5, 2024
1 parent a3d9b8d commit eada919
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Configuration settings to run the extension
ckanext.keycloak.realm_name = realm_name
ckanext.keycloak.redirect_uri = redirect_url
ckanext.keycloak.client_secret_key = client_secret_key
ckanext.keycloak.button_style = google/azure (if empty it will have the default stile)
```

## Developer installation
Expand Down
56 changes: 55 additions & 1 deletion ckanext/keycloak/assets/css/keycloak.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,58 @@
position: inherit;
margin-top: 1rem;
}
}
}

.azurebtn {
padding: 8px 16px 5px 42px;
margin-right: 10px;
border: 1px;
border-style: solid;

border-radius: 3px;
box-shadow: 0 -1px 0 rgba(0, 0, 0, .04), 0 1px 1px rgba(0, 0, 0, .25);

color: #000000;
font-size: 14px;
font-weight: 500;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;

background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAABHVBMVEVHcEw0t+0kisINUpgMT5QVcbwnl+AegsYHZbYGabwtpOc4w/Epl+ILVp4wq+YTXpo7yvMvqOgqmeMKXKgJYK4HZLUoluEOUJQ2u+4vqOgupec1uO0NUpY3vu8touYOUJQ0tewzsus4wfA5xPEsn+UNPnwLWqQOS406x/INUpYxruowrOYgd6k7yvMOWZ4LWqQKXKczse0KXKcup+Yyr+oJX60Yi9QDa8AIY7IHZrcHZrcHZrcAeNMAgN8OfM0AedUAdc84wvEysOstpOcJX6wrnuUCdMoHY7MztesPTo0MVJs6x/MAd9I3v+0MT5Q2u+41uO0MVp8wq+kLWKELWqQqnOIJYa8QfssWZqIcdq4kib4zsN8sns8citMEbsTGL1GGAAAAQXRSTlMAGwq7aBT+BPtOMD5MlPP7+f7u1H0r9x7zWIJiPN6s3o21vpfQQTSYbPTXzO7uzO9ZaP39mq2LievJ4PHeDe5tvTWfrhoAAADFSURBVBjTVcxFEsJAAADBACGCu7u7u8cVd/3/MygoWJY59mEQ5F26ZLOVjQgcap0rSu6PstJVoZKwaHXSjaISWoi8UelCzcMaiEL5xXm59MF/VF6cxNUqCJFZlq0WUYz9BNet15UiTcdxQHrndmtu0XTh989Udzu0vtlYDIBqDZbodpp2ux+QixVUld8zTADc2yz7UHmMYSI4uB8O/RF/57iU/kPuniC4pvyR4xzfP0kIBDmeHbE9ZvrSkBi4EXLi8The9ARvhx6sSwjytgAAAABJRU5ErkJggg==');
background-repeat: no-repeat;
background-position: 9px 9px;
background-color: #ffffff;

&:focus {
outline: none;
box-shadow:
0 -1px 0 rgba(0, 0, 0, .04),
0 2px 4px rgba(0, 0, 0, .25),
0 0 0 3px #c8dafc;
}

}
.azurebtn:hover {
background-color: #e6e6e6;
}

.register-azure{
position: relative;
}

.azure-button{
position: absolute;
right: 17%;
bottom: 0%;
}

@media only screen and (max-width: 900px) {

.register-azure{
position: inherit;
}

.azure-button{
position: inherit;
margin-top: 1rem;
}
}
11 changes: 11 additions & 0 deletions ckanext/keycloak/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ckan.model as model
import ckan.plugins.toolkit as tk
from os import environ


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -34,9 +35,11 @@ def ensure_unique_username_from_email(email):

return cleaned_localpart


def process_user(userinfo):
return _get_user_by_email(userinfo.get('email')) or _create_user(userinfo)


def _get_user_by_email(email):
user = model.User.by_email(email)
if user and isinstance(user, list):
Expand All @@ -46,6 +49,7 @@ def _get_user_by_email(email):

return user


def activate_user_if_deleted(user):
u'''Reactivates deleted user.'''
if not user:
Expand All @@ -55,6 +59,7 @@ def activate_user_if_deleted(user):
user.commit()
log.info(u'User {} reactivated'.format(user.name))


def _create_user(userinfo):
context = {
u'ignore_auth': True,
Expand All @@ -64,3 +69,9 @@ def _create_user(userinfo):
)(context, userinfo)

return _get_user_by_email(created_user_dict['email'])


def button_style():

return tk.config.get('ckanext.keycloak.button_style',
environ.get('CKANEXT__KEYCLOAK__BUTTON_STYLE'))
13 changes: 11 additions & 2 deletions ckanext/keycloak/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import ckan.plugins.toolkit as toolkit

from ckanext.keycloak.views import get_blueprint
from ckanext.keycloak import helpers as h


class KeycloakPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IBlueprint)
plugins.implements(plugins.ITemplateHelpers)

# IConfigurer

Expand All @@ -14,6 +17,12 @@ def update_config(self, config_):
toolkit.add_public_directory(config_, 'public')
toolkit.add_resource('assets', 'keycloak')


def get_blueprint(self):
return get_blueprint()
return get_blueprint()

# ITemplateHelpers

def get_helpers(self):
return {
'button_style': h.button_style,
}
13 changes: 11 additions & 2 deletions ckanext/keycloak/templates/user/snippets/login_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@

{% ckan_extends %}
{% block login_button %}
<a class="gbtn btn btn-default" href="{{ h.url_for('keycloak.sso') }}">{{ _('Sign in with Google') }}</a>
<button class="btn btn-primary" type="submit">{{ _('Login') }}</button>

{% set button_style = h.button_style() %}
{% if button_style == "google" %}
<a class="gbtn btn btn-default" href="{{ h.url_for('keycloak.sso') }}">{{ _('Sign in with Google') }}</a>
{% elif button_style == "azure" %}
<a class="azurebtn btn btn-defaul" href="{{ h.url_for('keycloak.sso') }}">{{ _('Sign in with AzureAD') }}</a>
{% else %}
<a class="btn btn-primary" href="{{ h.url_for('keycloak.sso') }}">{{ _('SSO') }}</a>
{% endif %}

<button class="btn btn-primary" type="submit">{{ _('Login') }}</button>

{% endblock %}

0 comments on commit eada919

Please sign in to comment.