Browse Source

VAPT Points init

master
administrator 2 years ago
parent
commit
163b60b4da
  1. 2
      smart_service/add_ons/report/feedback_report/feedback_report.py
  2. 4
      smart_service/add_ons/report/file_structure/file_structure.py
  3. 24
      smart_service/custom_scripts/user.js
  4. 97
      smart_service/templates/includes/login/_login.js
  5. 2
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py
  6. 2
      smart_service/transactions/doctype/procedure/procedure.py
  7. 2
      smart_service/transactions/doctype/publish/publish.js
  8. 4
      smart_service/transactions/doctype/publish/publish.json
  9. 3
      smart_service/transactions/doctype/publish/publish.py
  10. 2
      smart_service/transactions/doctype/system_mapping/system_mapping.py
  11. 5
      smart_service/transactions/doctype/variant_mapping/variant_mapping.py
  12. 49
      smart_service/www/login.html
  13. 20
      smart_service/www/login.py

2
smart_service/add_ons/report/feedback_report/feedback_report.py

@ -5,6 +5,8 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint, getdate from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _ from frappe import msgprint, _
import sys
sys.tracebacklimit=0
def execute(filters=None): def execute(filters=None):
columns, data = [], [] columns, data = [], []

4
smart_service/add_ons/report/file_structure/file_structure.py

@ -5,8 +5,8 @@ import frappe
from frappe import _ from frappe import _
import datetime import datetime
from frappe.utils import now from frappe.utils import now
import sys
sys.tracebacklimit=0
def execute(filters=None): def execute(filters=None):
data = files_tree() data = files_tree()

24
smart_service/custom_scripts/user.js

@ -13,5 +13,29 @@ frappe.ui.form.on('User', {
}, },
new_password: function(frm){ new_password: function(frm){
frm.doc.pwd = frm.doc.new_password; 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)
}
} }
}) })

