mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-14 02:28:23 +00:00
chg: [ail users] save last api usage
This commit is contained in:
parent
612c8dbce1
commit
e7f1b4fd6c
2 changed files with 14 additions and 3 deletions
|
@ -73,6 +73,7 @@ def authenticate_user(token, ip_address):
|
||||||
return {'status': 'error', 'reason': 'Malformed Authentication String'}, 400
|
return {'status': 'error', 'reason': 'Malformed Authentication String'}, 400
|
||||||
|
|
||||||
if is_valid_token(token):
|
if is_valid_token(token):
|
||||||
|
ail_users.update_user_last_seen_api(get_user_from_token(token))
|
||||||
return True, 200
|
return True, 200
|
||||||
# Failed Login
|
# Failed Login
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -283,6 +283,12 @@ def get_user_last_login(user_id):
|
||||||
def get_user_last_seen(user_id):
|
def get_user_last_seen(user_id):
|
||||||
return r_serv_db.hget(f'ail:user:metadata:{user_id}', 'last_seen')
|
return r_serv_db.hget(f'ail:user:metadata:{user_id}', 'last_seen')
|
||||||
|
|
||||||
|
def get_user_last_seen_api(user_id):
|
||||||
|
return r_serv_db.hget(f'ail:user:metadata:{user_id}', 'last_seen_api')
|
||||||
|
|
||||||
|
def update_user_last_seen_api(user_id):
|
||||||
|
r_serv_db.hset(f'ail:user:metadata:{user_id}', 'last_seen_api', datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
|
|
||||||
def get_disabled_users():
|
def get_disabled_users():
|
||||||
return r_serv_db.smembers(f'ail:users:disabled')
|
return r_serv_db.smembers(f'ail:users:disabled')
|
||||||
|
|
||||||
|
@ -366,8 +372,7 @@ def edit_user(user_id, password_hash, chg_passwd=False, otp=True):
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
# TODO USER: - Creation Date
|
# TODO USER:
|
||||||
# - Last API Usage
|
|
||||||
# - Organisation ???
|
# - Organisation ???
|
||||||
# - Disabled / Lock
|
# - Disabled / Lock
|
||||||
|
|
||||||
|
@ -400,6 +405,9 @@ class AILUser(UserMixin):
|
||||||
def update_last_seen(self):
|
def update_last_seen(self):
|
||||||
r_serv_db.hset(f'ail:user:metadata:{self.user_id}', 'last_seen', datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
|
r_serv_db.hset(f'ail:user:metadata:{self.user_id}', 'last_seen', datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
|
|
||||||
|
def update_last_seen_api(self):
|
||||||
|
update_user_last_seen_api(self.user_id)
|
||||||
|
|
||||||
def update_last_login(self):
|
def update_last_login(self):
|
||||||
r_serv_db.hset(f'ail:user:metadata:{self.user_id}', 'last_login', datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
|
r_serv_db.hset(f'ail:user:metadata:{self.user_id}', 'last_login', datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
|
|
||||||
|
@ -415,6 +423,8 @@ class AILUser(UserMixin):
|
||||||
meta['last_login'] = get_user_last_login(self.user_id)
|
meta['last_login'] = get_user_last_login(self.user_id)
|
||||||
if 'last_seen' in options:
|
if 'last_seen' in options:
|
||||||
meta['last_seen'] = get_user_last_seen(self.user_id)
|
meta['last_seen'] = get_user_last_seen(self.user_id)
|
||||||
|
if 'last_seen_api' in options:
|
||||||
|
meta['last_seen_api'] = get_user_last_seen_api(self.user_id)
|
||||||
if 'api_key' in options: # TODO add option to censor key
|
if 'api_key' in options: # TODO add option to censor key
|
||||||
meta['api_key'] = self.get_api_key()
|
meta['api_key'] = self.get_api_key()
|
||||||
if 'role' in options:
|
if 'role' in options:
|
||||||
|
@ -543,7 +553,7 @@ class AILUser(UserMixin):
|
||||||
|
|
||||||
def api_get_users_meta():
|
def api_get_users_meta():
|
||||||
meta = {'users': []}
|
meta = {'users': []}
|
||||||
options = {'api_key', 'creator', 'created_at', 'is_logged', 'last_edit', 'last_login', 'last_seen', 'role', '2fa', 'otp_setup'}
|
options = {'api_key', 'creator', 'created_at', 'is_logged', 'last_edit', 'last_login', 'last_seen', 'last_seen_api', 'role', '2fa', 'otp_setup'}
|
||||||
for user_id in get_users():
|
for user_id in get_users():
|
||||||
user = AILUser(user_id)
|
user = AILUser(user_id)
|
||||||
meta['users'].append(user.get_meta(options=options))
|
meta['users'].append(user.get_meta(options=options))
|
||||||
|
|
Loading…
Reference in a new issue