Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
MoinMoin.userprefs.oid.Settings Class Reference
Inheritance diagram for MoinMoin.userprefs.oid.Settings:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.userprefs.oid.Settings:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def handle_form
def create_form
def handle_form
def allowed
def make_form
def make_row

Public Attributes

 request
 cfg
 title
 allowed
 name

Private Member Functions

def _handle_remove
def _handle_add
def _handle_oidreturn
def _make_form
def _make_row
def _oidlist
def _addoidform

Private Attributes

 _
 _table

Detailed Description

Definition at line 25 of file oid.py.


Constructor & Destructor Documentation

def MoinMoin.userprefs.oid.Settings.__init__ (   self,
  request 
)
Initialize OpenID settings form. 

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 26 of file oid.py.

00026 
00027     def __init__(self, request):
00028         """ Initialize OpenID settings form. """
00029         UserPrefBase.__init__(self, request)
00030         self.request = request
00031         self._ = request.getText
00032         self.cfg = request.cfg
00033         _ = self._
00034         self.title = _("OpenID settings")
00035         openid_auth = False
00036         if not _openid_disabled:
00037             for authm in self.request.cfg.auth:
00038                 if isinstance(authm, OpenIDAuth):
00039                     openid_auth = True
00040                     break
00041         if not openid_auth:
00042             self.allowed = lambda: False


Member Function Documentation

Definition at line 181 of file oid.py.

00181 
00182     def _addoidform(self):
00183         _ = self.request.getText
00184         form = self._make_form()
00185         # go back to this page
00186         form.append(html.INPUT(type="hidden", name="sub", value="oid"))
00187         label = _("Add OpenID")
00188         form.append(html.INPUT(type="text", size="32",
00189                                name="openid_identifier",
00190                                id="openididentifier"))
00191         form.append(html.BR())
00192         form.append(html.INPUT(type="submit", name="add", value=label))
00193         self._make_row(_('Add OpenID'), [form])

Here is the call graph for this function:

Definition at line 58 of file oid.py.

00058 
00059     def _handle_add(self):
00060         _ = self.request.getText
00061         request = self.request
00062 
00063         openid_id = request.form.get('openid_identifier', '')
00064         if not openid_id:
00065             return 'error', _("No OpenID given.")
00066 
00067         if (hasattr(self.request.user, 'openids') and
00068             openid_id in request.user.openids):
00069             return 'error', _("OpenID is already present.")
00070 
00071         oidconsumer = consumer.Consumer(request.session,
00072                                         MoinOpenIDStore(self.request))
00073         try:
00074             oidreq = oidconsumer.begin(openid_id)
00075         except HTTPFetchingError:
00076             return 'error', _('Failed to resolve OpenID.')
00077         except DiscoveryFailure:
00078             return 'error', _('OpenID discovery failure, not a valid OpenID.')
00079         else:
00080             if oidreq is None:
00081                 return 'error', _("No OpenID given.") # ??
00082 
00083             qstr = {'action': 'userprefs',
00084                     'handler': 'oid',
00085                     'oid.return': '1'}
00086             return_to = request.getQualifiedURL(request.page.url(request, qstr))
00087             trust_root = request.url_root
00088             if oidreq.shouldSendRedirect():
00089                 redirect_url = oidreq.redirectURL(trust_root, return_to)
00090                 request.http_redirect(redirect_url)
00091             else:
00092                 form_html = oidreq.formMarkup(trust_root, return_to,
00093                     form_tag_attrs={'id': 'openid_message'})
00094                 request.session['openid.prefs.form_html'] = form_html
00095 

Here is the caller graph for this function:

Definition at line 96 of file oid.py.

