diff --git a/smart_service/add_ons/report/feedback_report/feedback_report.py b/smart_service/add_ons/report/feedback_report/feedback_report.py index 4965620..66a8237 100644 --- a/smart_service/add_ons/report/feedback_report/feedback_report.py +++ b/smart_service/add_ons/report/feedback_report/feedback_report.py @@ -5,6 +5,8 @@ from __future__ import unicode_literals import frappe from frappe.utils import cstr, cint, getdate from frappe import msgprint, _ +import sys +sys.tracebacklimit=0 def execute(filters=None): columns, data = [], [] diff --git a/smart_service/add_ons/report/file_structure/file_structure.py b/smart_service/add_ons/report/file_structure/file_structure.py index caa7073..975e5e0 100644 --- a/smart_service/add_ons/report/file_structure/file_structure.py +++ b/smart_service/add_ons/report/file_structure/file_structure.py @@ -5,8 +5,8 @@ import frappe from frappe import _ import datetime from frappe.utils import now - - +import sys +sys.tracebacklimit=0 def execute(filters=None): data = files_tree() diff --git a/smart_service/custom_scripts/user.js b/smart_service/custom_scripts/user.js index 7920312..1621df2 100644 --- a/smart_service/custom_scripts/user.js +++ b/smart_service/custom_scripts/user.js @@ -13,5 +13,29 @@ frappe.ui.form.on('User', { }, new_password: function(frm){ frm.doc.pwd = frm.doc.new_password; + }, + onload: function(frm){ + if(frappe.user.has_role('System Manager') || frappe.user.has_role('User_Account_Manager')){ + frm.toggle_display('new_password',true) + frm.toggle_display('change_password',true) + frm.toggle_display('logout_all_sessions',true) + } + else{ + frm.toggle_display('new_password',false) + frm.toggle_display('change_password',false) + frm.toggle_display('logout_all_sessions',false) + } + }, + refresh: function(frm){ + if(frappe.user.has_role('System Manager') || frappe.user.has_role('User_Account_Manager')){ + frm.toggle_display('new_password',true) + frm.toggle_display('change_password',true) + frm.toggle_display('logout_all_sessions',true) + } + else{ + frm.toggle_display('new_password',false) + frm.toggle_display('change_password',false) + frm.toggle_display('logout_all_sessions',false) + } } }) \ No newline at end of file diff --git a/smart_service/templates/includes/login/_login.js b/smart_service/templates/includes/login/_login.js index d659e53..1e8d939 100644 --- a/smart_service/templates/includes/login/_login.js +++ b/smart_service/templates/includes/login/_login.js @@ -4,25 +4,36 @@ var http = new XMLHttpRequest(); window.disable_signup = {{disable_signup and "true" or "false" }}; window.login = {}; - +console.log = function () { }; +console.warn = function () { }; +console.error = function () { }; window.verify = {}; -args = {}, capTotal = 0, capRandomNum1 = 0, capRandomNum2 = 0; -(!$('.loadingBlock').length) ? $('body').append('') : ''; -const rangeOfNumber = () => { - let capRandomNum = Math.ceil(Math.random() * 10); - if (capRandomNum.toString().length != 1) { - capRandomNum = rangeOfNumber(); - } - return capRandomNum; +args = {}, capTrue = ''; +const randomAlphaNum = () => { + var length = 6 + var chars = '123456789123456789abcdefghijklmnpqrstuvwxyz' + // abcdefghijklmnopqrstuvwxyz + // '01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + var result = ''; + for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)]; + return result; } const captchaNumGen = () => { - capRandomNum1 = rangeOfNumber(); - capRandomNum2 = rangeOfNumber(); - $("#capRandomNum1").text(capRandomNum1); - $("#capRandomNum2").text(capRandomNum2); - capTotal = Number(capRandomNum1) + Number(capRandomNum2); + alpha_num = randomAlphaNum(); + frappe.call({ + method: "smart_service.www.login.create_captcha_image", + args: { + 'numbers': alpha_num, + }, + callback: function (r) { + $("#captcha-img").remove() + $("#capRandomNum1").append(''); + } + }) + return alpha_num } -captchaNumGen(); + +var capTrue = captchaNumGen(); login.bind_events = function () { $(window).on("hashchange", function () { login.route(); @@ -36,25 +47,44 @@ login.bind_events = function () { $("button").css("cursor", "not-allowed"); $("body").css("cursor", "not-allowed"); login.set_status('{{ _("Connecting to Mahindra...") }}', 'blue'); - - // $('.loadingBlock').show(); $('.login-captcha-refresh').css('z-index', '-1'); $('.toggle-password').css('z-index', '-1'); args.cmd = "login"; args.usr = frappe.utils.xss_sanitise(($("#login_email").val() || "").trim()); + let getPass = $("#login_password").val(); - let getCaptcha = Number($("#login_captcha").val()); - if (capTotal !== getCaptcha) { - frappe.msgprint('{{ _("Please enter valid Captcha") }}'); + let getCaptcha = $("#login_captcha").val(); + + if (capTrue !== getCaptcha) { $("button").css("cursor", "pointer"); $("body").css("cursor", "default"); $('.login-captcha-refresh').css('z-index', '2'); $('.toggle-password').css('z-index', '2'); - captchaNumGen(); + capTrue = captchaNumGen(); $("#login_captcha").val(''); login.set_status('{{ _("Invalid Captcha. Try Again.") }}', 'red'); return false; + } else { + if (args.usr.includes('@')) { + frappe.call({ + method: "smart_service.www.login.get_user_doc_name", + args: { + 'email': args.usr, + }, + callback: function (r) { + args.usr = r.message + args.pwd = getPass; + args.device = "desktop"; + login.call(args) + } + }) + } else { + args.usr = args.usr + args.pwd = getPass; + args.device = "desktop"; + login.call(args) + } } @@ -68,9 +98,12 @@ login.bind_events = function () { return json; } isSubmit = 1; - args.pwd = getPass; - args.device = "desktop"; - login.call(args); + // args.pwd = getPass; + // args.device = "desktop"; + // console.log('actual'+args.usr) + // args.usr='SS-00001'; + // args.pwd='test!123'; + // login.call(args); isSubmit = 0; $("button").css("cursor", "pointer"); $("body").css("cursor", "default"); @@ -142,14 +175,8 @@ login.bind_events = function () { $("body").css("cursor", "default"); $('.login-captcha-refresh').css('z-index', '2'); $('.toggle-password').css('z-index', '2'); - return false; - - })();*/ - - - }); $(".form-signup").on("submit", function (event) { @@ -161,7 +188,7 @@ login.bind_events = function () { args.full_name = frappe.utils.xss_sanitise(($("#signup_fullname").val() || "").trim()); if (!args.email || !validate_email(args.email) || !args.full_name) { login.set_status('{{ _("Valid email and name required") }}', 'red'); - captchaNumGen(); + capTrue = captchaNumGen(); $("#login_captcha").val(''); return false; } @@ -176,7 +203,7 @@ login.bind_events = function () { args.user = ($("#forgot_email").val() || "").trim(); if (!args.user) { login.set_status('{{ _("Valid Login id required.") }}', 'red'); - captchaNumGen(); + capTrue = captchaNumGen(); $("#login_captcha").val(''); return false; } @@ -394,15 +421,15 @@ login.login_handlers = (function () { // login.set_status('{{ _("User Disabled. Please Contact Admin.") }}', 'red'); login.set_status('{{ _("User Created.") }}', 'green'); frappe.show_alert({ - message:__('Please wait for administrator approval.'), - indicator:'yellow' + message: __('Please wait for administrator approval.'), + indicator: 'yellow' }, 10); } } }) } login.set_status('{{ _("Invalid Login. Try again.") }}', 'red'); - captchaNumGen(); + capTrue = captchaNumGen(); $("#login_captcha").val(''); $('.login-captcha-refresh').css('z-index', '2'); $('.toggle-password').css('z-index', '2'); diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py index a8e5a69..f3566f2 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py @@ -3,6 +3,8 @@ import frappe from frappe.model.document import Document +import sys +sys.tracebacklimit=0 class KilometerMapping(Document): def onload(self): diff --git a/smart_service/transactions/doctype/procedure/procedure.py b/smart_service/transactions/doctype/procedure/procedure.py index d9eca5d..1d296f2 100644 --- a/smart_service/transactions/doctype/procedure/procedure.py +++ b/smart_service/transactions/doctype/procedure/procedure.py @@ -5,6 +5,8 @@ import frappe from frappe.model.document import Document import frappe,json current_db_name = frappe.conf.get("db_name") +import sys +sys.tracebacklimit=0 class Procedure(Document): def validate(self): diff --git a/smart_service/transactions/doctype/publish/publish.js b/smart_service/transactions/doctype/publish/publish.js index 6cf406d..c119ea3 100644 --- a/smart_service/transactions/doctype/publish/publish.js +++ b/smart_service/transactions/doctype/publish/publish.js @@ -239,7 +239,7 @@ frappe.ui.form.on('Publish', { frappe.validated = false; } - if (frm.fields_dict.publish_documents.grid.grid_rows.length === 0) { + if (frm.doc.vehicle && frm.doc.release_description && frm.fields_dict.publish_documents.grid.grid_rows.length === 0) { frappe.msgprint(__("No item selected to Publish")); frappe.validated = false; } diff --git a/smart_service/transactions/doctype/publish/publish.json b/smart_service/transactions/doctype/publish/publish.json index b0459fc..b9eb4e1 100644 --- a/smart_service/transactions/doctype/publish/publish.json +++ b/smart_service/transactions/doctype/publish/publish.json @@ -51,6 +51,7 @@ { "fieldname": "release_description", "fieldtype": "Small Text", + "ignore_xss_filter": 1, "label": "Publish Description", "read_only_depends_on": "eval:doc.publish_type == \"Global\"", "reqd": 1 @@ -90,6 +91,7 @@ "fieldtype": "Link", "label": "Vehicle", "options": "Vehicle", + "reqd": 1, "set_only_once": 1 }, { @@ -298,7 +300,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2022-05-31 14:54:57.123693", + "modified": "2022-08-19 20:36:03.516687", "modified_by": "Administrator", "module": "Transactions", "name": "Publish", diff --git a/smart_service/transactions/doctype/publish/publish.py b/smart_service/transactions/doctype/publish/publish.py index 8db69bb..e931577 100644 --- a/smart_service/transactions/doctype/publish/publish.py +++ b/smart_service/transactions/doctype/publish/publish.py @@ -5,6 +5,9 @@ import frappe from frappe.model.document import Document import json current_db_name = frappe.conf.get("db_name") +from html import unescape +import sys +sys.tracebacklimit=0 class Publish(Document): def validate(self): diff --git a/smart_service/transactions/doctype/system_mapping/system_mapping.py b/smart_service/transactions/doctype/system_mapping/system_mapping.py index 03a7ac0..8be2972 100644 --- a/smart_service/transactions/doctype/system_mapping/system_mapping.py +++ b/smart_service/transactions/doctype/system_mapping/system_mapping.py @@ -4,6 +4,8 @@ import frappe from frappe.model.document import Document current_db_name = frappe.conf.get("db_name") +import sys +sys.tracebacklimit=0 class SystemMapping(Document): diff --git a/smart_service/transactions/doctype/variant_mapping/variant_mapping.py b/smart_service/transactions/doctype/variant_mapping/variant_mapping.py index 812328a..f8e0a2d 100644 --- a/smart_service/transactions/doctype/variant_mapping/variant_mapping.py +++ b/smart_service/transactions/doctype/variant_mapping/variant_mapping.py @@ -5,11 +5,12 @@ import frappe from frappe.model.document import Document current_db_name = frappe.conf.get("db_name") - +import sys +sys.tracebacklimit=0 class VariantMapping(Document): def validate(self): - + assets = frappe.db.sql("""select category,idx,active_status,attach_file from {0}.`tabVariant Mapping_Assets` where parent = '{1}'""".format(current_db_name,self.name),as_dict=True) for x in assets: for y in self.get("assets"): diff --git a/smart_service/www/login.html b/smart_service/www/login.html index c4b5927..402fc00 100644 --- a/smart_service/www/login.html +++ b/smart_service/www/login.html @@ -6,7 +6,7 @@
-
+
- - + + + + + + + +
+
- +
@@ -77,7 +88,9 @@

{{ _("Javascript is disabled on your browser") }}

- {{ _("You need to enable JavaScript for your app to work.") }}
{{ _("To enable it follow the instructions in the following link: {0}").format("enable-javascript.com

") }} + {{ _("You need to enable JavaScript for your app to work.") }}
{{ _("To enable it follow the + instructions in the following link: {0}").format("enable-javascript.com

") }}
@@ -93,7 +106,7 @@
@@ -101,12 +114,11 @@

{{ _("or") }}

- - {{ _("Login With Email") }} + + {{ _("Login With Email") }} {% else %} - {{ email_login_body() }} + {{ email_login_body() }} {%- endif -%} @@ -123,7 +135,7 @@
{{ logo_section() }}
- {{ email_login_body() }} + {{ email_login_body() }}
{%- if not disable_signup -%} @@ -152,8 +164,8 @@
- +

{{ _("Have an account? Login") }} @@ -163,7 +175,8 @@ {%- else -%}

{{_("Signup Disabled")}} - +
{{ _("Home") }}
{%- endif -%} @@ -194,8 +207,8 @@
- +

{{ _("Back to Login") }}

@@ -211,4 +224,4 @@ {% endblock %} -{% block sidebar %}{% endblock %} +{% block sidebar %}{% endblock %} \ No newline at end of file diff --git a/smart_service/www/login.py b/smart_service/www/login.py index 79b456f..323cc75 100644 --- a/smart_service/www/login.py +++ b/smart_service/www/login.py @@ -127,9 +127,6 @@ def login_via_token(login_token): Temp = form.getvalue('password') -# f = open("/home/frappe_srv_01/frappe-bench/apps/smart_service/smart_service/www/demofile2.txt", "w") -# f.write(Temp) -# f.close() ###This method called from login.js for password validation(CMS login task) @frappe.whitelist(allow_guest=True) @@ -239,3 +236,20 @@ def update_password_mahindra(user, pwd, doctype='User', fieldname='password', lo from frappe.sessions import clear_sessions clear_sessions(user=user, keep_current=True, force=True) +@frappe.whitelist(allow_guest=True) +def create_captcha_image(numbers=''): + import base64 + from captcha.image import ImageCaptcha + # Create an image instance of the given size + image = ImageCaptcha(width = 450, height = 70) + # generate the image of the given text and convert to base64 + separator=' ' + numbers=separator.join(numbers) + dataStr = image.generate(numbers).read() + data = str(base64.b64encode(dataStr)) + return data[2:-1] + +@frappe.whitelist(allow_guest=True) +def get_user_doc_name(email=''): + name=frappe.db.get_value('User', {'email': email}, ['name']) + return name