initial commit

This commit is contained in:
Serghei Mihai 2014-10-02 18:16:05 +02:00
commit 41adf8c22e
10 changed files with 209 additions and 0 deletions

2
COPYING Normal file
View File

@ -0,0 +1,2 @@
authentic2-userinfo is entirely under the copyright of Entr'ouvert and
distributed under the license AGPLv3 or later.

20
README Normal file
View File

@ -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 **

View File

@ -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 []

View File

@ -0,0 +1,5 @@
from django.contrib import admin
from . import models
# registrer your admin editable models here using admin.register

View File

@ -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

View File

@ -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,)

View File

@ -0,0 +1,4 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
# put your models here

View File

@ -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'),
)
)

View File

@ -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}

53
setup.py Executable file
View File

@ -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',
],
},
)