00096 
00097     def _handle_oidreturn(self):
00098         request = self.request
00099         _ = request.getText
00100 
00101         oidconsumer = consumer.Consumer(request.session,
00102                                         MoinOpenIDStore(request))
00103         query = {}
00104         for key in request.form:
00105             query[key] = request.form[key]
00106         qstr = {'action': 'userprefs',
00107                 'handler': 'oid',
00108                 'oid.return': '1'}
00109         return_to = request.getQualifiedURL(request.page.url(request, qstr))
00110         info = oidconsumer.complete(query, return_to)
00111         if info.status == consumer.FAILURE:
00112             return 'error', _('OpenID error: %s.') % info.message
00113         elif info.status == consumer.CANCEL:
00114             return 'info', _('Verification canceled.')
00115         elif info.status == consumer.SUCCESS:
00116             if not hasattr(self.request.user, 'openids'):
00117                 request.user.openids = []
00118 
00119             if info.identity_url in request.user.openids:
00120                 return 'error', _("OpenID is already present.")
00121 
00122             if user.getUserIdByOpenId(request, info.identity_url):
00123                 return 'error', _("This OpenID is already used for another account.")
00124 
00125             # all fine
00126             request.user.openids.append(info.identity_url)
00127             request.user.save()
00128             return 'info', _("OpenID added successfully.")
00129         else:
00130             return 'error', _('OpenID failure.')
00131 

Here is the caller graph for this function:

Definition at line 43 of file oid.py.

00043 
00044     def _handle_remove(self):
00045         _ = self.request.getText
00046         if not hasattr(self.request.user, 'openids'):
00047             return
00048         openids = self.request.user.openids[:]
00049         for oid in self.request.user.openids:
00050             name = "rm-%s" % hash_new('sha1', oid).hexdigest()
00051             if name in self.request.form:
00052                 openids.remove(oid)
00053         if not openids and len(self.request.cfg.auth) == 1:
00054             return 'error', _("Cannot remove all OpenIDs.")
00055         self.request.user.openids = openids
00056         self.request.user.save()
00057         return 'info', _("The selected OpenIDs have been removed.")

Here is the caller graph for this function:

Definition at line 153 of file oid.py.

00153 
00154     def _make_form(self):
00155         action = "%s%s" % (self.request.script_root, self.request.path)
00156         _form = html.FORM(action=action)
00157         _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
00158         _form.append(html.INPUT(type="hidden", name="handler", value="oid"))
00159         return _form

Here is the caller graph for this function:

def MoinMoin.userprefs.oid.Settings._make_row (   self,
  label,
  cell,
  kw 
) [private]
Create a row in the form table.

Definition at line 160 of file oid.py.

00160 
00161     def _make_row(self, label, cell, **kw):
00162         """ Create a row in the form table.
00163         """
00164         self._table.append(html.TR().extend([
00165             html.TD(**kw).extend([html.B().append(label), '   ']),
00166             html.TD().extend(cell),
00167         ]))

Here is the caller graph for this function:

def MoinMoin.userprefs.oid.Settings._oidlist (   self) [private]

Definition at line 168 of file oid.py.

00168 
00169     def _oidlist(self):
00170         _ = self.request.getText
00171         form = self._make_form()
00172         for oid in self.request.user.openids:
00173             name = "rm-%s" % hash_new('sha1', oid).hexdigest()
00174             form.append(html.INPUT(type="checkbox", name=name, id=name))
00175             form.append(html.LABEL(for_=name).append(html.Text(oid)))
00176             form.append(html.BR())
00177         self._make_row(_("Current OpenIDs"), [form], valign='top')
00178         label = _("Remove selected")
00179         form.append(html.BR())
00180         form.append(html.INPUT(type="submit", name="remove", value=label))

Here is the call graph for this function:

def MoinMoin.userprefs.UserPrefBase.allowed (   self) [inherited]
    Not all preferences are applicable to all users,
    this method is called to determine whether the
    title should be listed or not and whether
    submissions are accepted.

Reimplemented in MoinMoin.userprefs.notification.Settings, MoinMoin.userprefs.changepass.Settings, MoinMoin.userprefs.suid.Settings, and MoinMoin.userprefs.oidserv.Settings.

Definition at line 60 of file __init__.py.

00060 
00061     def allowed(self):
00062         '''
00063             Not all preferences are applicable to all users,
00064             this method is called to determine whether the
00065             title should be listed or not and whether
00066             submissions are accepted.
00067         '''
00068         return self.request.user and self.request.user.valid

Create the complete HTML form code. 

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 194 of file oid.py.

