def pricing(request): ctx = dict(title="Pricing") if request.method == 'POST': if 'phone' in request.POST: subject = "Someone wants to buy subscription for Onekloud CRM!" pricing_type = request.POST['pricing'].capitalize() body = "User wants to buy pricing '{type}'.".format( type=pricing_type) data = dict(email=request.POST['email'], phone=request.POST['phone'], body=body) html = mark_safe(render_to_string('pages/email.html', data)) recipients = ('*****@*****.**', '*****@*****.**') msg = EmailMessage(subject, html, settings.SUPPORT_EMAIL, recipients) msg.content_subtype = 'html' msg.send() messages.success(request, "Thank you! We will contact you very soon.") else: form = SignupForm(request.POST) if form.is_valid(): # Email settings. subject = "Free trial activation for Onekloud CRM" data = form.cleaned_data # With this hash we will check if passed data is valid. key = '{key}{email}{company}'.format( key=settings.ACTIVATION_SALT, email=data['email'], company=data['company']).encode('utf8') data['key'] = hashlib.md5(key).hexdigest() encdata = urllib.parse.urlencode(data) html = mark_safe( render_to_string('pages/activation_email.html', dict(params=encdata))) msg = EmailMessage( subject, html, settings.SUPPORT_EMAIL, [data['email']], headers={'Reply-To': settings.SUPPORT_EMAIL}) msg.content_subtype = 'html' msg.send() messages.success( request, "Thank you! We have sent you activation link to " "{email}.".format(email=data['email'])) else: messages.error(request, form.errors) else: ctx['signup_form'] = SignupForm() return render(request, 'pages/pricing.html', ctx)
def pricing(request): ctx = dict(title="Pricing") if request.method == 'POST': if 'phone' in request.POST: subject = "Someone wants to buy subscription for Onekloud CRM!" pricing_type = request.POST['pricing'].capitalize() body = "User wants to buy pricing '{type}'.".format( type=pricing_type) data = dict(email=request.POST['email'], phone=request.POST['phone'], body=body) html = mark_safe(render_to_string('pages/email.html', data)) recipients = ('*****@*****.**', '*****@*****.**') msg = EmailMessage(subject, html, settings.SUPPORT_EMAIL, recipients) msg.content_subtype = 'html' msg.send() messages.success( request, "Thank you! We will contact you very soon.") else: form = SignupForm(request.POST) if form.is_valid(): # Email settings. subject = "Free trial activation for Onekloud CRM" data = form.cleaned_data # With this hash we will check if passed data is valid. key = '{key}{email}{company}'.format( key=settings.ACTIVATION_SALT, email=data['email'], company=data['company']).encode('utf8') data['key'] = hashlib.md5(key).hexdigest() encdata = urllib.parse.urlencode(data) html = mark_safe( render_to_string('pages/activation_email.html', dict(params=encdata))) msg = EmailMessage( subject, html, settings.SUPPORT_EMAIL, [data['email']], headers={'Reply-To': settings.SUPPORT_EMAIL}) msg.content_subtype = 'html' msg.send() messages.success( request, "Thank you! We have sent you activation link to " "{email}.".format(email=data['email'])) else: messages.error(request, form.errors) else: ctx['signup_form'] = SignupForm() return render(request, 'pages/pricing.html', ctx)
def home(request): logger = logging.getLogger(__name__) ctx = dict() if request.method == 'POST': form = SignupForm(request.POST) if form.is_valid(): # Email settings. subject = "Free trial activation for Onekloud CRM" data = form.cleaned_data # With this hash we will check if passed data is valid. key = '{key}{email}{phone}{company}'.format( key=settings.ACTIVATION_SALT, email=data['email'], phone=data['phone'], company=data['company']).encode('utf8') data['key'] = hashlib.md5(key).hexdigest() encdata = urllib.parse.urlencode(data) html = mark_safe( render_to_string('pages/activation_email.html', dict(params=encdata))) msg = EmailMessage(subject, html, settings.SUPPORT_EMAIL, [data['email']], headers={'Reply-To': settings.SUPPORT_EMAIL}) msg.content_subtype = 'html' try: msg.send(fail_silently=False) except SMTPException as e: # Fallback: immediately authorize for Trial with no email # notification. logger.error(e) url = 'https://crm.onekloud.com/auth/try/' full_url = '{url}?{params}'.format(url=url, params=encdata) return redirect(full_url) else: messages.success( request, "Thank you! We have sent you activation link to " "{email}.".format(email=data['email'])) else: messages.error(request, "Your form contains errors.") else: ctx['form'] = SignupForm() return render(request, 'pages/home.html', ctx)
def home(request): logger = logging.getLogger(__name__) ctx = dict() if request.method == 'POST': form = SignupForm(request.POST) if form.is_valid(): # Email settings. subject = "Free trial activation for Onekloud CRM" data = form.cleaned_data # With this hash we will check if passed data is valid. key = '{key}{email}{phone}{company}'.format( key=settings.ACTIVATION_SALT, email=data['email'], phone=data['phone'], company=data['company']).encode('utf8') data['key'] = hashlib.md5(key).hexdigest() encdata = urllib.parse.urlencode(data) html = mark_safe(render_to_string('pages/activation_email.html', dict(params=encdata))) msg = EmailMessage( subject, html, settings.SUPPORT_EMAIL, [data['email']], headers={'Reply-To': settings.SUPPORT_EMAIL}) msg.content_subtype = 'html' try: msg.send(fail_silently=False) except SMTPException as e: # Fallback: immediately authorize for Trial with no email # notification. logger.error(e) url = 'https://crm.onekloud.com/auth/try/' full_url = '{url}?{params}'.format(url=url, params=encdata) return redirect(full_url) else: messages.success( request, "Thank you! We have sent you activation link to " "{email}.".format(email=data['email'])) else: messages.error(request, "Your form contains errors.") else: ctx['form'] = SignupForm() return render(request, 'pages/home.html', ctx)