comparison MoinMoin/userprefs/oid.py @ 2364:96ec23afac7d

fix some bugs in openid prefs
author Johannes Berg <johannes AT sipsolutions DOT net>
date Thu, 12 Jul 2007 11:39:35 +0200
parents 8eb96bfafef9
children 6d9970321d79
comparison
equal deleted inserted replaced
2363:a73c99c076c2 2364:96ec23afac7d
4 4
5 @copyright: 2007 MoinMoin:JohannesBerg 5 @copyright: 2007 MoinMoin:JohannesBerg
6 @license: GNU GPL, see COPYING for details. 6 @license: GNU GPL, see COPYING for details.
7 """ 7 """
8 8
9 from MoinMoin import wikiutil 9 from MoinMoin import wikiutil, user
10 from MoinMoin.widget import html 10 from MoinMoin.widget import html
11 from MoinMoin.userprefs import UserPrefBase 11 from MoinMoin.userprefs import UserPrefBase
12 from MoinMoin.auth.openidrp import OpenIDAuth 12 from MoinMoin.auth.openidrp import OpenIDAuth
13 import sha 13 import sha
14 from MoinMoin.util.moinoid import MoinOpenIDStore 14 from MoinMoin.util.moinoid import MoinOpenIDStore
32 return UserPrefBase.allowed(self) 32 return UserPrefBase.allowed(self)
33 return False 33 return False
34 34
35 def _handle_remove(self): 35 def _handle_remove(self):
36 _ = self.request.getText 36 _ = self.request.getText
37 if not hasattr(self.request.user, 'openids'):
38 return
37 openids = self.request.user.openids[:] 39 openids = self.request.user.openids[:]
38 for oid in self.request.user.openids: 40 for oid in self.request.user.openids:
39 name = "rm-%s" % sha.new(oid).hexdigest() 41 name = "rm-%s" % sha.new(oid).hexdigest()
40 if name in self.request.form: 42 if name in self.request.form:
41 openids.remove(oid) 43 openids.remove(oid)
48 def _handle_add(self): 50 def _handle_add(self):
49 _ = self.request.getText 51 _ = self.request.getText
50 request = self.request 52 request = self.request
51 53
52 openid_id = request.form.get('openid_identifier', [''])[0] 54 openid_id = request.form.get('openid_identifier', [''])[0]
53 55 if not openid_id:
54 if openid_id in request.user.openids: 56 return _("No OpenID.")
57
58 if (hasattr(self.request.user, 'openids') and
59 openid_id in request.user.openids):
55 return _("OpenID is already present.") 60 return _("OpenID is already present.")
56 61
57 oidconsumer = consumer.Consumer(request.session, 62 oidconsumer = consumer.Consumer(request.session,
58 MoinOpenIDStore(self.request)) 63 MoinOpenIDStore(self.request))
59 try: 64 try:
99 if info.status == consumer.FAILURE: 104 if info.status == consumer.FAILURE:
100 return _('OpenID error: %s.') % info.message 105 return _('OpenID error: %s.') % info.message
101 elif info.status == consumer.CANCEL: 106 elif info.status == consumer.CANCEL:
102 return _('Verification canceled.') 107 return _('Verification canceled.')
103 elif info.status == consumer.SUCCESS: 108 elif info.status == consumer.SUCCESS:
104 if not info.identity_url in request.user.openids: 109 if not hasattr(self.request.user, 'openids'):
105 request.user.openids.append(info.identity_url) 110 request.user.openids = []
106 request.user.save() 111
107 return _("OpenID added successfully.") 112 if info.identity_url in request.user.openids:
108 else:
109 return _("OpenID is already present.") 113 return _("OpenID is already present.")
114
115 if user.getUserIdByOpenId(request, info.identity_url):
116 return _("This OpenID is already used for another account.")
117
118 # all fine
119 request.user.openids.append(info.identity_url)
120 request.user.save()
121 return _("OpenID added successfully.")
110 else: 122 else:
111 return _('OpenID failure.') 123 return _('OpenID failure.')
112 124
113 125
114 def handle_form(self): 126 def handle_form(self):
197 """ 209 """
198 oidhtml = request.session['openid.prefs.form_html'] 210 oidhtml = request.session['openid.prefs.form_html']
199 del request.session['openid.prefs.form_html'] 211 del request.session['openid.prefs.form_html']
200 return ''.join([txt, oidhtml, submitjs]) 212 return ''.join([txt, oidhtml, submitjs])
201 213
202 if request.user.openids: 214 if hasattr(request.user, 'openids') and request.user.openids:
203 self._oidlist() 215 self._oidlist()
204 self._addoidform() 216 self._addoidform()
205 217
206 form = self._make_form() 218 form = self._make_form()
207 label = _("Cancel") 219 label = _("Cancel")