From df6c5cd3e2ea6c750ae13debb533ea5062ebd52f Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 10 Jun 2021 16:27:59 +0530 Subject: [PATCH] Revert "fix: changed translate entries to javascript rather than python to resolve semgrep linter translate checks" This reverts commit 2b51641799c60ae9b16a1d29e4306d6c35e66070. --- frappe/templates/includes/login/login.js | 56 ++++++++++-------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/frappe/templates/includes/login/login.js b/frappe/templates/includes/login/login.js index 4bc17cb14b..93bf95bdb7 100644 --- a/frappe/templates/includes/login/login.js +++ b/frappe/templates/includes/login/login.js @@ -21,7 +21,7 @@ login.bind_events = function () { args.pwd = $("#login_password").val(); args.device = "desktop"; if (!args.usr || !args.pwd) { - frappe.msgprint(__("Both login and password required")); + frappe.msgprint('{{ _("Both login and password required") }}'); return false; } login.call(args); @@ -36,7 +36,7 @@ login.bind_events = function () { args.redirect_to = frappe.utils.sanitise_redirect(frappe.utils.get_url_arg("redirect-to")); 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'); + login.set_status('{{ _("Valid email and name required") }}', 'red'); return false; } login.call(args); @@ -49,7 +49,7 @@ login.bind_events = function () { args.cmd = "frappe.core.doctype.user.user.reset_password"; args.user = ($("#forgot_email").val() || "").trim(); if (!args.user) { - login.set_status(__("Valid Login id required."), 'red'); + login.set_status('{{ _("Valid Login id required.") }}', 'red'); return false; } login.call(args); @@ -60,10 +60,10 @@ login.bind_events = function () { var input = $($(this).attr("toggle")); if (input.attr("type") == "password") { input.attr("type", "text"); - $(this).text(__("Hide")) + $(this).text('{{ _("Hide") }}') } else { input.attr("type", "password"); - $(this).text(__("Show")) + $(this).text('{{ _("Show") }}') } }); @@ -75,7 +75,7 @@ login.bind_events = function () { args.pwd = $("#login_password").val(); args.device = "desktop"; if (!args.usr || !args.pwd) { - login.set_status(__("Both login and password required"), 'red'); + login.set_status('{{ _("Both login and password required") }}', 'red'); return false; } login.call(args); @@ -136,7 +136,7 @@ login.signup = function () { // Login login.call = function (args, callback) { - login.set_status(__("Verifying..."), 'blue'); + login.set_status('{{ _("Verifying...") }}', 'blue'); return frappe.call({ type: "POST", @@ -194,7 +194,7 @@ login.login_handlers = (function () { var login_handlers = { 200: function (data) { if (data.message == 'Logged In') { - login.set_status(__("Success"), 'green'); + login.set_status('{{ _("Success") }}', 'green'); window.location.href = frappe.utils.sanitise_redirect(frappe.utils.get_url_arg("redirect-to")) || data.home_page; } else if (data.message == 'Password Reset') { window.location.href = frappe.utils.sanitise_redirect(data.redirect_to); @@ -218,13 +218,13 @@ login.login_handlers = (function () { } } else if (window.location.hash === '#forgot') { if (data.message === 'not found') { - login.set_status(__("Not a valid user"), 'red'); + login.set_status('{{ _("Not a valid user") }}', 'red'); } else if (data.message == 'not allowed') { - login.set_status(__("Not Allowed"), 'red'); + login.set_status('{{ _("Not Allowed") }}', 'red'); } else if (data.message == 'disabled') { - login.set_status(__("Not Allowed: Disabled User"), 'red'); + login.set_status('{{ _("Not Allowed: Disabled User") }}', 'red'); } else { - login.set_status(__("Instructions Emailed"), 'green'); + login.set_status('{{ _("Instructions Emailed") }}', 'green'); } @@ -232,7 +232,7 @@ login.login_handlers = (function () { if (cint(data.message[0]) == 0) { login.set_status(data.message[1], 'red'); } else { - login.set_status(__("Success"), 'green'); + login.set_status('{{ _("Success") }}', 'green'); frappe.msgprint(data.message[1]) } //login.set_status(__(data.message), 'green'); @@ -240,7 +240,7 @@ login.login_handlers = (function () { //OTP verification if (data.verification && data.message != 'Logged In') { - login.set_status(__("Success"), 'green'); + login.set_status('{{ _("Success") }}', 'green'); document.cookie = "tmp_id=" + data.tmp_id; @@ -253,8 +253,8 @@ login.login_handlers = (function () { } } }, - 401: get_error_handler(__("Invalid Login. Try again.")), - 417: get_error_handler(__("Oops! Something went wrong")) + 401: get_error_handler('{{ _("Invalid Login. Try again.") }}'), + 417: get_error_handler('{{ _("Oops! Something went wrong") }}') }; return login_handlers; @@ -282,7 +282,7 @@ var verify_token = function (event) { args.otp = $("#login_token").val(); args.tmp_id = frappe.get_cookie('tmp_id'); if (!args.otp) { - frappe.msgprint(__("Login token required")); + frappe.msgprint('{{ _("Login token required") }}'); return false; } login.call(args); @@ -292,17 +292,9 @@ var verify_token = function (event) { var request_otp = function (r) { $('.login-content').empty(); - $('.login-content:visible').append($('
').attr({ 'id': 'twofactor_div' }).html( - '
\ -
\ - {{ _("Verification") }}\ -
\ -
\ - \ - \ -
')); - // add event handler for submit button - verify_token(); + $('.login-content:visible').append($('
').attr({ 'id': 'twofactor_div' }).html('{{ _("Verification") }}{{ _("Verify") }}')); + // add event handler for submit button + verify_token(); } var continue_otp_app = function (setup, qrcode) { @@ -310,11 +302,11 @@ var continue_otp_app = function (setup, qrcode) { var qrcode_div = $('
'); if (setup) { - direction = $('
').attr('id', 'qr_info').text(__("Enter Code displayed in OTP App.")); + direction = $('
').attr('id', 'qr_info').text('{{ _("Enter Code displayed in OTP App.") }}'); qrcode_div.append(direction); $('#otp_div').prepend(qrcode_div); } else { - direction = $('
').attr('id', 'qr_info').text(__("OTP setup using OTP App was not completed. Please contact Administrator.")); + direction = $('
').attr('id', 'qr_info').text('{{ _("OTP setup using OTP App was not completed. Please contact Administrator.") }}'); qrcode_div.append(direction); $('#otp_div').prepend(qrcode_div); } @@ -328,7 +320,7 @@ var continue_sms = function (setup, prompt) { sms_div.append(prompt) $('#otp_div').prepend(sms_div); } else { - direction = $('
').attr('id', 'qr_info').text(prompt || __("SMS was not sent. Please contact Administrator.")); + direction = $('
').attr('id', 'qr_info').text(prompt || '{{ _("SMS was not sent. Please contact Administrator.") }}'); sms_div.append(direction); $('#otp_div').prepend(sms_div) } @@ -342,7 +334,7 @@ var continue_email = function (setup, prompt) { email_div.append(prompt) $('#otp_div').prepend(email_div); } else { - var direction = $('
').attr('id', 'qr_info').text(prompt || __("Verification code email not sent. Please contact Administrator.")); + var direction = $('
').attr('id', 'qr_info').text(prompt || '{{ _("Verification code email not sent. Please contact Administrator.") }}'); email_div.append(direction); $('#otp_div').prepend(email_div); }