Code simplification.
Mostly just returning quickly instead of setting a variable and returning that later in the code.
This commit is contained in:
@@ -41,11 +41,11 @@ def validate(token):
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
raise e
|
||||
|
||||
if r.status_code == 200:
|
||||
response = r.json()
|
||||
else:
|
||||
response = None
|
||||
return response
|
||||
if r.status_code != 200:
|
||||
print('HTTP error %i validating token:\n%s' % (r.status_code, r.content))
|
||||
return None
|
||||
|
||||
return r.json()
|
||||
|
||||
|
||||
def validate_token():
|
||||
@@ -70,7 +70,9 @@ def validate_token():
|
||||
# to verify the validity of the token. We will get basic user info if
|
||||
# the user is authorized and we will make a new token.
|
||||
validation = validate(token)
|
||||
if validation['status'] == 'success':
|
||||
if validation is None or validation['status'] != 'success':
|
||||
return None
|
||||
|
||||
users = app.data.driver.db['users']
|
||||
email = validation['data']['user']['email']
|
||||
db_user = users.find_one({'email': email})
|
||||
@@ -125,8 +127,6 @@ def validate_token():
|
||||
groups=groups,
|
||||
token_expire_time=datetime.now() + timedelta(hours=1))
|
||||
#return token_data
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
users = app.data.driver.db['users']
|
||||
db_user = users.find_one(db_token['user'])
|
||||
@@ -136,5 +136,5 @@ def validate_token():
|
||||
groups=db_user['groups'],
|
||||
token_expire_time=db_token['expire_time'])
|
||||
|
||||
setattr(g, 'current_user', current_user)
|
||||
g.current_user = current_user
|
||||
|
||||
|
Reference in New Issue
Block a user