summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei MIHAI <smihai@entrouvert.com>2014-10-02 16:16:05 (GMT)
committerSerghei MIHAI <smihai@entrouvert.com>2014-10-03 10:32:15 (GMT)
commit41adf8c22e83a985ae2dcb24e9cff23583a0267e (patch)
tree5ce6948692a3c15565410fb75033b8e398901358
downloadauthentic2-userinfo-41adf8c22e83a985ae2dcb24e9cff23583a0267e.zip
authentic2-userinfo-41adf8c22e83a985ae2dcb24e9cff23583a0267e.tar.gz
authentic2-userinfo-41adf8c22e83a985ae2dcb24e9cff23583a0267e.tar.bz2
initial commit
-rw-r--r--COPYING2
-rw-r--r--README20
-rw-r--r--authentic2_userinfo/__init__.py62
-rw-r--r--authentic2_userinfo/admin.py5
-rw-r--r--authentic2_userinfo/app_settings.py23
-rw-r--r--authentic2_userinfo/dashboard.py11
-rw-r--r--authentic2_userinfo/models.py4
-rw-r--r--authentic2_userinfo/urls.py14
-rw-r--r--authentic2_userinfo/views.py15
-rwxr-xr-xsetup.py53
10 files changed, 209 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d84f1b5
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,2 @@
+authentic2-userinfo is entirely under the copyright of Entr'ouvert and
+distributed under the license AGPLv3 or later.
diff --git a/README b/README
new file mode 100644
index 0000000..31e0b56
--- /dev/null
+++ b/README
@@ -0,0 +1,20 @@
+** THIS IS A TEMPLATE PROJECT **
+
+To rename it to your taste:
+
+ $ ./adapt.sh
+
+** THIS IS A TEMPLATE PROJECT **
+Authentic2 Userinfo
+==========================
+
+Install
+-------
+
+You just have to install the package in your virtualenv and relaunch, it will
+be automatically loaded by authentic2.
+
+Settings
+--------
+
+** DESCRIBE CUSTOM SETTINGS HERE **
diff --git a/authentic2_userinfo/__init__.py b/authentic2_userinfo/__init__.py
new file mode 100644
index 0000000..13f0453
--- /dev/null
+++ b/authentic2_userinfo/__init__.py
@@ -0,0 +1,62 @@
+__version__ = '0.0.1'
+
+class Plugin(object):
+ def get_before_urls(self):
+ from . import urls
+ return urls.urlpatterns
+
+ def get_after_urls(self):
+ return []
+
+ def get_apps(self):
+ return [__name__]
+
+ def get_before_middleware(self):
+ return []
+
+ def get_after_middleware(self):
+ return []
+
+ def get_authentication_backends(self):
+ return []
+
+ def get_auth_frontends(self):
+ return []
+
+ def get_idp_backends(self):
+ return []
+
+ def get_admin_modules(self):
+ from . import dashboard
+ return dashboard.get_admin_modules()
+
+ def service_list(self, request):
+ '''For IdP plugins this method add links to the user homepage.
+
+ It must return a list of authentic2.utils.Service objects, each
+ object has a name and can have an url and some actions.
+
+ Service(name=name[, url=url[, actions=actions]])
+
+ Actions are a list of tuples, whose parts are
+ - first the name of the action,
+ - the HTTP method for calling the action,
+ - the URL for calling the action,
+ - the paramters to pass to this URL as a sequence of key-value tuples.
+ '''
+ return []
+
+ def logout_list(self, request):
+ '''For IdP or SP plugins this method add actions to logout from remote
+ IdP or SP.
+
+ It must returns a list of HTML fragments, each fragment is
+ responsible for calling the view doing the logout. Views are usually
+ called using <img/> or <iframge/> tags and finally redirect to an
+ icon indicating success or failure for the logout.
+
+ Authentic2 provide two such icons through the following URLs:
+ - os.path.join(settings.STATIC_URL, 'authentic2/img/ok.png')
+ - os.path.join(settings.STATIC_URL, 'authentic2/img/ok.png')
+ '''
+ return []
diff --git a/authentic2_userinfo/admin.py b/authentic2_userinfo/admin.py
new file mode 100644
index 0000000..08eef26
--- /dev/null
+++ b/authentic2_userinfo/admin.py
@@ -0,0 +1,5 @@
+from django.contrib import admin
+
+from . import models
+
+# registrer your admin editable models here using admin.register
diff --git a/authentic2_userinfo/app_settings.py b/authentic2_userinfo/app_settings.py
new file mode 100644
index 0000000..434d87e
--- /dev/null
+++ b/authentic2_userinfo/app_settings.py
@@ -0,0 +1,23 @@
+class AppSettings(object):
+ __DEFAULTS = {
+ 'ENABLED': True,
+ }
+
+ def __init__(self, prefix):
+ self.prefix = prefix
+
+ def _setting(self, name, dflt):
+ from django.conf import settings
+ return getattr(settings, self.prefix+name, dflt)
+
+ def __getattr__(self, name):
+ if name not in self.__DEFAULTS:
+ raise AttributeError(name)
+ return self._setting(name, self.__DEFAULTS[name])
+
+# Ugly? Guido recommends this himself ...
+# http://mail.python.org/pipermail/python-ideas/2012-May/014969.html
+import sys
+app_settings = AppSettings('A2_PLUGIN_TEMPLATE_')
+app_settings.__name__ = __name__
+sys.modules[__name__] = app_settings
diff --git a/authentic2_userinfo/dashboard.py b/authentic2_userinfo/dashboard.py
new file mode 100644
index 0000000..18d0ece
--- /dev/null
+++ b/authentic2_userinfo/dashboard.py
@@ -0,0 +1,11 @@
+from django.utils.translation import ugettext_lazy as _
+
+from admin_tools.dashboard import modules
+
+
+def get_admin_modules():
+ '''Show Client model in authentic2 admin'''
+ model_list = modules.ModelList(_('Authentic2 Userinfo'),
+ models=('authentic2_userinfo.models.*',))
+ return (model_list,)
+
diff --git a/authentic2_userinfo/models.py b/authentic2_userinfo/models.py
new file mode 100644
index 0000000..c0f6f87
--- /dev/null
+++ b/authentic2_userinfo/models.py
@@ -0,0 +1,4 @@
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+# put your models here
diff --git a/authentic2_userinfo/urls.py b/authentic2_userinfo/urls.py
new file mode 100644
index 0000000..f20cc77
--- /dev/null
+++ b/authentic2_userinfo/urls.py
@@ -0,0 +1,14 @@
+from django.conf.urls import patterns, url
+
+from authentic2.decorators import setting_enabled, required
+
+from . import app_settings
+from .views import UserFullData
+
+urlpatterns = required(
+ setting_enabled('ENABLED', settings=app_settings),
+ patterns('',
+ url('^userinfo/(?P<nameid>_\w+)$', UserFullData.as_view(),
+ name='authentic2-userinfo'),
+ )
+)
diff --git a/authentic2_userinfo/views.py b/authentic2_userinfo/views.py
new file mode 100644
index 0000000..18768e0
--- /dev/null
+++ b/authentic2_userinfo/views.py
@@ -0,0 +1,15 @@
+from django.views.generic import View
+
+from jsonresponse import to_json
+
+from authentic2 import compat
+
+user_model = compat.get_user_model()
+
+class UserFullData(View):
+
+ @to_json('api')
+ def get(self, request, nameid):
+ user = user_model.objects.get(libertyfederation__name_id_content=nameid, deleteduser__isnull=True)
+ return {'first_name': user.first_name, 'last_name': user.last_name,
+ 'email': user.email}
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..200e21e
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+from setuptools import setup, find_packages
+import os
+
+def get_version():
+ import glob
+ import re
+ import os
+
+ version = None
+ for d in glob.glob('*'):
+ module_file = os.path.join(d, '__init__.py')
+ if not os.path.exists(module_file):
+ continue
+ for v in re.findall("""__version__ *= *['"](.*)['"]""",
+ open(module_file).read()):
+ assert version is None
+ version = v
+ if version:
+ break
+ assert version is not None
+ if os.path.exists('.git'):
+ import subprocess
+ p = subprocess.Popen(['git','describe','--dirty','--match=v*'],
+ stdout=subprocess.PIPE)
+ result = p.communicate()[0]
+ assert p.returncode == 0, 'git returned non-zero'
+ new_version = result.split()[0][1:]
+ assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag'
+ version = new_version.replace('-', '.')
+ return version
+
+README = file(os.path.join(
+ os.path.dirname(__file__),
+ 'README')).read()
+
+setup(name='authentic2-userinfo',
+ version=get_version(),
+ license='AGPLv3',
+ description='Authentic2 Userinfo',
+ long_description=README,
+ author="Entr'ouvert",
+ author_email="info@entrouvert.com",
+ packages=find_packages(os.path.dirname(__file__) or '.'),
+ install_requires=[
+ 'django-jsonresponse==0.10'
+ ],
+ entry_points={
+ 'authentic2.plugin': [
+ 'authentic2-userinfo= authentic2_userinfo:Plugin',
+ ],
+ },
+)