def fromClient(self, valuesCache, name, data):
"""
Reads a value from the client.
If this value is valid for this bone,
store this value and return None.
Otherwise our previous value is
left unchanged and an error-message
is returned.
:param name: Our name in the skeleton
:type name: String
:param data: *User-supplied* request-data
:type data: Dict
:returns: None or String
"""
if request.current.get().isDevServer: #We dont enforce captchas on dev server
return( None )
user = utils.getCurrentUser()
if user and "root" in user["access"]: # Don't bother trusted users with this (not supported by admin/vi anyways)
return( None )
if not "recaptcha_challenge_field" in data.keys() or not "recaptcha_response_field" in data.keys():
return( u"No Captcha given!" )
data = { "privatekey": self.privateKey,
"remoteip": request.current.get().request.remote_addr,
"challenge": data["recaptcha_challenge_field"],
"response": data["recaptcha_response_field"]
}
response = urlfetch.fetch( url="http://www.google.com/recaptcha/api/verify",
payload=urllib.urlencode( data ),
method=urlfetch.POST,
headers={"Content-Type": "application/x-www-form-urlencoded"} )
if str(response.content).strip().lower().startswith("true"):
return( None )
return( u"Invalid Captcha" )
评论列表
文章目录