Browse Source

Token settings integrate into login

master
venkataakhil 1 year ago
parent
commit
3cd206f107
  1. 6
      smart_service/add_ons/doctype/token_settings/token_settings.json
  2. 6
      smart_service/add_ons/doctype/token_settings/token_settings.py
  3. 22
      smart_service/apis/app_user_login.py

6
smart_service/add_ons/doctype/token_settings/token_settings.json

@ -13,20 +13,20 @@
{
"description": "Token Expiry in Minutes e.g. 15",
"fieldname": "access_expiry_time",
"fieldtype": "Data",
"fieldtype": "Int",
"label": "Access Expiry Time"
},
{
"description": "Token Expiry in Hours e.g. 1",
"fieldname": "refresh_expiry_time",
"fieldtype": "Data",
"fieldtype": "Int",
"label": "Refresh Expiry Time"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-02-03 12:40:24.152626",
"modified": "2023-06-29 09:34:46.212738",
"modified_by": "Administrator",
"module": "Add Ons",
"name": "Token Settings",

6
smart_service/add_ons/doctype/token_settings/token_settings.py

@ -8,8 +8,4 @@ from frappe.model.document import Document
class TokenSettings(Document):
def validate(self):
if self.access_expiry_time > 60:
frappe.throw("Minutes should be less than 60")
if self.refresh_expiry_time > 24:
frappe.throw("Minutes should be less than 60")
pass

22
smart_service/apis/app_user_login.py

@ -918,8 +918,12 @@ def invalidate_token(refresh_token):
def update_tokens_in_doc(user_email, access, refresh):
access_exp_hours = 15 * 60
refresh_exp_hrs = 60 * 60 * 24
# access_exp_hours = 15 * 60
# refresh_exp_hrs = 60 * 60 * 24
token_settings = frappe.get_doc('Token Settings')
access_exp_hours = token_settings.access_expiry_time
refresh_exp_hrs = token_settings.refresh_expiry_time
user_token_details = {}
@ -938,8 +942,11 @@ def update_tokens_in_doc(user_email, access, refresh):
refresh_doc.access_token = encrypt(access)
refresh_doc.refresh_token = encrypt(refresh)
access_exp_time = datetime.now() + timedelta(seconds=access_exp_hours)
refresh_exp_time = datetime.now() + timedelta(seconds=refresh_exp_hrs)
# access_exp_time = datetime.now() + timedelta(seconds=access_exp_hours)
# refresh_exp_time = datetime.now() + timedelta(seconds=refresh_exp_hrs)
access_exp_time = datetime.now() + timedelta(minutes=access_exp_hours)
refresh_exp_time = datetime.now() + timedelta(hours=refresh_exp_hrs)
refresh_doc.access_expiry_time = access_exp_time
refresh_doc.refresh_expiry_time = refresh_exp_time
@ -990,8 +997,11 @@ 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)
token_settings = frappe.get_doc('Token Settings')
access_exp_hours = token_settings.access_expiry_time
# access_exp_hours = 15 * 60
access_exp_time = datetime.now() + timedelta(minutes=access_exp_hours)
frappe.set_user("Administrator")
doc_details = frappe.db.sql('''
SELECT * FROM `tabRefresh Token`;''', as_dict=1)

Loading…
Cancel
Save