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:
|
except requests.exceptions.ConnectionError as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if r.status_code == 200:
|
if r.status_code != 200:
|
||||||
response = r.json()
|
print('HTTP error %i validating token:\n%s' % (r.status_code, r.content))
|
||||||
else:
|
return None
|
||||||
response = None
|
|
||||||
return response
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def validate_token():
|
def validate_token():
|
||||||
@@ -70,7 +70,9 @@ def validate_token():
|
|||||||
# to verify the validity of the token. We will get basic user info if
|
# 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.
|
# the user is authorized and we will make a new token.
|
||||||
validation = validate(token)
|
validation = validate(token)
|
||||||
if validation['status'] == 'success':
|
if validation is None or validation['status'] != 'success':
|
||||||
|
return None
|
||||||
|
|
||||||
users = app.data.driver.db['users']
|
users = app.data.driver.db['users']
|
||||||
email = validation['data']['user']['email']
|
email = validation['data']['user']['email']
|
||||||
db_user = users.find_one({'email': email})
|
db_user = users.find_one({'email': email})
|
||||||
@@ -125,8 +127,6 @@ def validate_token():
|
|||||||
groups=groups,
|
groups=groups,
|
||||||
token_expire_time=datetime.now() + timedelta(hours=1))
|
token_expire_time=datetime.now() + timedelta(hours=1))
|
||||||
#return token_data
|
#return token_data
|
||||||
else:
|
|
||||||
return None
|
|
||||||
else:
|
else:
|
||||||
users = app.data.driver.db['users']
|
users = app.data.driver.db['users']
|
||||||
db_user = users.find_one(db_token['user'])
|
db_user = users.find_one(db_token['user'])
|
||||||
@@ -136,5 +136,5 @@ def validate_token():
|
|||||||
groups=db_user['groups'],
|
groups=db_user['groups'],
|
||||||
token_expire_time=db_token['expire_time'])
|
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