def save_contact(self, request): log.debug("Saving contact") data = self.cleaned_data password = data['password1'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] username = generate_id(first_name, last_name, email) verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: from registration.models import RegistrationProfile user = RegistrationProfile.objects.create_inactive_user( username, password, email, send_email=True) else: user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() # If the user already has a contact, retrieve it. # Otherwise, create a new one. try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = 'Customer' contact.title = data.get('title', '') contact.save() if 'newsletter' not in data: subscribed = False else: subscribed = data['newsletter'] signals.satchmo_registration.send(self, contact=contact, subscribed=subscribed, data=data) if not verify: user = authenticate(username=username, password=password) login(request, user) send_welcome_email(email, first_name, last_name) signals.satchmo_registration_verified.send(self, contact=contact) self.contact = contact return contact
def save_contact(self, request): log.debug("Saving contact") data = self.cleaned_data password = data['password1'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] username = data['username'] verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: from registration.models import RegistrationProfile user = RegistrationProfile.objects.create_inactive_user( username, password, email, send_email=True) else: user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() # If the user already has a contact, retrieve it. # Otherwise, create a new one. try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = 'Customer' contact.title = data.get('title', '') contact.save() signals.satchmo_registration.send(self, contact=contact, data=data) if not verify: user = authenticate(username=username, password=password) login(request, user) send_welcome_email(email, first_name, last_name) signals.satchmo_registration_verified.send(self, contact=contact) self.contact = contact return contact
def register_handle_form(request, redirect=None): """ Handle all registration logic. This is broken out from "register" to allow easy overriding/hooks such as a combined login/register page. Returns: - Success flag - HTTPResponseRedirect (success) or form (fail) """ if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): data = form.cleaned_data password = data['password'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] username = generate_id(first_name, last_name) verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: from registration.models import RegistrationProfile user = RegistrationProfile.objects.create_inactive_user( username, password, email, send_email=True) else: user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() # If the user already has a contact, retrieve it. # Otherwise, create a new one. contact = Contact.from_request(request, create=False) if contact is None: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = 'Customer' contact.save() if config_get_group('NEWSLETTER'): from satchmo.newsletter import update_subscription if 'newsletter' not in data: subscribed = False else: subscribed = data['newsletter'] update_subscription(contact, subscribed) if not verify: user = authenticate(username=username, password=password) login(request, user) send_welcome_email(email, first_name, last_name) if not redirect: redirect = urlresolvers.reverse('registration_complete') return (True, http.HttpResponseRedirect(redirect)) else: initial_data = {} contact = Contact.from_request(request, create=False) if contact is not None: initial_data = { 'email': contact.email, 'first_name': contact.first_name, 'last_name': contact.last_name} if contact and config_get_group('NEWSLETTER'): from satchmo.newsletter import is_subscribed current_subscriber = is_subscribed(contact) else: current_subscriber = False initial_data['newsletter'] = current_subscriber form = RegistrationForm(initial=initial_data) return (False, form)
def register_handle_form(request, redirect=None): """ Handle all registration logic. This is broken out from "register" to allow easy overriding/hooks such as a combined login/register page. Returns: - Success flag - HTTPResponseRedirect (success) or form (fail) """ if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): data = form.cleaned_data password = data['password'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] username = generate_id(first_name, last_name) verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: from registration.models import RegistrationProfile user = RegistrationProfile.objects.create_inactive_user( username, password, email, send_email=True) else: user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() # If the user already has a contact, retrieve it. # Otherwise, create a new one. contact = Contact.from_request(request, create=False) if contact is None: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = 'Customer' contact.save() if config_get_group('NEWSLETTER'): from satchmo.newsletter import update_subscription if 'newsletter' not in data: subscribed = False else: subscribed = data['newsletter'] update_subscription(contact, subscribed) if not verify: user = authenticate(username=username, password=password) login(request, user) send_welcome_email(email, first_name, last_name) if not redirect: redirect = urlresolvers.reverse('registration_complete') return (True, http.HttpResponseRedirect(redirect)) else: initial_data = {} contact = Contact.from_request(request, create=False) if contact is not None: initial_data = { 'email': contact.email, 'first_name': contact.first_name, 'last_name': contact.last_name } if contact and config_get_group('NEWSLETTER'): from satchmo.newsletter import is_subscribed current_subscriber = is_subscribed(contact) else: current_subscriber = False initial_data['newsletter'] = current_subscriber form = RegistrationForm(initial=initial_data) return (False, form)