view MoinMoin/auth/ @ 1550:a4f0632414da

using request.cfg.cache more
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 14 Sep 2006 22:49:42 +0200
parents 28ea5b3802b1
children b180f047d918
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - authentication using a remote wiki

    This is completely untested and rather has to be seen as an idea
    than a working implementation.

    @copyright: 2005 by ???
    @license: GNU GPL, see COPYING for details.
import xmlrpclib
from MoinMoin import auth, wikiutil, user

def interwiki(request, **kw):
    # TODO use auth_method and auth_attribs for User object
    username = kw.get('name')
    password = kw.get('password')
    login = kw.get('login')
    logout = kw.get('logout')
    user_obj = kw.get('user_obj')

    if login:
        wikitag, wikiurl, wikitail, err = wikiutil.resolve_wiki(username)

        if err or wikitag not in request.cfg.trusted_wikis:
            return user_obj, True

        if password:
            homewiki = xmlrpclib.Server(wikiurl + "?action=xmlrpc2")
            account_data = homewiki.getUser(wikitail, password)
            if isinstance(account_data, str):
                # show error message
                return user_obj, True

            u = user.User(request, name=username)
            for key, value in account_data.iteritems():
                if key not in ["may", "id", "valid", "trusted"
                               "name", "aliasname",
                    setattr(u, key, value)
            auth.setSessionCookie(request, u)
            return u, True
            # XXX redirect to homewiki

    return user_obj, True