Browse Source

User token deactivation

master
venkataakhil 2 years ago
parent
commit
feb9f00515
  1. 14
      smart_service/apis/app_user_login.py

14
smart_service/apis/app_user_login.py

@ -850,10 +850,9 @@ def generate_refresh_token():
""" For Refresh API """
@frappe.whitelist(allow_guest=1, methods=['POST'])
def refresh_token(refresh_token):
""" For Refresh API """
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
@ -983,20 +982,23 @@ def deactivate_tokens():
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
access_exp_hours = 15 * 60
access_exp_time = datetime.now() + timedelta(seconds=access_exp_hours)
frappe.set_user("Administrator")
doc_details = frappe.db.sql('''
SELECT * FROM `tabRefresh Token`;''', as_dict=1)
try:
cur_time = datetime.now()
for d in doc_details:
if cur_time < d['access_expiry_time']:
if d['access_expiry_time'] < cur_time:
doc_value = frappe.get_doc('Refresh Token', d['name'])
doc_value.access_token = encrypt(generate_keys(d['user']))
doc_value.access_expiry_time = access_exp_time
doc_value.save()
if cur_time < d['refresh_expiry_time'] > cur_time:
# frappe.delete_doc('Refresh Token', d['name'])
pass
if d['refresh_expiry_time'] < cur_time:
frappe.delete_doc('Refresh Token', d['name'])
return True
except Exception as e:

Loading…
Cancel
Save