summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarian Sigler <m@qjym.de>2012-09-26 00:05:26 +0200
committerMarian Sigler <m@qjym.de>2012-09-26 00:05:26 +0200
commitcc31815e01c6cb36fb1e88f02a9ae463745dac59 (patch)
treed3447ac8cb4ae61afa710217b1f9fb4114259b85
parent678d20c8308fe00d84ff15c9ce8f04bdb96b53b5 (diff)
downloadweb-cc31815e01c6cb36fb1e88f02a9ae463745dac59.tar.gz
web-cc31815e01c6cb36fb1e88f02a9ae463745dac59.tar.bz2
web-cc31815e01c6cb36fb1e88f02a9ae463745dac59.zip
add a Service() class to have more data about the services
-rw-r--r--account.py16
-rw-r--r--app.py6
-rw-r--r--utils.py10
3 files changed, 25 insertions, 7 deletions
diff --git a/account.py b/account.py
index 15e8539..123b07b 100644
--- a/account.py
+++ b/account.py
@@ -1,12 +1,18 @@
# -*- coding: utf-8 -*-
import ldap
+from utils import Service
LDAP_HOST = 'ldap://localhost:5678'
LDAP_BASE_DN = 'dc=account,dc=spline,dc=inf,dc=fu-berlin,dc=de'
LDAP_ADMIN_USER = 'admin'
LDAP_ADMIN_PASS = 'admin'
-SERVICES = ['foren','jabber', 'gitlab', 'osqa']
+SERVICES = [
+ Service('foren', 'Foren', 'http://foren.spline.de/'),
+ Service('jabber', 'Jabber', 'http://jabber.spline.de/'),
+ Service('gitlab', 'Gitlab', 'https://gitlab.spline.inf.fu-berlin.de/'),
+ Service('osqa', 'OS Q&A', 'http://osqa.spline.de/'),
+]
@@ -25,7 +31,7 @@ class AccountService:
>> service.register(foo)
* authenticate a new user
- >> service = AccountService(LDAP_HOST, LDAP_BASE_DN, ADMIN_USER, ADMIN_PW,, SERVICES)
+ >> service = AccountService(LDAP_HOST, LDAP_BASE_DN, ADMIN_USER, ADMIN_PW, SERVICES)
>> foo = service.auth('foo', 'bar')
* updates an account
@@ -177,7 +183,7 @@ class AccountService:
else:
self._bind('%s,%s' % (user, self.base_dn), password)
- dn = ['uid=%s,cn=%s,ou=services,%s' % (account.uid,s,self.base_dn) for s in account.services]
+ dn = ['uid=%s,cn=%s,ou=services,%s' % (account.uid,s,self.base_dn) for s.id in account.services]
dn.append(user)
for x in dn:
@@ -235,7 +241,7 @@ class Account:
An Account represents a complex ldap tree entry for spline users.
For each service a spline user can have a different password.
"""
- def __init__(self, uid, mail, services = [], dn = None, password = None):
+ def __init__(self, uid, mail, services=[], dn=None, password=None):
self.uid = uid.encode('utf8') if isinstance(uid, unicode) else uid
self.mail = mail.encode('utf8') if isinstance(mail, unicode) else mail
self.services = services
@@ -249,7 +255,7 @@ class Account:
return "<Account uid=%s>" % self.uid
- def change_password(self, new_password, old_password = '', service=None):
+ def change_password(self, new_password, old_password='', service=None):
"""
Changes a password for a given service. You have to use the
AccountService class to make the changes permanent. If no service is
diff --git a/app.py b/app.py
index f1f9ef1..43f6ef0 100644
--- a/app.py
+++ b/app.py
@@ -6,6 +6,7 @@ flaskext_compat.activate()
import account
import ldap
import os
+from copy import deepcopy
from flask import flash, Flask, g, redirect, request, session, url_for
from utils import *
from forms import RegisterForm, RegisterCompleteForm, LoginForm, SettingsForm
@@ -142,8 +143,9 @@ def settings():
flash(u'Nichts geƤndert')
- # (name, changed)
- services = [(name, name in g.user.services) for name in app.all_services]
+ services = deepcopy(app.all_services)
+ for s in services:
+ s.changed = s.id in g.user.services
return {
'form': form,
diff --git a/utils.py b/utils.py
index 6f81da8..6ab7ed4 100644
--- a/utils.py
+++ b/utils.py
@@ -172,3 +172,13 @@ def send_mail(recipient, subject, body, sender=None):
if p.wait() != 0:
raise RuntimeError('sendmail terminated with %d' % p.returncode)
+
+class Service(object):
+ def __init__(self, id, name, url):
+ self.id = id
+ self.name = name
+ self.url = url
+ self.changed = None # used by settings view
+
+ def __repr__(self):
+ return '<Service %s>' % self.id