97
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.disable_signup = {{disable_signup and "true" or "false" }};
window.login = {}; window.login = {};
console.log = function () { };
console.warn = function () { };
console.error = function () { };
window.verify = {}; window.verify = {};
args = {}, capTotal = 0, capRandomNum1 = 0, capRandomNum2 = 0; args = {}, capTrue = '';
(!$('.loadingBlock').length) ? $('body').append('<div class="loadingBlock" style="display:none"><div class="gear"></div></div>') : ''; const randomAlphaNum = () => {
const rangeOfNumber = () => { var length = 6
let capRandomNum = Math.ceil(Math.random() * 10); var chars = '123456789123456789abcdefghijklmnpqrstuvwxyz'
if (capRandomNum.toString().length != 1) { // abcdefghijklmnopqrstuvwxyz
capRandomNum = rangeOfNumber(); // '01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
} var result = '';
return capRandomNum; for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
} }
const captchaNumGen = () => { const captchaNumGen = () => {
capRandomNum1 = rangeOfNumber(); alpha_num = randomAlphaNum();
capRandomNum2 = rangeOfNumber(); frappe.call({
$("#capRandomNum1").text(capRandomNum1); method: "smart_service.www.login.create_captcha_image",
$("#capRandomNum2").text(capRandomNum2); args: {
capTotal = Number(capRandomNum1) + Number(capRandomNum2); 'numbers': alpha_num,
},
callback: function (r) {
$("#captcha-img").remove()
$("#capRandomNum1").append('<img id="captcha-img" style="border-radius:10px;" src="data:image/png;base64, ' + r.message + '">');
}
})
return alpha_num
} }
captchaNumGen();
var capTrue = captchaNumGen();
login.bind_events = function () { login.bind_events = function () {
$(window).on("hashchange", function () { $(window).on("hashchange", function () {
login.route(); login.route();
@ -36,25 +47,44 @@ login.bind_events = function () {
$("button").css("cursor", "not-allowed"); $("button").css("cursor", "not-allowed");
$("body").css("cursor", "not-allowed"); $("body").css("cursor", "not-allowed");
login.set_status('{{ _("Connecting to Mahindra...") }}', 'blue'); login.set_status('{{ _("Connecting to Mahindra...") }}', 'blue');
// $('.loadingBlock').show();
$('.login-captcha-refresh').css('z-index', '-1'); $('.login-captcha-refresh').css('z-index', '-1');
$('.toggle-password').css('z-index', '-1'); $('.toggle-password').css('z-index', '-1');
args.cmd = "login"; args.cmd = "login";
args.usr = frappe.utils.xss_sanitise(($("#login_email").val() || "").trim()); args.usr = frappe.utils.xss_sanitise(($("#login_email").val() || "").trim());
let getPass = $("#login_password").val(); let getPass = $("#login_password").val();
let getCaptcha = Number($("#login_captcha").val()); let getCaptcha = $("#login_captcha").val();
if (capTotal !== getCaptcha) {
frappe.msgprint('{{ _("Please enter valid Captcha") }}'); if (capTrue !== getCaptcha) {
$("button").css("cursor", "pointer"); $("button").css("cursor", "pointer");
$("body").css("cursor", "default"); $("body").css("cursor", "default");
$('.login-captcha-refresh').css('z-index', '2'); $('.login-captcha-refresh').css('z-index', '2');
$('.toggle-password').css('z-index', '2'); $('.toggle-password').css('z-index', '2');
captchaNumGen(); capTrue = captchaNumGen();
$("#login_captcha").val(''); $("#login_captcha").val('');
login.set_status('{{ _("Invalid Captcha. Try Again.") }}', 'red'); login.set_status('{{ _("Invalid Captcha. Try Again.") }}', 'red');
return false; 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; return json;
} }
isSubmit = 1; isSubmit = 1;
args.pwd = getPass; // args.pwd = getPass;
args.device = "desktop"; // args.device = "desktop";
login.call(args); // console.log('actual'+args.usr)
// args.usr='SS-00001';
// args.pwd='test!123';
// login.call(args);
isSubmit = 0; isSubmit = 0;
$("button").css("cursor", "pointer"); $("button").css("cursor", "pointer");
$("body").css("cursor", "default"); $("body").css("cursor", "default");
@ -142,14 +175,8 @@ login.bind_events = function () {
$("body").css("cursor", "default"); $("body").css("cursor", "default");
$('.login-captcha-refresh').css('z-index', '2'); $('.login-captcha-refresh').css('z-index', '2');
$('.toggle-password').css('z-index', '2'); $('.toggle-password').css('z-index', '2');
return false; return false;
})();*/ })();*/
}); });
$(".form-signup").on("submit", function (event) { $(".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()); args.full_name = frappe.utils.xss_sanitise(($("#signup_fullname").val() || "").trim());
if (!args.email || !validate_email(args.email) || !args.full_name) { 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');
captchaNumGen(); capTrue = captchaNumGen();
$("#login_captcha").val(''); $("#login_captcha").val('');
return false; return false;
} }
@ -176,7 +203,7 @@ login.bind_events = function () {
args.user = ($("#forgot_email").val() || "").trim(); args.user = ($("#forgot_email").val() || "").trim();
if (!args.user) { if (!args.user) {
login.set_status('{{ _("Valid Login id required.") }}', 'red'); login.set_status('{{ _("Valid Login id required.") }}', 'red');
captchaNumGen(); capTrue = captchaNumGen();
$("#login_captcha").val(''); $("#login_captcha").val('');
return false; return false;
} }
@ -394,15 +421,15 @@ login.login_handlers = (function () {
// login.set_status('{{ _("User Disabled. Please Contact Admin.") }}', 'red'); // login.set_status('{{ _("User Disabled. Please Contact Admin.") }}', 'red');
login.set_status('{{ _("User Created.") }}', 'green'); login.set_status('{{ _("User Created.") }}', 'green');
frappe.show_alert({ frappe.show_alert({
message:__('Please wait for administrator approval.'), message: __('Please wait for administrator approval.'),
indicator:'yellow' indicator: 'yellow'
}, 10); }, 10);
} }
} }
}) })
} }
login.set_status('{{ _("Invalid Login. Try again.") }}', 'red'); login.set_status('{{ _("Invalid Login. Try again.") }}', 'red');
captchaNumGen(); capTrue = captchaNumGen();
$("#login_captcha").val(''); $("#login_captcha").val('');
$('.login-captcha-refresh').css('z-index', '2'); $('.login-captcha-refresh').css('z-index', '2');
$('.toggle-password').css('z-index', '2'); $('.toggle-password').css('z-index', '2');

