def verify_simple(environ, start_response): logging.debug(environ['tiddlyweb.query']) domain = get_domain(environ['HTTP_HOST']) try: redirect = environ['tiddlyweb.query']['recaptcha_redirect'][0] except (KeyError, IndexError): redirect = environ['HTTP_REFERER'].split('?', 1)[0] query = environ['tiddlyweb.query'] formErrors = [] name = query['name'][0] if name == '': formErrors.append('name') email = query['email'][0] if email == '': formErrors.append('email') challenge_field = environ['tiddlyweb.query']['recaptcha_challenge_field'][0] # logging.debug('challenge_field: '+challenge_field) response_field = environ['tiddlyweb.query']['recaptcha_response_field'][0] # logging.debug('response_field: '+response_field) private_key = "6Ld8HAgAAAAAAAyOgYXbOtqAD1yuTaOuwP8lpzX0" ip_addr = environ['REMOTE_ADDR'] # logging.debug('ip_addr: '+ip_addr) resp = captcha.submit(challenge_field, response_field, private_key, ip_addr) if not resp.is_valid: formErrors.append('recaptcha_response_field') if formErrors: params = [] for key, value in query.iteritems(): params.append(key+'='+url_quote(value[0])) redirect = str(redirect + '?formErrors='+','.join(formErrors)+'&'+'&'.join(params)) # JRL: not sure why I need to wrap this in str(), but if I don't, I get WSGI response header value %r is not a byte string else: try: emailAvox(query) redirect = redirect + '?success=1' except Exception as exc: logging.debug(exc) redirect = redirect + '?emailError=1' start_response('302 Found', [ ('Content-Type', 'text/html'), ('Location', redirect), ('Pragma', 'no-cache') ]) return []
def verify_simple(environ, start_response): logging.debug(environ["tiddlyweb.query"]) domain = get_domain(environ["HTTP_HOST"]) try: redirect = environ["tiddlyweb.query"]["recaptcha_redirect"][0] except (KeyError, IndexError): redirect = environ["HTTP_REFERER"].split("?", 1)[0] query = environ["tiddlyweb.query"] formErrors = [] name = query["name"][0] if name == "": formErrors.append("name") email = query["email"][0] if email == "": formErrors.append("email") challenge_field = environ["tiddlyweb.query"]["recaptcha_challenge_field"][0] # logging.debug('challenge_field: '+challenge_field) response_field = environ["tiddlyweb.query"]["recaptcha_response_field"][0] # logging.debug('response_field: '+response_field) private_key = "6Ld8HAgAAAAAAAyOgYXbOtqAD1yuTaOuwP8lpzX0" ip_addr = environ["REMOTE_ADDR"] # logging.debug('ip_addr: '+ip_addr) resp = captcha.submit(challenge_field, response_field, private_key, ip_addr) if not resp.is_valid: formErrors.append("recaptcha_response_field") if formErrors: params = [] for key, value in query.iteritems(): params.append(key + "=" + url_quote(value[0])) redirect = str( redirect + "?formErrors=" + ",".join(formErrors) + "&" + "&".join(params) ) # JRL: not sure why I need to wrap this in str(), but if I don't, I get WSGI response header value %r is not a byte string else: try: emailAvox(query) redirect = redirect + "?success=1" except Exception as exc: logging.debug(exc) redirect = redirect + "?emailError=1" start_response("302 Found", [("Content-Type", "text/html"), ("Location", redirect), ("Pragma", "no-cache")]) return []
def verify(environ, start_response): logging.debug(environ["tiddlyweb.query"]) domain = get_domain(environ["HTTP_HOST"]) try: redirect = environ["tiddlyweb.query"]["recaptcha_redirect"][0] except (KeyError, IndexError): redirect = environ["HTTP_REFERER"].split("?", 1)[0] commonVars = templating.common_vars(environ) responseVars = {} notSpam = False query = environ["tiddlyweb.query"] formErrors = [] if commonVars["usersign"]["name"] == "GUEST": # check personal info name = query["name"][0] if name == "": formErrors.append('"name"') email = query["email"][0] if email == "": formErrors.append('"email"') country = query["country"][0] if country == "": formErrors.append('"country"') # check captcha challenge_field = environ["tiddlyweb.query"]["recaptcha_challenge_field"][0] logging.debug("challenge_field: " + challenge_field) response_field = environ["tiddlyweb.query"]["recaptcha_response_field"][0] logging.debug("response_field: " + response_field) private_key = "6Ld8HAgAAAAAAAyOgYXbOtqAD1yuTaOuwP8lpzX0" ip_addr = environ["REMOTE_ADDR"] logging.debug("ip_addr: " + ip_addr) resp = captcha.submit(challenge_field, response_field, private_key, ip_addr) if resp.is_valid: responseVars["captcha"] = 1 notSpam = True else: responseVars["captcha"] = 0 else: notSpam = True # check request-specific conditions requestType = query["requestType"][0] if requestType == "suggest_new": legal_name = query["legal_name"][0] if legal_name == "": formErrors.append('"legal_name"') operational_country = query["operational_country"][0] operational_state = query["operational_state"][0] if operational_country == "": formErrors.append('"operational_country"') elif operational_country == "USA" and operational_state == "": formErrors.append('"operational_state"') # create the formErrors url parameter if there are any validForm = True formErrors = ",".join(formErrors) logging.debug("formErrors: " + formErrors) if formErrors != "": responseVars["formError"] = formErrors validForm = False # email Avox now we have determined the form is correct if notSpam and validForm: try: emailAvox(query, domain=domain) emailSuccess = 1 except KeyError as detail: # the hook for server-side validation, not being used yet (see formError usage above) responseVars["formError"] = detail.args[0] emailSuccess = 0 # JRL: I think the checking for captcha key is unneccessary because notSpam would be False if that key was present if ( notSpam == False or validForm == False or emailSuccess == 0 or (responseVars.has_key("captcha") and responseVars["captcha"] == 0) ): responseVars["success"] = 0 else: responseVars["success"] = 1 # create string containing sent variables queryVars = "" for parameter in query: queryVars = queryVars + "&" + parameter + "=" + url_quote(query[parameter][0], "") redirect = redirect + "?success=" + str(responseVars["success"]) if responseVars.has_key("captcha"): redirect = redirect + "&captcha=" + str(responseVars["captcha"]) if responseVars.has_key("formError"): redirect = redirect + "&formError=" + responseVars["formError"] redirect = redirect + str(queryVars) start_response("302 Found", [("Content-Type", "text/html"), ("Location", redirect), ("Pragma", "no-cache")]) return []
def verify(environ, start_response): logging.debug(environ['tiddlyweb.query']) domain = get_domain(environ['HTTP_HOST']) try: redirect = environ['tiddlyweb.query']['recaptcha_redirect'][0] except (KeyError, IndexError): redirect = environ['HTTP_REFERER'].split('?', 1)[0] commonVars = templating.common_vars(environ) responseVars = {} notSpam = False query = environ['tiddlyweb.query'] formErrors = [] if commonVars['usersign']['name'] == 'GUEST': # check personal info name = query['name'][0] if name == '': formErrors.append('"name"') email = query['email'][0] if email == '': formErrors.append('"email"') country = query['country'][0] if country == '': formErrors.append('"country"') # check captcha challenge_field = environ['tiddlyweb.query']['recaptcha_challenge_field'][0] logging.debug('challenge_field: '+challenge_field) response_field = environ['tiddlyweb.query']['recaptcha_response_field'][0] logging.debug('response_field: '+response_field) private_key = "6Ld8HAgAAAAAAAyOgYXbOtqAD1yuTaOuwP8lpzX0" ip_addr = environ['REMOTE_ADDR'] logging.debug('ip_addr: '+ip_addr) resp = captcha.submit(challenge_field, response_field, private_key, ip_addr) if resp.is_valid: responseVars['captcha'] = 1 notSpam = True else: responseVars['captcha'] = 0 else: notSpam = True #check request-specific conditions requestType = query['requestType'][0] if requestType == 'suggest_new': legal_name = query['legal_name'][0] if legal_name == '': formErrors.append('"legal_name"') operational_country = query['operational_country'][0] operational_state = query['operational_state'][0] if operational_country == '': formErrors.append('"operational_country"') elif operational_country == 'USA' and operational_state == '': formErrors.append('"operational_state"') #create the formErrors url parameter if there are any validForm = True formErrors = ','.join(formErrors) logging.debug('formErrors: '+formErrors) if formErrors != '': responseVars['formError'] = formErrors validForm = False # email Avox now we have determined the form is correct if notSpam and validForm: try: emailAvox(query,domain=domain) emailSuccess = 1 except KeyError as detail: # the hook for server-side validation, not being used yet (see formError usage above) responseVars['formError'] = detail.args[0] emailSuccess = 0 # JRL: I think the checking for captcha key is unneccessary because notSpam would be False if that key was present if notSpam == False or validForm == False or emailSuccess == 0 or (responseVars.has_key('captcha') and responseVars['captcha'] == 0): responseVars['success'] = 0 else: responseVars['success'] = 1 # create string containing sent variables queryVars = '' for parameter in query: queryVars = queryVars + '&' + parameter + '=' + url_quote(query[parameter][0].encode('utf-8'), '') redirect = redirect + '?success='+str(responseVars['success']) if responseVars.has_key('captcha'): redirect = redirect + '&captcha='+str(responseVars['captcha']) if responseVars.has_key('formError'): redirect = redirect +'&formError='+responseVars['formError'] redirect = redirect + str(queryVars) start_response('302 Found', [ ('Content-Type', 'text/html'), ('Location', redirect), ('Pragma', 'no-cache') ]) return []