Example #1
0
def dev_signup(request):
   invalid_captcha = False
   if request.method == 'POST':
      form = SignupForm(request.POST)

      # talk to the reCAPTCHA service  
      response = captcha.submit(  
            request.POST.get('recaptcha_challenge_field'),  
            request.POST.get('recaptcha_response_field'),  
            reCAPTCHA_KEY,  
            request.META['REMOTE_ADDR'],)

      if form.is_valid() and response.is_valid:
         dev_name = form.cleaned_data['developer_name']
         organization = form.cleaned_data['organization']
         app_name = form.cleaned_data['application_name']
         email = form.cleaned_data['email']

         # Generate API key
         key_req = APIKey(application=app_name)
         key_req.organization = organization
         key_req.full_name = dev_name
         key_req.email = email
         key_req.key = generate_key()

         key_req.save()

         # Prepare email
         sender = 'Wild Stallions'
         message = ("Thank you for signing up for an API Key.\n\nYour Key: %s" % key_req.key)
         subject = "Geotagged Sensor Fusion API Key"
         recipient = [email]

         # Send email
         from django.core.mail import send_mail
         send_mail(subject, message, sender, recipient)

         return HttpResponseRedirect('/')
      elif not response.is_valid:
         invalid_captcha = True
   else:
      form = SignupForm()

   return render(request, 'api/devsignup.html', 
      {'form': form, 'captcha_flag': invalid_captcha}
   )