Posted by stodge |
|
I'm researching community type CMSs and applications for a development server. The server currently hosts Trac and Subversion over Apache. Authentication for both is performed using an Apache htpasswd file. I think I read that Django has a middleware or some kind of support for Apache authentication. How would SCT interact with it though in terms of users? When someone logs into Apache for an SCT site for the first time I want an account to be created for them in SCT automatically. I don't want users registering for accounts using the http://localhost:8000/community/accounts/register/ link. Any thoughts?
Thanks |
|
Posted by Herbert Poul |
|
SCT basically relies on django users and django authentication. the easiest way would be to create a middleware which looks for an existing basic authentication header and logs the user in automatically..
a middleware would look like: class \BasicAuthenticationMiddleware(object): def process_request(self, request): user = getattr(request, 'user') headername = 'HTTP_AUTHORIZATION' if (user is None or not user.is_authenticated()) \ and headername in request.META: auth = request.META[headername] auth = auth.split(' ')[1] authdecode = base64.b64decode(auth) (username, password) = authdecode.split(':') user = authenticate(username = username, password = password) if user is not None and user.is_authenticated() and user.is_active: login(request, user) return None you would need to add that to for example a middleware.py of your application and add it to MIDDLEWARE_CLASSES settings variable. i'm not sure how familiar you are with django, so no idea how much that helps you ;) but django is pretty straight forward in that regard actually.. you can probably justp lay around with that code.. e.g. if the user does not exist - and hence 'authenticate' would not return a user you could simply create one.. so it looks like single sign on to the user.. --- Last Edited by Herbert Poul at 2009-10-29 16:57:12 --- Hey, we have Signatures !!! Great, isn't it ? ;) |
|
Posted by Herbert Poul |
|
(in my case i have used the above code with a LDAP authentication module.. ie. i would use basic authentication in apache which checks against LDAP and then additional check the authentication in django.. but this second check is usually not required, since you can trust your apache :) this is why - if you don't want to write your own authentication module for django .. you can simply create the user right in the middleware.. hope that makes any sense to you :) ) Hey, we have Signatures !!! Great, isn't it ? ;) |
|
Posted by stodge |
|
Sounds good. I am slightly familiar with Django though I haven't done much with it yet. I'll also have to research SCT and mod_python (how to server admin pages and media files). Yes I've already read http://docs.djangoproject.com/en/dev/howto/deployment/modpython/, as I have deployed a small Django site that resets a user's password in an htpasswd file. :)
Thanks --- Last Edited by stodge at 2009-10-29 17:25:33 --- |
|
Posted by stodge |
|
OK so far I have:
class BasicAuthenticationMiddleware(object): def process_request(self, request): import syslog, base64 from django.contrib.auth import * from django.contrib.auth.models import User syslog.syslog(str(dir(request))) user = getattr(request, 'user') headername = 'HTTP_AUTHORIZATION' if (user is None or not user.is_authenticated()) \ and headername in request.META: auth = request.METAheadername auth = auth.split(' ')1 authdecode = base64.b64decode(auth) (username, password) = authdecode.split(':') user = authenticate(username = username, password = password) if user is not None and user.is_authenticated() and user.is_active: login(request, user) else: if user is None: # Create new user. user = User.objects.create_user(username, '%s@noreply.com'%username, password) if user is not None and user.is_authenticated() and user.is_active: login(request, user) return None |
Please login to post a reply.