[register] Register cube should not be mandatory, see #3299721
authorVincent Michel <vincent.michel@logilab.fr>
Mon, 25 Nov 2013 13:34:35 +0000
changeset 502 3b73b96326c8
parent 501 fe6d699ca8e8
child 503 4797298ce571
[register] Register cube should not be mandatory, see #3299721
__pkginfo__.py
views/register.py
--- a/__pkginfo__.py	Fri Nov 08 11:08:28 2013 +0000
+++ b/__pkginfo__.py	Mon Nov 25 13:34:35 2013 +0000
@@ -21,12 +21,12 @@
                 'cubicweb-card': None,
                 'cubicweb-bootstrap': None,
                 'cubicweb-comment': None,
-                'cubicweb-registration': None,
-                'cubicweb-forgotpwd': None,
                 'cubicweb-jqplot': None,
                 }
 __recommends__ = {'cubicweb-brainoviz': None,
                   'cubicweb-vtimeline': '>= 0.4.0',
+                  'cubicweb-registration': None,
+                  'cubicweb-forgotpwd': None,
                   }
 
 
--- a/views/register.py	Fri Nov 08 11:08:28 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +0,0 @@
-# -*- coding: utf-8 -*-
-# copyright 2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr -- mailto:contact@logilab.fr
-# copyright 2013 CEA (Saclay, FRANCE), all rights reserved.
-#
-# This program is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with this program. If not, see <http://www.gnu.org/licenses/>.
-
-"""cubicweb-brainomics views/forms/actions/components for web ui"""
-from cubicweb import crypto
-
-from logilab.common.decorators import clear_cache
-from logilab.mtconverter import xml_escape
-
-from cubicweb.web import ValidationError, Redirect
-from cubicweb.web import formwidgets as fw, formfields as ff
-
-from cubes.registration.views import (RegistrationFormView,
-                                      RegistrationForm,
-                                      RegistrationSendMailController,
-                                      RegistrationConfirmController,
-                                      RegisterLink, qname)
-
-
-###############################################################################
-### REGISTRATION LINK #########################################################
-###############################################################################
-class BrainomicsRegisterLink(RegisterLink):
-
-    def render(self, w):
-        w(u'<a class="btn btn-info" href="%s">%s</a>' % (
-            self._cw.build_url('register'), self._cw._('i18n_register_user')))
-
-
-###############################################################################
-### REGISTRATION VIEW #########################################################
-###############################################################################
-class BrainomicsRegistrationFormView(RegistrationFormView):
-
-    def call(self):
-        # Redefine the RegistrationView to include (if existing)
-        # the license of the data
-        super(BrainomicsRegistrationFormView, self).call()
-        card = self._cw.execute('Any X WHERE X is Card, X title %(t)s', {'t': 'license'})
-        if card:
-            msg = self._cw._(u'By signing up to this site you implicitly accept its '
-                             'terms and conditions, which are stated '
-                             'in the License agreement shown below')
-            self.w(u'<span class="badge badge-important">%s</span>' % xml_escape(msg))
-            self.w(u'<div>%s</div>' % card.get_entity(0, 0).content)
-
-
-###############################################################################
-### REGISTRATION FORMS ########################################################
-###############################################################################
-class BrainomicsRegistrationForm(RegistrationForm):
-    affiliation = ff.StringField(widget=fw.TextInput(), role='subject',
-                                label=_('affiliation'),
-                                help=_('Please provide affiliation information'),
-                                required=True)
-
-    extra_infos = ff.StringField(widget=fw.TextInput(), role='subject',
-                                 label=_('extra infos'),
-                                 help=_('Provide additional information if desired'))
-
-    acceptance = ff.BooleanField(widget=fw.Radio(), role='subject',
-                                 label=_('license acceptance'),
-                                 help=_('Please click to accept license (see below)'),
-                                 required=True)
-
-
-class BrainomicsRegistrationSendMailController(RegistrationSendMailController):
-
-    def checked_data(self):
-        data = super(BrainomicsRegistrationSendMailController, self).checked_data()
-        if not data.get(qname('acceptance')):
-            license_error = self._cw._('License error')
-            no_license = xml_escape(self._cw._('To register, you have to accept the license'))
-            raise ValidationError(None, {'License error': no_license})
-        return data
-
-
-###############################################################################
-### REGISTRATION CONTROLLER ###################################################
-###############################################################################
-class BrainomicsRegistrationConfirmController(RegistrationConfirmController):
-
-    # Overridden to add the ``affiliation`` and ``extra_infos`` kwargs to ``register_user`` call
-    def publish(self, rset=None):
-        req = self._cw
-        try:
-            data = crypto.decrypt(req.form['key'],
-                                  req.vreg.config['registration-cypher-seed'])
-            login = data[qname('login')]
-            password = data.pop(qname('upassword'))
-        except:
-            msg = req._(u'Invalid registration data. Please try registering again.')
-            raise Redirect(req.build_url(u'register', __message=msg))
-        if self._cw.user.login == login:
-            # already logged in (e.g. regstration link replayed twice in the browser)
-            raise Redirect(self.success_redirect_url())
-        req.form = data # hijack for proper validation error handling
-        err_raised = False
-        try:
-            self.appli.repo.register_user(login, password,
-                                          email=data.get(qname('email_address')),
-                                          firstname=data.get(qname('firstname')),
-                                          surname=data.get(qname('surname')),
-                                          affiliation=data.get(qname('affiliation')),
-                                          extra_infos=data.get(qname('extra_infos')))
-        except ValidationError, err:
-            err_raised = True
-            if err.errors.keys() != ['login-subject']:
-                raise
-        # force new authentication (anon until there)
-        clear_cache(req, 'get_authorization')
-        req.form['__login'] = login
-        req.form['__password'] = password
-        if req.cnx:
-            req.cnx.close()
-        req.cnx = None
-        try:
-            self.appli.session_handler.set_session(req)
-        except Redirect:
-            pass
-        if req.user.login != 'login' and err_raised:
-            # if both authentication and register_user() failed, the problem
-            # is probably that we do have a true login conflict, just re-raise
-            # the original validation error
-            raise
-        assert req.user.login == login
-        raise Redirect(self.success_redirect_url())
-
-
-
-
-def registration_callback(vreg):
-    vreg.register_and_replace(BrainomicsRegistrationForm, RegistrationForm)
-    vreg.register_and_replace(BrainomicsRegistrationSendMailController,
-                              RegistrationSendMailController)
-    vreg.register_and_replace(BrainomicsRegistrationConfirmController,
-                              RegistrationConfirmController)
-    vreg.register_and_replace(BrainomicsRegistrationFormView, RegistrationFormView)
-    vreg.register_and_replace(BrainomicsRegisterLink, RegisterLink)