diff --git a/ckanext/oauth2/plugin.py b/ckanext/oauth2/plugin.py index 94203a3..3d02f6c 100644 --- a/ckanext/oauth2/plugin.py +++ b/ckanext/oauth2/plugin.py @@ -99,7 +99,12 @@ def __init__(self, name=None): def before_map(self, m): log.debug('Setting up the redirections to the OAuth2 service') - m.connect('/user/login', + if self.enable_ckan_auth: + base = '/oauth2' + else: + base = '' + + m.connect(base+'/user/login', controller='ckanext.oauth2.controller:OAuth2Controller', action='login') @@ -111,15 +116,15 @@ def before_map(self, m): # Redirect the user to the OAuth service register page if self.register_url: - m.redirect('/user/register', self.register_url) + m.redirect(base+'/user/register', self.register_url) # Redirect the user to the OAuth service reset page if self.reset_url: - m.redirect('/user/reset', self.reset_url) + m.redirect(base+'/user/reset', self.reset_url) # Redirect the user to the OAuth service reset page if self.edit_url: - m.redirect('/user/edit/{user}', self.edit_url) + m.redirect(base+'/user/edit/{user}', self.edit_url) return m @@ -179,6 +184,7 @@ def update_config(self, config): self.reset_url = os.environ.get("CKAN_OAUTH2_RESET_URL", config.get('ckan.oauth2.reset_url', None)) self.edit_url = os.environ.get("CKAN_OAUTH2_EDIT_URL", config.get('ckan.oauth2.edit_url', None)) self.authorization_header = os.environ.get("CKAN_OAUTH2_AUTHORIZATION_HEADER", config.get('ckan.oauth2.authorization_header', 'Authorization')).lower() + self.enable_ckan_auth = os.environ.get("CKAN_OAUTH2_ENABLE_CKAN_AUTH", config.get('ckan.oauth2.enable_ckan_auth', False)) # Add this plugin's templates dir to CKAN's extra_template_paths, so # that CKAN will use this plugin's custom templates. diff --git a/ckanext/oauth2/templates/header.html b/ckanext/oauth2/templates/header.html index ee2403b..3ac4e7c 100644 --- a/ckanext/oauth2/templates/header.html +++ b/ckanext/oauth2/templates/header.html @@ -1,8 +1,6 @@ {% ckan_extends %} -{% if header_account_notlogged is defined %} - {% block header_account_notlogged %} -
  • {% link_for _('Log in'), controller='user', action='login' %}
  • -
  • {% link_for _('Register'), controller='user', action='register', class_='sub' %}
  • - {% endblock %} -{% endif %} \ No newline at end of file +{% block header_account_notlogged %} +
  • {% link_for _('OAuth Log in'), named_route='oauth2.login' %}
  • +{{ super() }} +{% endblock %}