Skip to content

Commit

Permalink
fixed pep8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
giohappy committed Feb 4, 2019
1 parent 1a8f1f6 commit d20c9db
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 24 deletions.
3 changes: 0 additions & 3 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#
#########################################################################

import datetime
import math
import os
import re
Expand All @@ -36,7 +35,6 @@
from django.db import models
from django.core import serializers
from django.db.models import Q, signals
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
from django.conf import settings
Expand Down Expand Up @@ -74,7 +72,6 @@
set_session_token,
get_session_token,
remove_session_token)
from oauth2_provider.models import AccessToken

logger = logging.getLogger(__name__)

Expand Down
22 changes: 2 additions & 20 deletions geonode/base/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@
logger = logging.getLogger(__name__)


def make_token_expiration(seconds = 86400):
def make_token_expiration(seconds=86400):
_expire_seconds = getattr(settings, 'ACCESS_TOKEN_EXPIRE_SECONDS', seconds)
_expire_time = datetime.datetime.now(timezone.get_current_timezone())
_expire_delta = datetime.timedelta(seconds=_expire_seconds)
return _expire_time + _expire_delta


def is_old_token(token, seconds = 86400):
_expire_seconds = getattr(settings, 'ACCESS_TOKEN_EXPIRE_SECONDS', seconds)
_expire_time = datetime.datetime.now(timezone.get_current_timezone())
_expire_delta = datetime.timedelta(seconds=_expire_seconds)

token.expires < _expire_time


def create_auth_token(user, client="GeoServer"):
expires = make_token_expiration()
Application = get_application_model()
Expand Down Expand Up @@ -57,19 +49,11 @@ def get_or_create_token(user, client="GeoServer"):
application = get_application_model()
app = application.objects.get(name=client)

# Lets create a new one
token = generate_token()

# 1 day expiration time by default
_expire_seconds = getattr(settings, 'ACCESS_TOKEN_EXPIRE_SECONDS', 86400)
_expire_time = datetime.datetime.now(timezone.get_current_timezone())
_expire_delta = datetime.timedelta(seconds=_expire_seconds)

# Let's create the new AUTH TOKEN
existing_token = None
try:
existing_token = AccessToken.objects.filter(user=user, application=app).order_by('-expires').first()
if existing_token and is_old_token(existing_token):
if existing_token and existing_token.is_expired():
existing_token.delete()
existing_token = None
except BaseException:
Expand Down Expand Up @@ -133,5 +117,3 @@ def get_token_object_from_session(session):
def remove_session_token(session):
if 'access_token' in session:
del session['access_token']


1 change: 0 additions & 1 deletion geonode/proxy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import os
import re
import json
import base64
import shutil
import logging
import requests
Expand Down

0 comments on commit d20c9db

Please sign in to comment.