def save(self, user_id): username = self.cleaned_data["username"].lower() address = self.cleaned_data["address1"].lower() u = User.objects.get(pk = user_id) u.username = username u.save() zipcode_obj = ZipCode.objects.get(code=self.cleaned_data["zip_code"]) phone = parse_phone_number(self.cleaned_data["phone"], zipcode_obj.city.region.country.code) customer = u.shoppleyuser.customer if (not customer.customerphone) or (not customer.customerphone.number==phone): #phone!= u.shoppleyuser.customer.phone: t = TxtTemplates() msg = t.render(TxtTemplates.templates["CUSTOMER"]["VERIFY_PHONE"], {}) sms_notify(phone, msg) c = u.shoppleyuser.customer c.address_1 = address p,created = CustomerPhone.objects.get_or_create(customer=c, defaults={"number":phone,}) if not created: p.number = phone p.save() c.daily_limit = self.cleaned_data["daily_limit"] c.zipcode = zipcode_obj c.save() c.set_location_from_address()
def offer_forward(request): """ :param offer_code: the code that is forwarded :param phones: list of phone numbers :param emails: list of emails :param note: a note for the friend """ data = {} u = request.user customer = u.shoppleyuser.customer offer_code = request.POST.get("offer_code", None) phones = request.POST.getlist("phones") emails = request.POST.getlist("emails") notes = request.POST.get("note", "") if offer_code and len(phones) > 0: if OfferCode.objects.filter(code__iexact=offer_code).exists(): original_code = OfferCode.objects.filter(code__iexact=offer_code)[0] offer = original_code.offer for phone in phones: new_code, random_pw = offer.gen_forward_offercode(original_code, phone) # text the user the user name and password customer_msg = _("%(customer)s forwarded you an offer!\n*from: %(merchant)s\n*title: %(description)s\n*expires: %(expiration)s\nCome redeem w/ [%(code)s]\n")%{ "customer": customer.phone, "merchant": offer.merchant, "expiration": pretty_date(original_code.expiration_time), "description": offer.description, "dollar_off": offer.dollar_off, "code": new_code.code, } #TODO: if the person do not mind receiving txt sms_notify(phone,customer_msg, SMS_DEBUG) if random_pw: new_customer = new_code.customer #print "created a customer for %s" % friend_num account_msg = _("Welcome to Shoppley! shoppley.com login info:\n-username: %(name)s\n-password: %(password)s\nTxt #help to %(shoppley)s to get started.")%{"name":new_customer.user.username,"password":random_pw, "shoppley": settings.SHOPPLEY_NUM} sms_notify(phone,account_msg, SMS_DEBUG) forwarder_msg= _('Offer by "%s" was forwarded to ') % offer_code forwarder_msg= forwarder_msg+ ''.join([str(i)+' ' for i in phones]) + "\nYou will receive points when they redeem their offers." data["confirm_msg"] = forwarder_msg data["result"] = 1 data["result_msg"] = "Offers have been forwarded." else: # ERROR: offer code is invalid data["result"] = -2 data["result_msg"] = "Offer code is invalid." else: # ERROR: no offer code POSTed data["result"] = -1 data["result_msg"] = "Offer code has not been specified in POST parameter." return JSONHttpResponse(data)
def save(self): # assign email as user name username = self.cleaned_data["username"].lower() email = self.cleaned_data["email"].lower() password = self.cleaned_data["password1"] if self.cleaned_data["confirmation_key"]: from friends.models import JoinInvitation # @@@ temporary fix for issue 93 try: join_invitation = JoinInvitation.objects.get(confirmation_key = self.cleaned_data["confirmation_key"]) confirmed = True except JoinInvitation.DoesNotExist: confirmed = False else: confirmed = False # @@@ clean up some of the repetition below -- DRY! if confirmed: if email == join_invitation.contact.email: new_user = User.objects.create_user(username, email, password) join_invitation.accept(new_user) # should go before creation of EmailAddress below new_user.message_set.create(message=ugettext(u"Your email address has already been verified")) # already verified so can just create EmailAddress(user=new_user, email=email, verified=True, primary=True).save() else: new_user = User.objects.create_user(username, "", password) join_invitation.accept(new_user) # should go before creation of EmailAddress below if email: new_user.message_set.create(message=ugettext(u"Confirmation email sent to %(email)s") % {'email': email}) EmailAddress.objects.add_email(new_user, email) else: new_user = User.objects.create_user(username, "", password) if email: new_user.message_set.create(message=ugettext(u"Confirmation email sent to %(email)s") % {'email': email}) EmailAddress.objects.add_email(new_user, email) if settings.ACCOUNT_EMAIL_VERIFICATION: new_user.is_active = False new_user.save() zipcode_obj = ZipCode.objects.get(code=self.cleaned_data["zip_code"]) phone = parse_phone_number(self.cleaned_data["phone"], zipcode_obj.city.region.country.code) t = TxtTemplates() msg = t.render(TxtTemplates.templates["CUSTOMER"]["VERIFY_PHONE"], {}) sms_notify(phone, msg) new_customer = Customer.objects.create(user=new_user, address_1=self.cleaned_data["address_1"], # address_2=self.cleaned_data["address_2"], # phone=phone, zipcode=zipcode_obj, verified=True, ) new_customer.set_location_from_address() p = CustomerPhone.objects.create(number=phone ,customer = new_customer) return username, password # required for authenticate()
def verify_phone(shoppleyUser, isVerify): t = TxtTemplates() if isVerify: shoppleyUser.verified_phone = shoppleyUser.VERIFIED_YES msg = t.render(TxtTemplates.templates["CUSTOMER"]["VERIFY_SUCCESS"], {}) else: shoppleyUser.verified_phone = shoppleyUser.VERIFIED_NO msg = t.render(TxtTemplates.templates["CUSTOMER"]["VERIFY_NO_SUCCESS"], {}) shoppleyUser.save() print "in verify_phone", shoppleyUser.verified_phone if shoppleyUser.is_merchant(): sms_notify(shoppleyUser.phone, msg) else: sms_notify(shoppleyUser.customer.customerphone.number, msg)
def notify(self, phone, msg): if SMS_DEBUG: print _("\"%(msg)s\" sent to %(phone)s") % { "msg": msg, "phone": phone, } else: return sms_notify(phone, msg)
def customer_signup(request, form_class=CustomerSignupForm, template_name="shoppleyuser/customer_signup.html", success_url=None): #success_url = "shoopleyuser/customer_landing_page.html" success_url = "/shoppleyuser/customer/signup-success" if success_url is None: success_url = get_default_redirect(request) if request.method == "POST": form = form_class(request.POST) if form.is_valid(): username, password = form.save() #from shoppleyuser.utils import parse_phone_number,sms_notify #signup_msg = _("Welcome to Shoppley! Txt \"#help\" for all commands. Enjoy!") #sms_notify(parse_phone_number(form.cleaned_data["phone"]),signup_msg) if settings.ACCOUNT_EMAIL_VERIFICATION: return render_to_response("account/verification_sent.html", { "email": form.cleaned_data["email"], }, context_instance=RequestContext(request)) else: user = authenticate(username=username, password=password) auth_login(request, user) request.user.message_set.create( message=_("Successfully logged in as %(username)s.") % { 'username': user.username }) from shoppleyuser.utils import parse_phone_number,sms_notify signup_msg =unicode(_("Welcome to Shoppley! Txt \"#help\" for all commands. Enjoy!")) #print signup_msg try : sms_notify(parse_phone_number(form.cleaned_data["phone"]),signup_msg) except ValidationError: pass return HttpResponseRedirect(success_url) else: form = form_class() return render_to_response(template_name, { "form": form, }, context_instance=RequestContext(request))
def notify(self, phone, msg): if DEBUG: print _("TXT: \"%(msg)s\" sent to %(phone)s") % {"msg":msg, "phone":phone,} else: return sms_notify(phone,msg)
def customer_register(email, username, zipcode, phone, password, address, method): data = {} # sanitize inputs if email is not None: email = check_email(email) if email is None: data["result"] = -1 data["result_msg"] = "Email address is used by another user." return data if zipcode is not None: zipcode = check_zipcode(zipcode) if zipcode is None: data["result"] = -2 data["result_msg"] = "Zip Code is invalid or not in the system." return data if phone is not None: phone = check_phone(phone) if phone is None: data["result"] = -3 data["result_msg"] = "Phone number is used by another user." return data if username is None: if email is not None: username = email elif phone is not None: username = phone else: data["result"] = -4 data["result_msg"] = "Either email address, phone number or username is required." return data is_random_password = False if password is None: s = string.lowercase + string.digits password = ''.join(random.sample(s,6)) is_random_password = True try: user = User.objects.create_user(username, "", password) user.save() except IntegrityError: data["result"] = -5 data["result_msg"] = "'" + username + "' is used by the other user." return data # create customer information c = Customer(user=user, zipcode=zipcode, verified=True) c.save() CustomerPhone.objects.create(customer=c, number = phone) c.set_location_from_address() num_merchants = c.count_merchants_within_miles() t = TxtTemplates() args = {"email": email, "number": num_merchants} if is_random_password: args["password"] = password, welcome_msg = t.render(TxtTemplates.templates["CUSTOMER"]["SIGNUP_SUCCESS"], args) else: welcome_msg = t.render(TxtTemplates.templates["CUSTOMER"]["SIGNUP_SUCCESS_NO_PASSWORD"], args) if email is not None: e = EmailAddress(user=user, email=email, verified=True, primary=True) e.save() send_mail('Welcome to Shoppley', welcome_msg, '*****@*****.**', [email], fail_silently=True) if phone is not None: if method == "SMS": sms_notify(phone, welcome_msg) else: # send verification sms verify_msg = t.render(TxtTemplates.templates["CUSTOMER"]["VERIFY_PHONE"], {}) sms_notify(phone, verify_msg) data["result"] = 1 data["result_msg"] = "User registered successfully." data["username"] = username data["password"] = password return data;