annotate MoinMoin/auth/interwiki.py @ 2025:d919b7b7b3e9

auth framework: login() methods return an object now This avoids overloading the returned tuple and simplifies code since they can now just instantiate ContinueLogin(), CancelLogin() etc.
author Johannes Berg <johannes AT sipsolutions DOT net>
date Tue, 24 Apr 2007 12:04:19 +0200
parents 1b14cc05a54a
children 340ae0e7529e
rev   line source
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - authentication using a remote wiki
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
1951
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
5 @copyright: 2005 by Florian Festi,
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
6 2007 by MoinMoin:ThomasWaldmann
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 """
1953
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
9
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
10 verbose = False
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
11
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 import xmlrpclib
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 from MoinMoin import auth, wikiutil, user
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
14 from MoinMoin.auth import BaseAuth, ContinueLogin, CancelLogin
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
16 class InterwikiAuth(BaseAuth):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
17 name = 'interwiki'
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
18 logout_possible = True
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
19 login_inputs = ['username', 'password']
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
21 def __init__(self, trusted_wikis):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
22 BaseAuth.__init__(self)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
23 self.trusted_wikis = trusted_wikis
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
24
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
25 def login(self, request, user_obj, **kw):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
26 username = kw.get('username')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
27 password = kw.get('password')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
28
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
29 if not username or not password:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
30 return ContinueLogin(user_obj)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
31
1953
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
32 if verbose: request.log("interwiki auth: trying to auth %r" % username)
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
33 username = username.replace(' ', ':', 1) # Hack because ':' is not allowed in name field
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
34 wikitag, wikiurl, name, err = wikiutil.resolve_wiki(request, username)
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35
1953
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
36 if verbose: request.log("interwiki auth: resolve wiki returned: %r %r %r %r" % (wikitag, wikiurl, name, err))
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
37 if err or wikitag not in self.trusted_wikis:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
38 return ContinueLogin(user_obj)
948
28ea5b3802b1 whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 776
diff changeset
39
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
40 homewiki = xmlrpclib.Server(wikiurl + "?action=xmlrpc2")
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
41 account_data = homewiki.getUser(name, password)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
42 if isinstance(account_data, str):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
43 if verbose: request.log("interwiki auth: %r wiki said: %s" % (wikitag, account_data))
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
44 return ContinueLogin(None, account_data)
948
28ea5b3802b1 whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 776
diff changeset
45
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
46 # TODO: check remote auth_attribs
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
47 u = user.User(request, name=name, auth_method=self.name, auth_attribs=('name', 'aliasname', 'password', 'email', ))
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
48 for key, value in account_data.iteritems():
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
49 if key not in request.cfg.user_transient_fields:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
50 setattr(u, key, value)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
51 u.valid = True
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
52 u.create_or_update(True)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
53 if verbose: request.log("interwiki: successful auth for %r" % name)
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
54 return ContinueLogin(u)