changeset 1951:a05a3b447db5

interwiki auth fixed, added getUserData xmlrpc method
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 06 Apr 2007 19:40:03 +0200
parents bbfc3144a567
children 8ab85e3711dc 97626bb218f4
files MoinMoin/auth/interwiki.py MoinMoin/user.py MoinMoin/xmlrpc/__init__.py
diffstat 3 files changed, 34 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/auth/interwiki.py	Fri Apr 06 16:41:27 2007 +0200
+++ b/MoinMoin/auth/interwiki.py	Fri Apr 06 19:40:03 2007 +0200
@@ -2,10 +2,8 @@
 """
     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 ???
+    @copyright: 2005 by Florian Festi,
+                2007 by MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 import xmlrpclib
@@ -15,7 +13,6 @@
     username = kw.get('name')
     password = kw.get('password')
     login = kw.get('login')
-    logout = kw.get('logout')
     user_obj = kw.get('user_obj')
 
     if login:
@@ -28,23 +25,16 @@
             homewiki = xmlrpclib.Server(wikiurl + "?action=xmlrpc2")
             account_data = homewiki.getUser(wikitail, password)
             if isinstance(account_data, str):
-                # show error message
+                # e.g. "Authentication failed", TODO: show error message
                 return user_obj, True
 
-            # TODO: use auth_method and auth_attribs for User object
-            u = user.User(request, name=username)
+            # TODO: check auth_attribs items
+            u = user.User(request, name=username, auth_method='interwiki', auth_attribs=('name', 'aliasname', 'password', 'email', ))
             for key, value in account_data.iteritems():
-                if key not in ["may", "id", "valid", "trusted"
-                               "auth_username",
-                               "name", "aliasname",
-                               "enc_passwd"]:
+                if key not in request.cfg.user_transient_fields:
                     setattr(u, key, value)
-            u.save()
-            auth.setSessionCookie(request, u)
-            return u, True
-        else:
-            pass
-            # TODO: redirect to homewiki
+            if u:
+                u.create_or_update(True)
+            return u, True # moin_session has to set the cookie
 
     return user_obj, True
-
--- a/MoinMoin/user.py	Fri Apr 06 16:41:27 2007 +0200
+++ b/MoinMoin/user.py	Fri Apr 06 19:40:03 2007 +0200
@@ -530,6 +530,11 @@
         # No encoded password match, this must be wrong password
         return False, False
 
+    def persistent_items(self):
+        """ items we want to store into the user profile """
+        return [(key, value) for key, value in vars(self).items()
+                    if key not in self._cfg.user_transient_fields and key[0] != '_']
+
     def save(self):
         """ Save user account data to user account file on disk.
 
@@ -552,20 +557,19 @@
         data.write("# Data saved '%s' for id '%s'\n" % (
             time.strftime(self._cfg.datetime_fmt, time.localtime(time.time())),
             self.id))
-        attrs = vars(self).items()
+        attrs = self.persistent_items()
         attrs.sort()
         for key, value in attrs:
-            if key not in self._cfg.user_transient_fields and key[0] != '_':
-                # Encode list values
-                if isinstance(value, list):
-                    key += '[]'
-                    value = encodeList(value)
-                # Encode dict values
-                elif isinstance(value, dict):
-                    key += '{}'
-                    value = encodeDict(value)
-                line = u"%s=%s\n" % (key, unicode(value))
-                data.write(line)
+            # Encode list values
+            if isinstance(value, list):
+                key += '[]'
+                value = encodeList(value)
+            # Encode dict values
+            elif isinstance(value, dict):
+                key += '{}'
+                value = encodeDict(value)
+            line = u"%s=%s\n" % (key, unicode(value))
+            data.write(line)
         data.close()
 
         if not self.disabled:
--- a/MoinMoin/xmlrpc/__init__.py	Fri Apr 06 16:41:27 2007 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Fri Apr 06 19:40:03 2007 +0200
@@ -560,6 +560,15 @@
         from MoinMoin import version
         return (version.project, version.release, version.revision)
 
+    def xmlrpc_getUser(self, username, password):
+        u = self.request.get_user_default_None(name=username, password=password, login=1)
+        if u is None:
+            return "Authentication failed"
+        else:
+            userdata = dict(u.persistent_items())
+            del userdata['enc_password']
+            del userdata['last_saved']
+            return userdata
 
     # authorization methods