captchaBone.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:server 作者: viur-framework 项目源码 文件源码
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" )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号