Changeset 12039


Ignore:
Timestamp:
23 Nov 2014, 16:54:27 (10 years ago)
Author:
Henrik Bettermann
Message:

Implement customer self-registration.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/templates/loginpage.pt

    r11952 r12039  
    1111    <div class="col-sm-10">
    1212      <input name="form.password" type="password" class="form-control" id="password">
    13       <font  i18n:translate="" color="red"> Notice: User names, Ids and passwords are case sensitive.</font>
     13      <font  i18n:translate="" color="red"> Notice: User names, ids and passwords are case sensitive.</font>
    1414    </div>
    1515  </div>
     
    2222  </p>
    2323  <p i18n:translate="login_trouble2" tal:condition="python:False">
    24     You don't have an account because you are a new customer, or your customer record has just been created?
     24    You don't have an account because you are a new customer, or your customer record has been created for you?
    2525    Acquire a Password Activation Code (PWD) and inititialize your customer account
    2626    <strong><a href ="setpassword"> here</a></strong>.
    2727  </p>
    2828  <p i18n:translate="login_trouble4">
    29     You don't have an account because you are a new customer, or your customer record has just been created?
     29    You don't have an account because you are a new customer?
     30    Create your customer account <strong><a href="createaccount"> here</a></strong>.
     31  </p>
     32  <p i18n:translate="login_trouble5">
     33    You don't have an account because you are a new customer and your customer record has been created for you?
    3034    Inititialize your customer account <strong><a href="requestpw"> here</a></strong>.
    3135  </p>
    32   <p i18n:translate="login_trouble3"> Or simply forgot your customer id password? Then request a new password
     36  <p i18n:translate="login_trouble3"> Or simply forgot your id or password? Then request a new password
    3337    <strong><a href="changepw"> here</a></strong>.
    3438  </p>
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12035 r12039  
    4747from waeup.ikoba.customers.interfaces import (
    4848    ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils,
    49     ICustomerDocument, ICustomerDocumentsContainer
     49    ICustomerDocument, ICustomerDocumentsContainer, ICustomerCreate
    5050    )
    5151from waeup.ikoba.customers.catalog import search
     
    467467
    468468class CustomerRequestPasswordPage(IkobaAddFormPage):
    469     """Captcha'd registration page for applicants.
     469    """Captcha'd password request page for customers.
    470470    """
    471471    grok.name('requestpw')
    472472    grok.require('waeup.Anonymous')
    473473    grok.template('requestpw')
    474     form_fields = grok.AutoFields(ICustomerRequestPW).select(
    475         'firstname','number','email')
     474    form_fields = grok.AutoFields(ICustomerRequestPW)
    476475    label = _('Request password for first-time login')
    477476
     
    484483
    485484    def _redirect(self, email, password, customer_id):
    486         # Forward only email to landing page in base package.
     485        # Forward only email address to landing page in base package.
    487486        self.redirect(self.url(self.context, 'requestpw_complete',
    488487            data=dict(email=email)))
     
    554553
    555554
     555class CustomerCreateAccountPage(IkobaAddFormPage):
     556    """Captcha'd account creation page for customers.
     557    """
     558    grok.name('createaccount')
     559    grok.require('waeup.Anonymous')
     560    grok.template('createaccount')
     561    form_fields = grok.AutoFields(ICustomerCreate)
     562    label = _('Create customer account')
     563
     564    def update(self):
     565        # Handle captcha
     566        self.captcha = getUtility(ICaptchaManager).getCaptcha()
     567        self.captcha_result = self.captcha.verify(self.request)
     568        self.captcha_code = self.captcha.display(self.captcha_result.error_code)
     569        return
     570
     571    def _redirect(self, email, password, customer_id):
     572        # Forward only email address to landing page in base package.
     573        self.redirect(self.url(self.context, 'requestpw_complete',
     574            data=dict(email=email)))
     575        return
     576
     577    @action(_('Send login credentials to email address'), style='primary')
     578    def create_account(self, **data):
     579        if not self.captcha_result.is_valid:
     580            # Captcha will display error messages automatically.
     581            # No need to flash something.
     582            return
     583        customer = createObject(u'waeup.Customer')
     584        customer.firstname = data.get('firstname','')
     585        customer.middlename = data.get('middlename','')
     586        customer.lastname = data.get('lastname','')
     587        customer.email = data.get('email','')
     588        self.context['customers'].addCustomer(customer)
     589        ikoba_utils = getUtility(IIkobaUtils)
     590        password = ikoba_utils.genPassword()
     591        mandate = PasswordMandate()
     592        mandate.params['password'] = password
     593        mandate.params['user'] = customer
     594        site = grok.getSite()
     595        site['mandates'].addMandate(mandate)
     596        # Send email with credentials
     597        args = {'mandate_id':mandate.mandate_id}
     598        mandate_url = self.url(site) + '/mandate?%s' % urlencode(args)
     599        url_info = u'Confirmation link: %s' % mandate_url
     600        msg = _('You have successfully created a customer account for the')
     601        if ikoba_utils.sendCredentials(IUserAccount(customer),
     602            password, url_info, msg):
     603            email_sent = customer.email
     604        else:
     605            email_sent = None
     606        self._redirect(email=email_sent, password=password,
     607            customer_id=customer.customer_id)
     608        ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','')
     609        self.context.logger.info(
     610            '%s - %s - %s' % (ob_class, customer.customer_id, email_sent))
     611        return
     612
     613
    556614class CustomerRequestPasswordEmailSent(IkobaPage):
    557615    """Landing page after successful password request.
     
    561619    grok.require('waeup.Public')
    562620    grok.template('requestpwmailsent')
    563     label = _('Your password request was successful.')
     621    label = _('Your request was successful.')
    564622
    565623    def update(self, email=None, customer_id=None, password=None):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/changepassword.pt

    r11979 r12039  
    2121    </tbody>
    2222  </table>
     23  <br />
    2324
    2425  <div tal:condition="view/availableActions">
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/requestpw.pt

    r11996 r12039  
    2121    To be able to proceed you must provide a valid email address!
    2222  </p>
     23  <br />
    2324  <div tal:condition="view/availableActions">
    2425    <input tal:repeat="action view/actions"
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12018 r12039  
    205205
    206206
    207 class ICustomerRequestPW(ICustomer):
    208     """Representation of an customer for first-time password request.
     207class ICustomerRequestPW(IIkobaObject):
     208    """Representation of a customer for first-time password request.
    209209
    210210    This interface is used when customers use the requestpw page to
     
    228228
    229229
     230class ICustomerCreate(IIkobaObject):
     231    """Representation of an customer for account creation.
     232
     233    This interface is used when customers use the createaccount page.
     234    """
     235
     236    firstname = schema.TextLine(
     237        title = _(u'First Name'),
     238        required = True,
     239        )
     240
     241    middlename = schema.TextLine(
     242        title = _(u'Middle Name'),
     243        required = False,
     244        )
     245
     246    lastname = schema.TextLine(
     247        title = _(u'Last Name (Surname)'),
     248        required = True,
     249        )
     250
     251    email = schema.ASCIILine(
     252        title = _(u'Email Address'),
     253        required = True,
     254        constraint=validate_email,
     255        )
     256
     257
    230258# Customer document interfaces
    231259
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12038 r12039  
    703703        self.browser.getControl("Send login credentials").click()
    704704        # Yeah, we succeded ...
    705         self.assertTrue('Your password request was successful.'
     705        self.assertTrue('Your request was successful.'
    706706            in self.browser.contents)
    707707        # ... and  customer can be found in the catalog via the email address
Note: See TracChangeset for help on using the changeset viewer.