comparison 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
comparison
equal deleted inserted replaced
2024:b73858101d66 2025:d919b7b7b3e9
9 9
10 verbose = False 10 verbose = False
11 11
12 import xmlrpclib 12 import xmlrpclib
13 from MoinMoin import auth, wikiutil, user 13 from MoinMoin import auth, wikiutil, user
14 from MoinMoin.auth import BaseAuth 14 from MoinMoin.auth import BaseAuth, ContinueLogin, CancelLogin
15 15
16 class InterwikiAuth(BaseAuth): 16 class InterwikiAuth(BaseAuth):
17 name = 'interwiki' 17 name = 'interwiki'
18 logout_possible = True 18 logout_possible = True
19 login_inputs = ['username', 'password'] 19 login_inputs = ['username', 'password']
25 def login(self, request, user_obj, **kw): 25 def login(self, request, user_obj, **kw):
26 username = kw.get('username') 26 username = kw.get('username')
27 password = kw.get('password') 27 password = kw.get('password')
28 28
29 if not username or not password: 29 if not username or not password:
30 return user_obj, True, None, None 30 return ContinueLogin(user_obj)
31 31
32 if verbose: request.log("interwiki auth: trying to auth %r" % username) 32 if verbose: request.log("interwiki auth: trying to auth %r" % username)
33 username = username.replace(' ', ':', 1) # Hack because ':' is not allowed in name field 33 username = username.replace(' ', ':', 1) # Hack because ':' is not allowed in name field
34 wikitag, wikiurl, name, err = wikiutil.resolve_wiki(request, username) 34 wikitag, wikiurl, name, err = wikiutil.resolve_wiki(request, username)
35 35
36 if verbose: request.log("interwiki auth: resolve wiki returned: %r %r %r %r" % (wikitag, wikiurl, name, err)) 36 if verbose: request.log("interwiki auth: resolve wiki returned: %r %r %r %r" % (wikitag, wikiurl, name, err))
37 if err or wikitag not in self.trusted_wikis: 37 if err or wikitag not in self.trusted_wikis:
38 return user_obj, True, None, None 38 return ContinueLogin(user_obj)
39 39
40 homewiki = xmlrpclib.Server(wikiurl + "?action=xmlrpc2") 40 homewiki = xmlrpclib.Server(wikiurl + "?action=xmlrpc2")
41 account_data = homewiki.getUser(name, password) 41 account_data = homewiki.getUser(name, password)
42 if isinstance(account_data, str): 42 if isinstance(account_data, str):
43 if verbose: request.log("interwiki auth: %r wiki said: %s" % (wikitag, account_data)) 43 if verbose: request.log("interwiki auth: %r wiki said: %s" % (wikitag, account_data))
44 return user_obj, True, None, account_data 44 return ContinueLogin(None, account_data)
45 45
46 # TODO: check remote auth_attribs 46 # TODO: check remote auth_attribs
47 u = user.User(request, name=name, auth_method=self.name, auth_attribs=('name', 'aliasname', 'password', 'email', )) 47 u = user.User(request, name=name, auth_method=self.name, auth_attribs=('name', 'aliasname', 'password', 'email', ))
48 for key, value in account_data.iteritems(): 48 for key, value in account_data.iteritems():
49 if key not in request.cfg.user_transient_fields: 49 if key not in request.cfg.user_transient_fields:
50 setattr(u, key, value) 50 setattr(u, key, value)
51 u.valid = True 51 u.valid = True
52 u.create_or_update(True) 52 u.create_or_update(True)
53 if verbose: request.log("interwiki: successful auth for %r" % name) 53 if verbose: request.log("interwiki: successful auth for %r" % name)
54 return u, True, None, None 54 return ContinueLogin(u)