2
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

@ -3,6 +3,8 @@
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
import sys
sys.tracebacklimit=0
class KilometerMapping(Document): class KilometerMapping(Document):
def onload(self): def onload(self):

2
smart_service/transactions/doctype/procedure/procedure.py

@ -5,6 +5,8 @@ import frappe
from frappe.model.document import Document from frappe.model.document import Document
import frappe,json import frappe,json
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
import sys
sys.tracebacklimit=0
class Procedure(Document): class Procedure(Document):
def validate(self): def validate(self):

2
smart_service/transactions/doctype/publish/publish.js

@ -239,7 +239,7 @@ frappe.ui.form.on('Publish', {
frappe.validated = false; 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.msgprint(__("No item selected to Publish"));
frappe.validated = false; frappe.validated = false;
} }

4
smart_service/transactions/doctype/publish/publish.json

@ -51,6 +51,7 @@
{ {
"fieldname": "release_description", "fieldname": "release_description",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"ignore_xss_filter": 1,
"label": "Publish Description", "label": "Publish Description",
"read_only_depends_on": "eval:doc.publish_type == \"Global\"", "read_only_depends_on": "eval:doc.publish_type == \"Global\"",
"reqd": 1 "reqd": 1
@ -90,6 +91,7 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "Vehicle", "label": "Vehicle",
"options": "Vehicle", "options": "Vehicle",
"reqd": 1,
"set_only_once": 1 "set_only_once": 1
}, },
{ {
@ -298,7 +300,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2022-05-31 14:54:57.123693", "modified": "2022-08-19 20:36:03.516687",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Transactions", "module": "Transactions",
"name": "Publish", "name": "Publish",

3
smart_service/transactions/doctype/publish/publish.py

@ -5,6 +5,9 @@ import frappe
from frappe.model.document import Document from frappe.model.document import Document
import json import json
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
from html import unescape
import sys
sys.tracebacklimit=0
class Publish(Document): class Publish(Document):
def validate(self): def validate(self):

2
smart_service/transactions/doctype/system_mapping/system_mapping.py

@ -4,6 +4,8 @@
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
import sys
sys.tracebacklimit=0
class SystemMapping(Document): class SystemMapping(Document):

5
smart_service/transactions/doctype/variant_mapping/variant_mapping.py

@ -5,11 +5,12 @@ import frappe
from frappe.model.document import Document from frappe.model.document import Document
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
import sys
sys.tracebacklimit=0
class VariantMapping(Document): class VariantMapping(Document):
def validate(self): 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) 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 x in assets:
for y in self.get("assets"): for y in self.get("assets"):

49
smart_service/www/login.html

@ -6,7 +6,7 @@
<label class="form-label sr-only" for="login_email">{{ login_label or _("Email")}}</label> <label class="form-label sr-only" for="login_email">{{ login_label or _("Email")}}</label>
<div class="email-field"> <div class="email-field">
<input type="text" id="login_email" class="form-control" <input type="text" id="login_email" class="form-control"
placeholder="{% if login_name_placeholder %}{{ login_name_placeholder }}{% else %}{{ _('jane@example.com') }}{% endif %}" placeholder="{% if login_name_placeholder %}{{ login_name_placeholder }}{% else %}{{ _('Username / user@example.com') }}{% endif %}"
required autofocus> required autofocus>
<svg class="field-icon email-icon" width="20" height="20" viewBox="0 0 20 20" fill="none" <svg class="field-icon email-icon" width="20" height="20" viewBox="0 0 20 20" fill="none"
@ -39,13 +39,24 @@
<div class="form-group"> <div class="form-group">
<label class="form-label sr-only" for="login_captcha">{{ _("Captcha") }}</label> <label class="form-label sr-only" for="login_captcha">{{ _("Captcha") }}</label>
<div class="password-field"> <div class="password-field">
<div class="field-icon captcha-txt" style="width:30%" > <span id="capRandomNum1"></span> + <span id=capRandomNum2></span></div> <input type="text" id="login_captcha" class="form-control txt-input-captcha" style="width:100%; right:15%"
<input type="text" id="login_captcha" class="form-control txt-input-captcha" placeholder="Enter Captcha" required> placeholder="Enter Captcha" required>
<span class="login-captcha-refresh text-muted" onclick="captchaNumGen()">{{ _('Refresh') }}</span> <svg class="field-icon password-icon" xmlns="http://www.w3.org/2000/svg" width="20" height="16.08"
viewBox="0 0 15.42 16.08">
<g id="Group_73" data-name="Group 73" transform="translate(12098 -9453.67)">
<rect id="Rectangle_45" data-name="Rectangle 45" width="15.42" height="16.08"
transform="translate(-12098 9453.67)" fill="none" />
<path id="settings_backup_restore_FILL0_wght400_GRAD0_opsz48"
d="M13.71,15.316a1.609,1.609,0,1,1,1.135-.471A1.547,1.547,0,0,1,13.71,15.316Zm0,6.1A7.417,7.417,0,0,1,8.249,19.16,7.471,7.471,0,0,1,6,13.689H7.285A6.231,6.231,0,0,0,9.159,18.25a6.178,6.178,0,0,0,4.551,1.885,6.4,6.4,0,0,0,6.425-6.425A6.4,6.4,0,0,0,13.71,7.285a6.011,6.011,0,0,0-2.763.653A7.365,7.365,0,0,0,8.7,9.705h2.227V10.99H6.471V6.535H7.756v2.27a8.089,8.089,0,0,1,2.677-2.067,7.676,7.676,0,0,1,6.286-.128A7.746,7.746,0,0,1,20.81,10.7a7.722,7.722,0,0,1,0,6.018,7.746,7.746,0,0,1-4.091,4.091A7.459,7.459,0,0,1,13.71,21.42Z"
transform="translate(-12104 9448)" fill="#74808b" />
</g>
</svg>
<span class="login-captcha-refresh text-muted" onclick="captchaNumGen()">{{ _('Refresh') }}</span>
</div> </div>
</div> </div>
<div class="form-group" style="width:100%"> <span id="capRandomNum1" alt="captcha"></span> </div>
<!-- <p class="forgot-password-message"> --> <!-- <p class="forgot-password-message"> -->
<!-- <a href="#forgot">{{ _("Forgot Password?") }}</a></p> --> <!-- <a href="#forgot">{{ _("Forgot Password?") }}</a></p> -->
</div> </div>
<div class="page-card-actions"> <div class="page-card-actions">
@ -77,7 +88,9 @@
<div class="text-center my-5"> <div class="text-center my-5">
<h4>{{ _("Javascript is disabled on your browser") }}</h4> <h4>{{ _("Javascript is disabled on your browser") }}</h4>
<p class="text-muted"> <p class="text-muted">
{{ _("You need to enable JavaScript for your app to work.") }}<br>{{ _("To enable it follow the instructions in the following link: {0}").format("<a href='https://enable-javascript.com/'>enable-javascript.com</a></p>") }} {{ _("You need to enable JavaScript for your app to work.") }}<br>{{ _("To enable it follow the
instructions in the following link: {0}").format("<a
href='https://enable-javascript.com/'>enable-javascript.com</a></p>") }}
</div> </div>
</noscript> </noscript>
<section class='for-login'> <section class='for-login'>
@ -93,7 +106,7 @@
<a href="{{ provider.auth_url }}" <a href="{{ provider.auth_url }}"
class="btn btn-block btn-default btn-sm btn-login-option btn-{{ provider.name }}"> class="btn btn-block btn-default btn-sm btn-login-option btn-{{ provider.name }}">
{% if provider.icon %} {% if provider.icon %}
{{ provider.icon }} {{ provider.icon }}
{% endif %} {% endif %}
{{ _("Login With {0}").format(provider.provider_name) }}</a> {{ _("Login With {0}").format(provider.provider_name) }}</a>
</div> </div>
@ -101,12 +114,11 @@
<p class="text-muted login-divider">{{ _("or") }}</p> <p class="text-muted login-divider">{{ _("or") }}</p>
</div> </div>
</div> </div>
<a href="#email" <a href="#email" class="btn btn-block btn-default btn-sm btn-login-option">
class="btn btn-block btn-default btn-sm btn-login-option"> {{ _("Login With Email") }}</a>
{{ _("Login With Email") }}</a>
</div> </div>
{% else %} {% else %}
{{ email_login_body() }} {{ email_login_body() }}
{%- endif -%} {%- endif -%}
</form> </form>
</div> </div>
@ -123,7 +135,7 @@
<div class="login-content page-card"> <div class="login-content page-card">
{{ logo_section() }} {{ logo_section() }}
<form class="form-signin form-login" role="form"> <form class="form-signin form-login" role="form">
{{ email_login_body() }} {{ email_login_body() }}
</form> </form>
</div> </div>
{%- if not disable_signup -%} {%- if not disable_signup -%}
@ -152,8 +164,8 @@
</div> </div>
</div> </div>
<div class="page-card-actions"> <div class="page-card-actions">
<button class="btn btn-sm btn-primary btn-block btn-signup" <button class="btn btn-sm btn-primary btn-block btn-signup" type="submit">{{ _("Sign up")
type="submit">{{ _("Sign up") }}</button> }}</button>
<p class="text-center sign-up-message"> <p class="text-center sign-up-message">
<a href="#login" class="blue">{{ _("Have an account? Login") }}</a> <a href="#login" class="blue">{{ _("Have an account? Login") }}</a>
@ -163,7 +175,8 @@
{%- else -%} {%- else -%}
<div class='page-card-head mb-2'> <div class='page-card-head mb-2'>
<span class='indicator gray'>{{_("Signup Disabled")}}</span> <span class='indicator gray'>{{_("Signup Disabled")}}</span>
<p class="text-muted text-normal sign-up-message mt-1 mb-8">{{_("Signups have been disabled for this website.")}}</p> <p class="text-muted text-normal sign-up-message mt-1 mb-8">{{_("Signups have been disabled for this
website.")}}</p>
<div><a href='/' class='btn btn-primary btn-md'>{{ _("Home") }}</a></div> <div><a href='/' class='btn btn-primary btn-md'>{{ _("Home") }}</a></div>
</div> </div>
{%- endif -%} {%- endif -%}
@ -194,8 +207,8 @@
</div> </div>
</div> </div>
<div class="page-card-actions"> <div class="page-card-actions">
<button class="btn btn-sm btn-primary btn-block btn-forgot" <button class="btn btn-sm btn-primary btn-block btn-forgot" type="submit">{{ _("Reset Password")
type="submit">{{ _("Reset Password") }}</button> }}</button>
<p class="text-center sign-up-message"> <p class="text-center sign-up-message">
<a href="#login">{{ _("Back to Login") }}</a> <a href="#login">{{ _("Back to Login") }}</a>
</p> </p>
@ -211,4 +224,4 @@
<script>{% include "templates/includes/login/_login.js" %}</script> <script>{% include "templates/includes/login/_login.js" %}</script>
{% endblock %} {% endblock %}
{% block sidebar %}{% endblock %} {% block sidebar %}{% endblock %}

20
smart_service/www/login.py

@ -127,9 +127,6 @@ def login_via_token(login_token):
Temp = form.getvalue('password') 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) ###This method called from login.js for password validation(CMS login task)
@frappe.whitelist(allow_guest=True) @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 from frappe.sessions import clear_sessions
clear_sessions(user=user, keep_current=True, force=True) 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

Loading…
Cancel
Save