예제 #1
0
    def __call__(self, request):
        if request.path.startswith("/login") or request.path.startswith(
                "/register") or request.path.startswith(
                    "/admin/") or request.path.startswith(
                        "/token") or request.path.startswith('/api/logger'):
            response = self.get_response(request)
        elif self.validateToken(request):
            token_str = request.COOKIES['token']
            token = AuthToken.Get(token_str)
            pathsToIgnore = [
                "/",
                "/api/status",
                "/api/queue",
                "/api/playlist",
                "/api/playlist/all",
                "/api/users",
            ]
            #if request.path != "/api/status" and request.path != "/api/queue":
            if request.path not in pathsToIgnore:
                Logger.instance().Log("{} -> {}".format(
                    token.user.displayName, request.path))
            response = self.get_response(request)
        elif request.path.startswith("/api"):
            response = HttpResponse("Access denied!", status=401)
            response.delete_cookie('token')
        else:
            response = redirect('/login')
            response.delete_cookie('token')

        return response
예제 #2
0
 def process_response(self, request: HttpRequest,
                      response: HttpResponse) -> HttpResponse:
     """
     If request.session was modified, or if the configuration is to save the
     session every time, save the changes and set a session cookie or delete
     the session cookie if the session has been emptied.
     """
     try:
         accessed = request.session.accessed
         modified = request.session.modified
         empty = request.session.is_empty()
     except AttributeError:
         return response
     # Set SameSite based on whether or not the request is secure
     secure = SessionMiddleware.is_secure(request)
     same_site = "None" if secure else "Lax"
     # First check if we need to delete this cookie.
     # The session should be deleted only if the session is entirely empty.
     if settings.SESSION_COOKIE_NAME in request.COOKIES and empty:
         response.delete_cookie(
             settings.SESSION_COOKIE_NAME,
             path=settings.SESSION_COOKIE_PATH,
             domain=settings.SESSION_COOKIE_DOMAIN,
             samesite=same_site,
         )
         patch_vary_headers(response, ("Cookie", ))
     else:
         if accessed:
             patch_vary_headers(response, ("Cookie", ))
         if (modified or settings.SESSION_SAVE_EVERY_REQUEST) and not empty:
             if request.session.get_expire_at_browser_close():
                 max_age = None
                 expires = None
             else:
                 max_age = request.session.get_expiry_age()
                 expires_time = time() + max_age
                 expires = http_date(expires_time)
             # Save the session data and refresh the client cookie.
             # Skip session save for 500 responses, refs #3881.
             if response.status_code != 500:
                 try:
                     request.session.save()
                 except UpdateError:
                     raise SessionInterrupted(
                         "The request's session was deleted before the "
                         "request completed. The user may have logged "
                         "out in a concurrent request, for example.")
                 response.set_cookie(
                     settings.SESSION_COOKIE_NAME,
                     request.session.session_key,
                     max_age=max_age,
                     expires=expires,
                     domain=settings.SESSION_COOKIE_DOMAIN,
                     path=settings.SESSION_COOKIE_PATH,
                     secure=secure,
                     httponly=settings.SESSION_COOKIE_HTTPONLY or None,
                     samesite=same_site,
                 )
     return response
예제 #3
0
def setting_cookie(request):
    resp = HttpResponse()  # $ HttpResponse mimetype=text/html
    resp.set_cookie(
        "key", "value")  # $ CookieWrite CookieName="key" CookieValue="value"
    resp.set_cookie(
        key="key",
        value="value")  # $ CookieWrite CookieName="key" CookieValue="value"
    resp.headers[
        "Set-Cookie"] = "key2=value2"  # $ MISSING: CookieWrite CookieRawHeader="key2=value2"
    resp.cookies[
        "key3"] = "value3"  # $ CookieWrite CookieName="key3" CookieValue="value3"
    resp.delete_cookie("key4")  # $ CookieWrite CookieName="key4"
    resp.delete_cookie(key="key4")  # $ CookieWrite CookieName="key4"
    return resp
예제 #4
0
    def validation(self, request, *args, **kwargs):
        userId = get_user(request)
        response = HttpResponse(status=401)
        response.delete_cookie('jwt')
        if not userId:
            return response

        try:
            Usr.objects.raw(
                f'SELECT * FROM (SELECT * FROM USR WHERE USR_ID=\'{userId}\') WHERE ROWNUM=1;'
            )[0]
        except IndexError:
            return response
        else:
            return HttpResponse(status=200)
예제 #5
0
def index(request):
    response = HttpResponse('hello,xiaobai')
    response.set_cookie('best2','python3',max_age=3000)
    response.set_cookie('best5','python6',max_age=3000)

    cookie2 = request.COOKIES.get('best2')
    print(cookie2)
    cookie3 = response.delete_cookie('best2')

    return response
예제 #6
0
def delete_cookie(request):
    key = request.GET.get('key')
    response = HttpResponse("删除%s的cookie" % key)
    response.delete_cookie(key)
    return response
예제 #7
0
파일: views.py 프로젝트: heraldmatias/endes
 def post(self, request, *args, **kwargs):
     response = HttpResponse(json.dumps(self.save()), content_type="application/json")
     response.delete_cookie('vparte1')
     response.delete_cookie('vparte2')
     response.delete_cookie('vparte3')
     return response
예제 #8
0
 def unlogin(self):
     r=HttpResponse()
     r.delete_cookie("userlogin_username")
     r.write("<script>self.location='/index/index'</script>")
     return r
예제 #9
0
def delete_ck(request):
    rs = HttpResponse('删除cookie')
    rs.delete_cookie('name')
    return rs
예제 #10
0
def logout(req):
    resp = HttpResponse('logout')
    resp.delete_cookie("db_pf")
    del req.session['name']
    return resp
예제 #11
0
def logout(request):
    auth_logout(request)
    response = HttpResponse(json.dumps({'detail': 'Logged out'}))
    response.delete_cookie('csrftoken')
    response.delete_cookie('sessionid')
    return response
예제 #12
0
파일: views.py 프로젝트: ludechu/DJevn
def delcookie(request):
    """删除cookie"""
    res = HttpResponse()
    res.delete_cookie('ldc')
    return HttpResponse("cookie删除成功")
예제 #13
0
def logout(req):
    res = HttpResponse()
    res.delete_cookie('username')
    return res
예제 #14
0
def logout(request):
    print('enter in logout')
    response = HttpResponse({'response': 'fail'})
    response.delete_cookie('username')
    response.delete_cookie('type')
    return response
예제 #15
0
 def get(self, request):
     response = HttpResponse()
     response.delete_cookie('AccessToken')
     return response
예제 #16
0
 def logout(self, request, *args, **kwargs):
     response = HttpResponse(status=200)
     response.delete_cookie('jwt')
     return response