view MoinMoin/auth/ @ 776:ab9cd47eb066

teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 10 Jun 2006 10:12:59 +0200
children 28ea5b3802b1
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