00194 
00195     def create_form(self):
00196         """ Create the complete HTML form code. """
00197         _ = self._
00198 
00199         ret = html.P()
00200         # Use the user interface language and direction
00201         lang_attr = self.request.theme.ui_lang_attr()
00202         ret.append(html.Raw('<div %s>' % lang_attr))
00203         self._table = html.TABLE(border="0")
00204         ret.append(self._table)
00205         ret.append(html.Raw("</div>"))
00206 
00207         request = self.request
00208 
00209         if 'openid.prefs.form_html' in request.session:
00210             txt = _('OpenID verification requires that you click this button:')
00211             # create JS to automatically submit the form if possible
00212             submitjs = """<script type="text/javascript">
00213 <!--//
00214 document.getElementById("openid_message").submit();
00215 //-->
00216 </script>
00217 """
00218             oidhtml = request.session['openid.prefs.form_html']
00219             del request.session['openid.prefs.form_html']
00220             return ''.join([txt, oidhtml, submitjs])
00221 
00222         if hasattr(request.user, 'openids') and request.user.openids:
00223             self._oidlist()
00224         self._addoidform()
00225 
00226         form = self._make_form()
00227         label = _("Cancel")
00228         form.append(html.INPUT(type="submit", name='cancel', value=label))
00229         self._make_row('', [form])
00230         return unicode(ret)
def MoinMoin.userprefs.UserPrefBase.handle_form (   self,
  request 
) [inherited]
    When any of the created forms is submitted and the
    hidden fields are set correctly (see create_form)
    this method will be invoked to handle the user's
    input. Note that GET requests are also handed to
    this method, so if you require POST check that.

Definition at line 50 of file __init__.py.

00050 
00051     def handle_form(self, request):
00052         '''
00053             When any of the created forms is submitted and the
00054             hidden fields are set correctly (see create_form)
00055             this method will be invoked to handle the user's
00056             input. Note that GET requests are also handed to
00057             this method, so if you require POST check that.
00058         '''
00059         raise NotImplementedError

Definition at line 132 of file oid.py.

00132 
00133     def handle_form(self):
00134         _ = self._
00135         form = self.request.form
00136 
00137         if self.request.values.has_key('oid.return'):
00138             return self._handle_oidreturn()
00139 
00140         if form.has_key('cancel'):
00141             return
00142 
00143         if self.request.method != 'POST':
00144             return
00145 
00146         if form.has_key('remove'):
00147             return self._handle_remove()
00148 
00149         if form.has_key('add'):
00150             return self._handle_add()
00151 
00152         return

Here is the call graph for this function:

def MoinMoin.userprefs.UserPrefBase.make_form (   self,
  explanation = None 
) [inherited]
    To have a consistent UI, use this method for most
    preferences forms and then call make_row(). See
    existing plugins, e.g. changepass.py.

Definition at line 69 of file __init__.py.

00069 
00070     def make_form(self, explanation=None):
00071         '''
00072             To have a consistent UI, use this method for most
00073             preferences forms and then call make_row(). See
00074             existing plugins, e.g. changepass.py.
00075         '''
00076         action = self.request.page.url(self.request)
00077         _form = html.FORM(action=action)
00078         _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
00079         _form.append(html.INPUT(type="hidden", name="handler", value=self.name))
00080 
00081         self._table = html.TABLE(border="0")
00082 
00083         # Use the user interface language and direction
00084         lang_attr = self.request.theme.ui_lang_attr()
00085         _form.append(html.Raw('<div class="userpref"%s>' % lang_attr))
00086         para = html.P()
00087         _form.append(para)
00088         if explanation:
00089             para.append(explanation)
00090 
00091         para.append(self._table)
00092         _form.append(html.Raw("</div>"))
00093 
00094         return _form

Here is the caller graph for this function:

def MoinMoin.userprefs.UserPrefBase.make_row (   self,
  label,
  cell,
  kw 
) [inherited]
   Create a row in the form table.

Definition at line 95 of file __init__.py.

00095 
00096     def make_row(self, label, cell, **kw):
00097         '''
00098            Create a row in the form table.
00099         '''
00100         self._table.append(html.TR().extend([
00101             html.TD(**kw).extend([html.B().append(label), '   ']),
00102             html.TD().extend(cell),
00103         ]))

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 30 of file oid.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 202 of file oid.py.

Definition at line 41 of file oid.py.

Definition at line 31 of file oid.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 29 of file oid.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 33 of file oid.py.


The documentation for this class was generated from the following file: