From 08743b8100a2fcba8f0e4bd1aadb1435225ff615 Mon Sep 17 00:00:00 2001 From: ckosiegbu Date: Mon, 31 Jul 2017 02:06:23 +0100 Subject: [PATCH] Changes to OTP settings in System Settings --- .../system_settings/system_settings.json | 96 +++++++------------ frappe/twofactor.py | 11 +-- 2 files changed, 35 insertions(+), 72 deletions(-) diff --git a/frappe/core/doctype/system_settings/system_settings.json b/frappe/core/doctype/system_settings/system_settings.json index c1932a0ed0..e1bdaacd0b 100644 --- a/frappe/core/doctype/system_settings/system_settings.json +++ b/frappe/core/doctype/system_settings/system_settings.json @@ -714,7 +714,8 @@ "collapsible": 0, "columns": 0, "default": "0", - "fieldname": "enable_two_factor_auth", + "description": "If enabled, the password strength will be enforced based on the Minimum Password Score value. A value of 2 being medium strong and 4 being very strong.", + "fieldname": "enable_password_policy", "fieldtype": "Check", "hidden": 0, "ignore_user_permissions": 0, @@ -723,7 +724,7 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Enable Two Factor Authentication", + "label": "Enable Password Policy", "length": 0, "no_copy": 0, "permlevel": 0, @@ -744,10 +745,9 @@ "bold": 0, "collapsible": 0, "columns": 0, - "default": "OTP App", - "depends_on": "eval:doc.enable_two_factor_auth==1", - "description": "Choose authentication method to be used by all users", - "fieldname": "two_factor_method", + "default": "2", + "depends_on": "eval:doc.enable_password_policy==1", + "fieldname": "minimum_password_score", "fieldtype": "Select", "hidden": 0, "ignore_user_permissions": 0, @@ -756,10 +756,10 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Authentication method", + "label": "Minimum Password Score", "length": 0, "no_copy": 0, - "options": "OTP App\nSMS\nEmail", + "options": "2\n4", "permlevel": 0, "precision": "", "print_hide": 0, @@ -778,10 +778,9 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:doc.enable_two_factor_auth==1 && doc.two_factor_method == \"OTP App\" && doc.send_barcode_as_email==1", - "description": "Time in seconds to retain QR code image on server. Min:240", - "fieldname": "lifespan_barcode_image", - "fieldtype": "Int", + "default": "0", + "fieldname": "enable_two_factor_auth", + "fieldtype": "Check", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -789,7 +788,7 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Delete QR Code Image On server", + "label": "Enable Two Factor Authentication", "length": 0, "no_copy": 0, "permlevel": 0, @@ -810,9 +809,11 @@ "bold": 0, "collapsible": 0, "columns": 0, - "default": "Frappe Framework", - "fieldname": "otp_issuer_name", - "fieldtype": "Data", + "default": "OTP App", + "depends_on": "eval:doc.enable_two_factor_auth==1", + "description": "Choose authentication method to be used by all users", + "fieldname": "two_factor_method", + "fieldtype": "Select", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -820,10 +821,10 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "OTP Issuer Name", + "label": "Authentication method", "length": 0, "no_copy": 0, - "options": "", + "options": "OTP App\nSMS\nEmail", "permlevel": 0, "precision": "", "print_hide": 0, @@ -842,18 +843,18 @@ "bold": 0, "collapsible": 0, "columns": 0, - "default": "0", - "description": "If enabled, the password strength will be enforced based on the Minimum Password Score value. A value of 2 being medium strong and 4 being very strong.", - "fieldname": "enable_password_policy", - "fieldtype": "Check", + "depends_on": "eval:doc.enable_two_factor_auth==1 && doc.two_factor_method == \"OTP App\"", + "description": "Time in seconds to retain QR code image on server. Min:240", + "fieldname": "lifespan_qrcode_image", + "fieldtype": "Int", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, - "in_filter": 0, + "in_filter": 0, "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Enable Password Policy", + "label": "Delete QR Code Image On server", "length": 0, "no_copy": 0, "permlevel": 0, @@ -874,10 +875,10 @@ "bold": 0, "collapsible": 0, "columns": 0, - "default": "2", - "depends_on": "eval:doc.enable_password_policy==1", - "fieldname": "minimum_password_score", - "fieldtype": "Select", + "default": "Frappe Framework", + "depends_on": "eval:doc.enable_two_factor_auth==1", + "fieldname": "otp_issuer_name", + "fieldtype": "Data", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -885,10 +886,10 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Minimum Password Score", + "label": "OTP Issuer Name", "length": 0, "no_copy": 0, - "options": "2\n4", + "options": "", "permlevel": 0, "precision": "", "print_hide": 0, @@ -1024,37 +1025,6 @@ "set_only_once": 0, "unique": 0 }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "eval:doc.enable_two_factor_auth==1 && doc.two_factor_method == \"OTP App\"", - "fieldname": "send_barcode_as_email", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Send QR Code as email", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -1187,8 +1157,8 @@ "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2017-07-20 22:57:56.466867", - "modified_by": "Administrator", + "modified": "2017-07-31 02:05:48.674604", + "modified_by": "chude.osiegbu@manqala.com", "module": "Core", "name": "System Settings", "name_case": "", diff --git a/frappe/twofactor.py b/frappe/twofactor.py index 1c6b9c1053..ea4d418d0b 100644 --- a/frappe/twofactor.py +++ b/frappe/twofactor.py @@ -223,7 +223,7 @@ def get_link_for_qrcode(user,totp_uri): key = frappe.generate_hash(length=20) key_user = "{}_user".format(key) key_uri = "{}_uri".format(key) - lifespan = int(frappe.db.get_value('System Settings', 'System Settings', 'lifespan_barcode_image')) + lifespan = int(frappe.db.get_value('System Settings', 'System Settings', 'lifespan_qrcode_image')) if lifespan<=0: lifespan = 240 frappe.cache().set_value(key_uri,totp_uri,expires_in_sec=lifespan) @@ -276,13 +276,6 @@ def send_token_via_email(user, token, otp_secret, otp_issuer,subject=None,messag enqueue(method=frappe.sendmail, queue='short', timeout=300, event=None, async=True, job_name=None, now=False, **email_args) return True -def should_send_barcode_as_email(): - settings = frappe.get_doc('System Settings', 'System Settings') - if settings.two_factor_method and settings.send_barcode_as_email: - return True - return False - - def get_qr_svg_code(totp_uri): '''Get SVG code to display Qrcode for OTP.''' url = qrcreate(totp_uri) @@ -344,7 +337,7 @@ def should_remove_barcode_image(barcode): '''Check if it's time to delete barcode image from server. ''' if isinstance(barcode, basestring): barcode = frappe.get_doc('File',barcode) - lifespan = frappe.db.get_value('System Settings', 'System Settings', 'lifespan_barcode_image') + lifespan = frappe.db.get_value('System Settings', 'System Settings', 'lifespan_qrcode_image') if time_diff_in_seconds(get_datetime(),barcode.creation) > int(lifespan): return True return False