Ejemplo n.º 1
0
 def _get_products(self):
     """
     Format of cookie "products":
       id|name|quantity|declination
     Example:
       1|polo-red-ikaaro|2|4
     """
     products = []
     cookie = self.context.get_cookie('products')
     if not cookie or cookie == 'deleted':
         return products
     cookie = Password.decode(cookie)
     for data in cookie.split('@'):
         try:
             id, name, quantity, declination = data.split('|')
         except ValueError:
             raise ValueError, 'Value "%s" is incorrect' % data
         # Check product exist
         product = self.context.root.get_resource(name, soft=True)
         if not product or not product.is_buyable(self.context):
             continue
         # Add product
         products.append({'id': id,
                          'name': name,
                          'quantity': int(quantity),
                          'declination': declination})
     return products
Ejemplo n.º 2
0
    def action(self, resource, context, form):
        # Get the user
        email = form['username'].strip()
        user = context.root.get_user_from_login(email)
        if form['no_password']:
            if not Email.is_valid(email):
                message = u'The given username is not an email address.'
                context.message = ERROR(message)
                return
            # Case 1: Register
            # check captcha first
            captcha = form['captcha'].strip()
            crypted = crypt_captcha(captcha)
            crypt_imgtext = form['crypt_imgtext'].strip()
            decrypt =  Password.decode('%s' % crypt_imgtext)
            if crypted != decrypt:
                error = u"You typed an incorrect captcha string."
                context.message = ERROR(error)
                return
            # does the user exists?
            if user is None:
                if context.site_root.is_allowed_to_register():
                    return self._register(resource, context, email)
                    # FIXME This message does not protect privacy
                    error = u"You don't have an account, contact the site admin."
                    context.message = ERROR(error)
                    return
            # Case 2: Forgotten password
            email = user.get_property('email')
            user.send_forgotten_password(context, email)
            path = '/ui/website/forgotten_password.xml'
            handler = resource.get_resource(path)
            return stl(handler)
        
        # Case 3: Login
        password = form['password']
        if user is None or not user.authenticate(password, clear=True):
            context.message = ERROR(u'The email or the password is incorrect.')
            return
        # Set cookie & context
        user.set_auth_cookie(context, password)
        context.user = user

        # Come back
        referrer = context.get_referrer()
        if referrer is None:
            goto = get_reference('./')
        else:
            path = get_uri_path(referrer)
            if path.endswith(';login'):
                goto = get_reference('./')
            else:
                goto = referrer
        return context.come_back(INFO(u"Welcome to the Phoenix Project!"), goto)
Ejemplo n.º 3
0
 def _get_shipping(self):
     """
     Format of cookie "shipping":
       shipping_name|shipping_option
     Example:
       collisimo|suivi
     """
     cookie = self.context.get_cookie('shipping')
     if not cookie or cookie == 'deleted':
         return None
     cookie = Password.decode(cookie)
     name, option = cookie.split('|')
     return {'name': name, 'option': option}
Ejemplo n.º 4
0
 def _get_addresses(self):
     """
     Format of cookie "addresses":
       id_delivery_address|id_bill_address
     Example:
       25|45
     """
     cookie = self.context.get_cookie('addresses')
     if not cookie or cookie == 'deleted':
         delivery_address = bill_address = None
     else:
         cookie = Password.decode(cookie)
         delivery_address, bill_address = cookie.split('|')
         delivery_address = int(delivery_address) if delivery_address else None
         bill_address = int(bill_address) if bill_address else None
     return {'delivery_address':delivery_address,
             'bill_address': bill_address}
Ejemplo n.º 5
0
 def _get_id_zone(self):
     cookie = self.context.get_cookie('id_zone')
     if not cookie or cookie == 'deleted':
         return None
     return Password.decode(cookie)