def get_namespace(self, resource, context): cart = ProductCart(context) cart.clean() cart_is_empty = cart.products == [] if cart_is_empty: cart = None else: cart = Cart_View(see_actions=True).GET(resource, context) return {'cart': cart, 'cart_is_empty': cart_is_empty, 'progress': Shop_Progress(index=1).GET(resource, context)}
def get_namespace(self, resource, context): cart = ProductCart(context) cart.clean() cart_is_empty = cart.products == [] if cart_is_empty: cart = None else: cart = Cart_View(see_actions=True).GET(resource, context) return { 'cart': cart, 'cart_is_empty': cart_is_empty, 'progress': Shop_Progress(index=1).GET(resource, context) }
def action(self, resource, context, form): shop = get_shop(resource) root = context.root site_root = resource.get_site_root() # Check the new password matches password = form['password'].strip() if password != form['password_check']: context.message = ERROR(u"The two passwords are different.") return if shop.get_property('registration_need_email_validation') is False: msg = MSG(u'Your inscription has been validaded.') else: msg = MSG(u'Your inscription has been validaded, ' u'you will receive an email to confirm it.') # Do we already have a user with that email? email = form['email'].strip() user = root.get_user_from_login(email) if user is not None: context.message = ERROR(u'This email address is already used.') return # Add the user users = root.get_resource('users') user = users.set_user(email, password) # Set user group (do it befor save_form for dynanic schema) group = self.get_group(context) user.set_property('user_group', str(group.get_abspath())) # Save properties user.save_form(self.get_schema(resource, context), form) # Save address in addresses table if group.get_property('hide_address_on_registration') is False: kw = {'user': user.name} addresses = shop.get_resource('addresses') for key in [ 'gender', 'lastname', 'firstname', 'address_1', 'address_2', 'zipcode', 'town', 'country' ]: kw[key] = form[key] kw['title'] = MSG(u'Your address').gettext() addresses.handler.add_record(kw) # Clean cart, if another user already login before cart = ProductCart(context) cart.clean() # Set the role site_root.set_user_role(user.name, 'guests') # We log authentification shop = get_shop(resource) logs = shop.get_resource('customers/authentification_logs') logs.log_authentification(user.name) user.set_property('last_time', datetime.now()) # Send confirmation email need_email_validation = shop.get_property( 'registration_need_email_validation') user.send_register_confirmation(context, need_email_validation) # User is enabled ? user_is_enabled = group.get_property('user_is_enabled_when_register') user.set_property('is_enabled', user_is_enabled) # Create modules if needed search = context.root.search(is_shop_user_module=True) for brain in search.get_documents(): shop_user_module = root.get_resource(brain.abspath) shop_user_module.initialize(user) # If user not enabled, send mail to webmaster to validate user if user_is_enabled is False: subject = MSG( u'A customer must be validated in your shop').gettext() shop_backoffice_uri = shop.get_property('shop_backoffice_uri') body = registration_notification_body.gettext( name=user.name, email=email, shop_backoffice_uri=shop_backoffice_uri) for to_addr in shop.get_property('order_notification_mails'): root.send_email(to_addr, subject, text=body) # If need_email_validation or user not enable redirect on Welcome if need_email_validation is True or user_is_enabled is False: goto = '%s/welcome/' % context.get_link(group) return context.come_back(msg, goto=goto) ######################## # Do authentification ######################## # Set cookie user.set_auth_cookie(context, form['password']) # Set context context.user = user # Redirect shop = get_shop(resource) if form['goto']: goto = context.query['goto'] elif resource == shop: goto = './;addresses' elif resource.class_id == shop.product_class.class_id: goto = './' else: goto = '/users/%s' % user.name return context.come_back(msg, goto)
def action(self, resource, context, form): shop = get_shop(resource) root = context.root site_root = resource.get_site_root() # Check the new password matches password = form['password'].strip() if password != form['password_check']: context.message = ERROR(u"The two passwords are different.") return if shop.get_property('registration_need_email_validation') is False: msg = MSG(u'Your inscription has been validaded.') else: msg = MSG(u'Your inscription has been validaded, ' u'you will receive an email to confirm it.') # Do we already have a user with that email? email = form['email'].strip() user = root.get_user_from_login(email) if user is not None: context.message = ERROR(u'This email address is already used.') return # Add the user users = root.get_resource('users') user = users.set_user(email, password) # Set user group (do it befor save_form for dynanic schema) group = self.get_group(context) user.set_property('user_group', str(group.get_abspath())) # Save properties user.save_form(self.get_schema(resource, context), form) # Save address in addresses table if group.get_property('hide_address_on_registration') is False: kw = {'user': user.name} addresses = shop.get_resource('addresses') for key in ['gender', 'lastname', 'firstname', 'address_1', 'address_2', 'zipcode', 'town', 'country']: kw[key] = form[key] kw['title'] = MSG(u'Your address').gettext() addresses.handler.add_record(kw) # Clean cart, if another user already login before cart = ProductCart(context) cart.clean() # Set the role site_root.set_user_role(user.name, 'guests') # We log authentification shop = get_shop(resource) logs = shop.get_resource('customers/authentification_logs') logs.log_authentification(user.name) user.set_property('last_time', datetime.now()) # Send confirmation email need_email_validation = shop.get_property('registration_need_email_validation') user.send_register_confirmation(context, need_email_validation) # User is enabled ? user_is_enabled = group.get_property('user_is_enabled_when_register') user.set_property('is_enabled', user_is_enabled) # Create modules if needed search = context.root.search(is_shop_user_module=True) for brain in search.get_documents(): shop_user_module = root.get_resource(brain.abspath) shop_user_module.initialize(user) # If user not enabled, send mail to webmaster to validate user if user_is_enabled is False: subject = MSG(u'A customer must be validated in your shop').gettext() shop_backoffice_uri = shop.get_property('shop_backoffice_uri') body = registration_notification_body.gettext( name=user.name, email=email, shop_backoffice_uri=shop_backoffice_uri) for to_addr in shop.get_property('order_notification_mails'): root.send_email(to_addr, subject, text=body) # If need_email_validation or user not enable redirect on Welcome if need_email_validation is True or user_is_enabled is False: goto = '%s/welcome/' % context.get_link(group) return context.come_back(msg, goto=goto) ######################## # Do authentification ######################## # Set cookie user.set_auth_cookie(context, form['password']) # Set context context.user = user # Redirect shop = get_shop(resource) if form['goto']: goto = context.query['goto'] elif resource == shop: goto = './;addresses' elif resource.class_id == shop.product_class.class_id: goto = './' else: goto = '/users/%s' % user.name return context.come_back(msg, goto)