當前位置: 首頁>>代碼示例>>Python>>正文


Python BaseResponse.set_cookie方法代碼示例

本文整理匯總了Python中werkzeug.wrappers.BaseResponse.set_cookie方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseResponse.set_cookie方法的具體用法?Python BaseResponse.set_cookie怎麽用?Python BaseResponse.set_cookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在werkzeug.wrappers.BaseResponse的用法示例。


在下文中一共展示了BaseResponse.set_cookie方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pin_auth

# 需要導入模塊: from werkzeug.wrappers import BaseResponse [as 別名]
# 或者: from werkzeug.wrappers.BaseResponse import set_cookie [as 別名]
    def pin_auth(self, request):
        """Authenticates with the pin."""
        exhausted = False
        auth = False
        if self.is_trusted(request.environ):
            auth = True
        elif self._failed_pin_auth > 10:
            exhausted = True
        else:
            entered_pin = request.args.get('pin')
            if entered_pin.strip().replace('-', '') == \
               self.pin.replace('-', ''):
                self._failed_pin_auth = 0
                auth = True
            else:
                time.sleep(self._failed_pin_auth > 5 and 5.0 or 0.5)
                self._failed_pin_auth += 1
                auth = False

        rv = Response(json.dumps({
            'auth': auth,
            'exhausted': exhausted,
        }), mimetype='application/json')
        if auth:
            rv.set_cookie(self.pin_cookie_name, str(int(time.time())),
                          httponly=True)
        return rv
開發者ID:JackLoveShen,項目名稱:werkzeug,代碼行數:29,代碼來源:__init__.py

示例2: pin_auth

# 需要導入模塊: from werkzeug.wrappers import BaseResponse [as 別名]
# 或者: from werkzeug.wrappers.BaseResponse import set_cookie [as 別名]
    def pin_auth(self, request):
        """Authenticates with the pin."""
        exhausted = False
        auth = False
        trust = self.check_pin_trust(request.environ)

        # If the trust return value is `None` it means that the cookie is
        # set but the stored pin hash value is bad.  This means that the
        # pin was changed.  In this case we count a bad auth and unset the
        # cookie.  This way it becomes harder to guess the cookie name
        # instead of the pin as we still count up failures.
        bad_cookie = False
        if trust is None:
            self._fail_pin_auth()
            bad_cookie = True

        # If we're trusted, we're authenticated.
        elif trust:
            auth = True

        # If we failed too many times, then we're locked out.
        elif self._failed_pin_auth > 10:
            exhausted = True

        # Otherwise go through pin based authentication
        else:
            entered_pin = request.args.get('pin')
            if entered_pin.strip().replace('-', '') == \
               self.pin.replace('-', ''):
                self._failed_pin_auth = 0
                auth = True
            else:
                self._fail_pin_auth()

        rv = Response(json.dumps({
            'auth': auth,
            'exhausted': exhausted,
        }), mimetype='application/json')
        if auth:
            rv.set_cookie(self.pin_cookie_name, '%s|%s' % (
                int(time.time()),
                hash_pin(self.pin)
            ), httponly=True)
        elif bad_cookie:
            rv.delete_cookie(self.pin_cookie_name)
        return rv
開發者ID:CityPulse,項目名稱:pickup-planner,代碼行數:48,代碼來源:__init__.py


注:本文中的werkzeug.wrappers.BaseResponse.set_cookie方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。