finished ##218
This commit is contained in:
parent
0d1c116da7
commit
39095af891
|
@ -53,13 +53,13 @@ class AccesTokenController(metaclass=Singleton):
|
|||
"""
|
||||
LOGGER.info("Verify AccessToken with token: {} and group: {}".format(token, group))
|
||||
for accToken in self.tokenList:
|
||||
LOGGER.debug("Check is token {} same as in AccessToken {}".format(token, accToken))
|
||||
if accToken == token:
|
||||
LOGGER.debug("AccessToken is {}".format(accToken))
|
||||
endTime = accToken.timestamp + timedelta(seconds=self.lifetime)
|
||||
endTime = accToken.timestamp + timedelta(seconds=accToken.lifetime)
|
||||
now = datetime.now()
|
||||
LOGGER.debug("Check if AccessToken's Endtime {} is bigger then now {}".format(endTime, now))
|
||||
if now <= endTime:
|
||||
LOGGER.debug("Check is token {} same as in AccessToken {}".format(token, accToken))
|
||||
if accToken == token:
|
||||
self.checkBar(accToken.user)
|
||||
LOGGER.debug("Check if AccesToken {} has same group {}".format(accToken, group))
|
||||
if self.isSameGroup(accToken, group):
|
||||
|
@ -67,11 +67,14 @@ class AccesTokenController(metaclass=Singleton):
|
|||
LOGGER.info("Found AccessToken {} with token: {} and group: {}".format(accToken, token, group))
|
||||
return accToken
|
||||
else:
|
||||
LOGGER.debug("AccessToken {} is no longer valid and will removed".format(accToken))
|
||||
self.tokenList.remove(accToken)
|
||||
self.deleteAccessToken(accToken)
|
||||
LOGGER.info("Found no valid AccessToken with token: {} and group: {}".format(token, group))
|
||||
return False
|
||||
|
||||
def deleteAccessToken(self, accToken):
|
||||
LOGGER.debug("AccessToken {} is no longer valid and will removed".format(accToken))
|
||||
self.tokenList.remove(accToken)
|
||||
|
||||
def createAccesToken(self, user, ldap_conn):
|
||||
""" Create an AccessToken
|
||||
|
||||
|
@ -87,7 +90,7 @@ class AccesTokenController(metaclass=Singleton):
|
|||
now = datetime.ctime(datetime.now())
|
||||
token = hashlib.md5((now + user.dn).encode('utf-8')).hexdigest()
|
||||
self.checkBar(user)
|
||||
accToken = AccessToken(user, token, ldap_conn, datetime.now())
|
||||
accToken = AccessToken(user, token, ldap_conn, self.lifetime, datetime.now())
|
||||
LOGGER.debug("Add AccessToken {} to current Tokens".format(accToken))
|
||||
self.tokenList.append(accToken)
|
||||
LOGGER.info("Finished create AccessToken {} with Token {}".format(accToken, token))
|
||||
|
|
|
@ -17,7 +17,7 @@ class AccessToken():
|
|||
token = None
|
||||
ldap_conn = None
|
||||
|
||||
def __init__(self, user, token, ldap_conn, timestamp=datetime.now()):
|
||||
def __init__(self, user, token, ldap_conn, lifetime, timestamp=datetime.now()):
|
||||
""" Initialize Class AccessToken
|
||||
|
||||
No more to say.
|
||||
|
@ -30,6 +30,7 @@ class AccessToken():
|
|||
LOGGER.debug("Initialize AccessToken")
|
||||
self.user = user
|
||||
self.timestamp = timestamp
|
||||
self.lifetime = lifetime
|
||||
self.token = token
|
||||
self.ldap_conn = ldap_conn
|
||||
|
||||
|
|
|
@ -77,6 +77,43 @@ def _getUsers(**kwargs):
|
|||
except Exception as err:
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@app.route("/getLifeTime", methods=['GET'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER])
|
||||
def _getLifeTime(**kwargs):
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
return jsonify({"value": accToken.lifetime})
|
||||
except Exception as err:
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@app.route("/saveLifeTime", methods=['POST'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER])
|
||||
def _saveLifeTime(**kwargs):
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
|
||||
data = request.get_json()
|
||||
lifetime = data['value']
|
||||
accToken.lifetime = lifetime
|
||||
accToken.updateTimestamp()
|
||||
|
||||
return jsonify({"value": accToken.lifetime})
|
||||
except Exception as err:
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@app.route("/logout", methods=['GET'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER])
|
||||
def _logout(**kwargs):
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
accesTokenController.deleteAccessToken(accToken)
|
||||
return jsonify({"ok": "ok"})
|
||||
except Exception as err:
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@app.route("/login", methods=['POST'])
|
||||
def _login():
|
||||
""" Login User
|
||||
|
|
Loading…
Reference in New Issue