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(self, site_skin): cd = self.cleaned_data user = User() user.username=cd['username'] user.email = cd['email'] user.first_name = cd['first_name'] user.last_name = cd['last_name'] user.is_active = True user.save() user.set_password(cd['password1']) contact = Contact() contact.user = user contact.role = ContactRole.objects.get(key='Concierge') contact.email = cd['email'] contact.save() # the listeners.sfst_object_link creates the concierge and adds it to contact.concierge. concierge = contact.concierge concierge.site_skin = site_skin concierge.contact = contact concierge.booking_type = cd['booking_type'] if 'send_checks_to_bool' in cd and cd['send_checks_to_bool']: concierge.send_checks_to = Concierge.SEND_CHECKS_TO_HOME concierge.save() super(ConciergeRegistrationForm, self).save(concierge) # create default commissions for this new concierge for tour_type in TourType.objects.filter(active=True): ConciergeCommission.objects.create(concierge=concierge, tour_type=tour_type, amount=tour_type.default_commission) # shoot emails to concierge about this c_subject = 'Your Concierge Account with SF Shuttle Tours / NY Sprinter Tours has been setup!' c_message = 'Thank you for creating your Concierge Account with us! You will now be able to easily book tours online, track your sales commission, request brochures, and send us messages through your own account.\n\n' c_message += 'PLEASE BOOKMARK THIS LINK: http://%s%s\n\n' % (django_settings.SITE_DOMAIN, reverse('concierges_home')) c_message += 'This is the link you will use on a daily basis. If you are having any trouble with your account, please call us at 415-513-5400 (for NY concierges call 1-888-996-9286) and we will be happy to help you!\n\n' c_message += 'Regards,\nSF Shuttle Tours / NY Sprinter Tours Team!\n\n' start_thread(send_mail, c_subject, c_message, django_settings.DEFAULT_FROM_EMAIL, [django_settings.DEFAULT_TO_EMAIL, contact.email]) # shoot an email to admins about this a_subject = '"%s %s" has just created a Concierge Account' % (user.first_name, user.last_name) a_message = 'Concierge Name: %s %s\n' % (user.first_name, user.last_name) a_message += 'Hotel name: %s\n' % concierge.hotel_name a_message += 'Phone number: %s %s\n' % (concierge.hotel_phone(), concierge.home_phone()) a_message += 'How often they book our tours: %s\n' % concierge.frequency a_message += 'Average number of tours they book per week: %s\n' % concierge.per_week start_thread(send_mail, a_subject, a_message, django_settings.DEFAULT_FROM_EMAIL, [django_settings.DEFAULT_TO_EMAIL,])
def handler_create_profile(sender, user, **kwargs): try: contact = Contact.objects.get(user=user) except Contact.DoesNotExist: contact = Contact() contact.user = user #contact.first_name = first_name #contact.last_name = last_name contact.email = user.email contact.role = ContactRole.objects.get(pk='Customer') contact.title = '' contact.save() l.debug("Signal Profile Create default -> satchmo_registration_verified") signals.satchmo_registration_verified.send(sender=sender, contact=contact)
def register(self, request, **kwargs): """Use HtmlRegistrationProfile instead of default RegistrationProfile """ username = kwargs['username'] email = kwargs['email'] password = kwargs['password1'] first_name = kwargs['first_name'] last_name = kwargs['last_name'] if not username: username = generate_id(first_name, last_name, email) if Site._meta.installed: site = Site.objects.get_current() else: site = RequestSite(request) new_user = HtmlRegistrationProfile.objects.create_inactive_user( username, email, password, site) new_user.first_name = first_name new_user.last_name = last_name new_user.save() signals.user_registered.send(sender=self.__class__, user=new_user, request=request) # If the user already has a contact, retrieve it. # Otherwise, create a new one. contact = None try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: pass if contact is None: contact = Contact() contact.user = new_user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = ContactRole.objects.get(pk='Customer') contact.title = "%s %s" % (first_name, last_name) contact.save() return new_user
def save_info(self, contact=None, **kwargs): """Save the contact info into the database. Checks to see if contact exists. If not, creates a contact and copies in the address and phone number.""" if not contact: customer = Contact() log.debug('creating new contact') else: customer = contact log.debug('Saving contact info for %s', contact) data = self.cleaned_data.copy() country = data['country'] if not isinstance(country, Country): country = Country.objects.get(pk=country) data['country'] = country data['country_id'] = country.id shipcountry = data['ship_country'] if not isinstance(shipcountry, Country): shipcountry = Country.objects.get(pk=shipcountry) data['ship_country'] = shipcountry data['ship_country_id'] = shipcountry.id organization_name = data.pop('organization', None) if organization_name: org = Organization.objects.by_name(organization_name, create=True) customer.organization = org else: # in case customer wants to remove organization name from their profile customer.organization = None for field in customer.__dict__.keys(): try: setattr(customer, field, data[field]) except KeyError: pass if not customer.role: customer.role = ContactRole.objects.get(pk='Customer') customer.save() # we need to make sure we don't blindly add new addresses # this isn't ideal, but until we have a way to manage addresses # this will force just the two addresses, shipping and billing # TODO: add address management like Amazon. bill_address = customer.billing_address if not bill_address: bill_address = AddressBook(contact=customer) changed_location = False address_keys = bill_address.__dict__.keys() for field in address_keys: if (not changed_location) and field in ('state', 'country_id', 'city'): if getattr(bill_address, field) != data[field]: changed_location = True try: setattr(bill_address, field, data[field]) except KeyError: pass bill_address.is_default_billing = True copy_address = data['copy_address'] ship_address = customer.shipping_address if copy_address: # make sure we don't have any other default shipping address if ship_address and ship_address.id != bill_address.id: ship_address.delete() bill_address.is_default_shipping = True bill_address.save() if not copy_address: if not ship_address or ship_address.id == bill_address.id: ship_address = AddressBook() for field in address_keys: ship_field = 'ship_' + field if (not changed_location) and field in ('state', 'country_id', 'city'): if getattr(ship_address, field) != data[ship_field]: changed_location = True try: setattr(ship_address, field, data[ship_field]) except KeyError: pass ship_address.is_default_shipping = True ship_address.is_default_billing = False ship_address.contact = customer ship_address.save() if not customer.primary_phone: phone = PhoneNumber() phone.primary = True else: phone = customer.primary_phone phone.phone = data['phone'] phone.contact = customer phone.save() form_postsave.send(ContactInfoForm, object=customer, formdata=data, form=self) if changed_location: signals.satchmo_contact_location_changed.send(self, contact=customer) return customer.id
def save_contact(self, request, force_new_contact = False): log.debug("Saving contact") data = self.cleaned_data password = data['password1'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] allow_nickname = config_value('SHOP', 'ALLOW_NICKNAME_USERNAME') if allow_nickname and data['username']: username = data['username'] else: username = generate_id(first_name, last_name, email) verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: site = Site.objects.get_current() from registration.models import RegistrationProfile user = RegistrationProfile.objects.create_inactive_user( username, email, password, site) 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 = None if not force_new_contact: try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: pass if contact is None: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = ContactRole.objects.get(pk='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: username_field = getattr(User, "USERNAME_FIELD", 'username') if username_field == 'username': user = authenticate(username=username, password=password) else: user = authenticate(username=email, 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, force_new_contact = False): log.debug("Saving contact") data = self.cleaned_data password = data['password1'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] allow_nickname = config_value('SHOP', 'ALLOW_NICKNAME_USERNAME') if allow_nickname and data['username']: username = data['username'] else: username = generate_id(first_name, last_name, email) verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: site = Site.objects.get_current() from registration.models import RegistrationProfile # TODO: # In django-registration trunk this signature has changed. # Satchmo is going to stick with the latest release so I'm changing # this to work with 0.7 # When 0.8 comes out we're going to have to refactor to this: #user = RegistrationProfile.objects.create_inactive_user( # username, email, password, site) # See ticket #1028 where we checked in the above line prematurely user = RegistrationProfile.objects.create_inactive_user(username, password, email) 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 = None if not force_new_contact: try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: pass if contact is None: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = ContactRole.objects.get(pk='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_info(self, contact=None, **kwargs): """Save the contact info into the database. Checks to see if contact exists. If not, creates a contact and copies in the address and phone number.""" if not contact: customer = Contact() log.debug('creating new contact') else: customer = contact log.debug('Saving contact info for %s', contact) data = self.cleaned_data.copy() country = data['country'] if not isinstance(country, Country): country = Country.objects.get(pk=country) data['country'] = country data['country_id'] = country.id shipcountry = data['ship_country'] if not isinstance(shipcountry, Country): shipcountry = Country.objects.get(pk=shipcountry) data['ship_country'] = shipcountry data['ship_country_id'] = shipcountry.id organization_name = data.pop('organization', None) if organization_name: org = Organization.objects.by_name(organization_name, create=True) customer.organization = org else: # in case customer wants to remove organization name from their profile customer.organization = None for field in customer.__dict__.keys(): try: setattr(customer, field, data[field]) except KeyError: pass if not customer.role: customer.role = ContactRole.objects.get(pk='Customer') customer.save() # we need to make sure we don't blindly add new addresses # this isn't ideal, but until we have a way to manage addresses # this will force just the two addresses, shipping and billing # TODO: add address management like Amazon. bill_address = customer.billing_address if not bill_address: bill_address = AddressBook(contact=customer) changed_location = False address_keys = bill_address.__dict__.keys() for field in address_keys: if (not changed_location) and field in ('state', 'country_id', 'city'): if getattr(bill_address, field) != data[field]: changed_location = True try: setattr(bill_address, field, data[field]) except KeyError: pass bill_address.is_default_billing = True copy_address = data['copy_address'] ship_address = customer.shipping_address try: setattr(ship_address, "addressee",data.get('ship_addressee', "")) setattr(bill_address, "addressee",data.get('addressee', "")) except AttributeError: pass # If we are copying the address and one isn't in place for shipping # copy it if not getattr(ship_address, "addressee", False) and copy_address: try: ship_address.addressee = bill_address.addressee except AttributeError: pass # Make sure not to overwrite a custom ship to name if copy_address and getattr(ship_address, "addressee", "") == getattr(bill_address, "addressee", ""): # make sure we don't have any other default shipping address if ship_address and ship_address.id != bill_address.id: ship_address.delete() bill_address.is_default_shipping = True bill_address.save() # If we have different ship to and bill to names, preserve them if not copy_address or getattr(ship_address, "addressee", "") != getattr(bill_address, "addressee", ""): if not ship_address or ship_address.id == bill_address.id: ship_address = AddressBook() for field in address_keys: ship_field = 'ship_' + field if (not changed_location) and field in ('state', 'country_id', 'city'): if getattr(ship_address, field) != data[ship_field]: changed_location = True try: setattr(ship_address, field, data[ship_field]) except KeyError: pass ship_address.is_default_shipping = True ship_address.is_default_billing = False ship_address.contact = customer ship_address.save() if not customer.primary_phone: phone = PhoneNumber() phone.primary = True else: phone = customer.primary_phone phone.phone = data['phone'] phone.contact = customer phone.save() form_postsave.send(ContactInfoForm, object=customer, formdata=data, form=self) if changed_location: signals.satchmo_contact_location_changed.send(self, contact=customer) return customer.id
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: site = Site.objects.get_current() from registration.models import RegistrationProfile # TODO: # In django-registration trunk this signature has changed. # Satchmo is going to stick with the latest release so I'm changing # this to work with 0.7 # When 0.8 comes out we're going to have to refactor to this: #user = RegistrationProfile.objects.create_inactive_user( # username, email, password, site) # See ticket #1028 where we checked in the above line prematurely user = RegistrationProfile.objects.create_inactive_user( username, password, email) 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 = ContactRole.objects.get(pk='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, force_new_contact = False): log.debug("Saving contact") data = self.cleaned_data password = data['password1'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] allow_nickname = config_value('SHOP', 'ALLOW_NICKNAME_USERNAME') if allow_nickname and data['username']: username = data['username'] else: username = generate_id(first_name, last_name, email) verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: site = Site.objects.get_current() from registration.models import RegistrationProfile user = RegistrationProfile.objects.create_inactive_user( username, email, password, site) 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 = None if not force_new_contact: try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: pass if contact is None: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = ContactRole.objects.get(pk='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 complete_process(request, backend, *args, **kwargs): """Authentication complete process""" # pop redirect value before the session is trashed on login() redirect_value = request.session.get(REDIRECT_FIELD_NAME, '') user = auth_complete(request, backend, *args, **kwargs) if isinstance(user, HttpResponse): return user if not user and request.user.is_authenticated(): return HttpResponseRedirect(redirect_value) if user: if getattr(user, 'is_active', True): # catch is_new flag before login() might reset the instance is_new = getattr(user, 'is_new', False) login(request, user) # add cart ljj-2012-10-12 from satchmo_store.contact.models import Contact from satchmo_store.contact.models import ContactRole try: contact = Contact.objects.from_request(request) except Contact.DoesNotExist: contact = None if contact == None: contact = Contact(user=request.user) contact.first_name = request.user.username # set customer role as default role contact.role = ContactRole.objects.get(pk='Customer') contact.save() from satchmo_store.accounts.views import _assign_cart, _get_prev_cart from livesettings import config_value _assign_cart(request) if config_value('SHOP','PERSISTENT_CART'): _get_prev_cart(request) # user.social_user is the used UserSocialAuth instance defined # in authenticate process social_user = user.social_user if redirect_value: request.session[REDIRECT_FIELD_NAME] = redirect_value or \ DEFAULT_REDIRECT if setting('SOCIAL_AUTH_SESSION_EXPIRATION', True): # Set session expiration date if present and not disabled by # setting. Use last social-auth instance for current provider, # users can associate several accounts with a same provider. expiration = social_user.expiration_datetime() if expiration: try: request.session.set_expiry(expiration) except OverflowError: # Handle django time zone overflow, set default expiry. request.session.set_expiry(None) # store last login backend name in session key = setting('SOCIAL_AUTH_LAST_LOGIN', 'social_auth_last_login_backend') request.session[key] = social_user.provider # Remove possible redirect URL from session, if this is a new # account, send him to the new-users-page if defined. new_user_redirect = backend_setting(backend, 'SOCIAL_AUTH_NEW_USER_REDIRECT_URL') if new_user_redirect and is_new: url = new_user_redirect else: url = redirect_value or \ backend_setting(backend, 'SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \ DEFAULT_REDIRECT else: url = backend_setting(backend, 'SOCIAL_AUTH_INACTIVE_USER_URL', LOGIN_ERROR_URL) else: msg = setting('LOGIN_ERROR_MESSAGE', None) if msg: messages.error(request, msg) url = backend_setting(backend, 'LOGIN_ERROR_URL', LOGIN_ERROR_URL) return HttpResponseRedirect(url)
def save_info(self, contact=None, **kwargs): """Save the contact info into the database. Checks to see if contact exists. If not, creates a contact and copies in the address and phone number.""" if not contact: customer = Contact() log.debug('creating new contact') else: customer = contact log.debug('Saving contact info for %s', contact) data = self.cleaned_data.copy() country = data['country'] if not isinstance(country, Country): country = Country.objects.get(pk=country) data['country'] = country data['country_id'] = country.id shipcountry = data['ship_country'] if not isinstance(shipcountry, Country): shipcountry = Country.objects.get(pk=shipcountry) data['ship_country'] = shipcountry data['ship_country_id'] = shipcountry.id companyname = data.pop('company', None) if companyname: org = Organization.objects.by_name(companyname, create=True) customer.organization = org for field in customer.__dict__.keys(): try: setattr(customer, field, data[field]) except KeyError: pass if not customer.role: customer.role = "Customer" customer.save() # we need to make sure we don't blindly add new addresses # this isn't ideal, but until we have a way to manage addresses # this will force just the two addresses, shipping and billing # TODO: add address management like Amazon. bill_address = customer.billing_address if not bill_address: bill_address = AddressBook(contact=customer) changed_location = False address_keys = bill_address.__dict__.keys() for field in address_keys: if (not changed_location) and field in ('state', 'country', 'city'): if getattr(bill_address, field) != data[field]: changed_location = True try: setattr(bill_address, field, data[field]) except KeyError: pass bill_address.is_default_billing = True copy_address = data['copy_address'] ship_address = customer.shipping_address if copy_address: # make sure we don't have any other default shipping address if ship_address and ship_address.id != bill_address.id: ship_address.delete() bill_address.is_default_shipping = True bill_address.save() if not copy_address: if not ship_address or ship_address.id == bill_address.id: ship_address = AddressBook() for field in address_keys: if (not changed_location) and field in ('state', 'country', 'city'): if getattr(ship_address, field) != data[field]: changed_location = True try: setattr(ship_address, field, data['ship_' + field]) except KeyError: pass ship_address.is_default_shipping = True ship_address.is_default_billing = False ship_address.contact = customer ship_address.save() if not customer.primary_phone: phone = PhoneNumber() phone.primary = True else: phone = customer.primary_phone phone.phone = data['phone'] phone.contact = customer phone.save() signals.form_save.send(ContactInfoForm, object=customer, formdata=data, form=self) if changed_location: signals.satchmo_contact_location_changed.send(self, contact=customer) return customer.id