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. 3
      smart_service/transactions/doctype/variant_mapping/variant_mapping.py
  12. 35
      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
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _
import sys
sys.tracebacklimit=0
def execute(filters=None):
columns, data = [], []

4
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()

24
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)
}
}
})

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.login = {};
console.log = function () { };
console.warn = function () { };
console.error = function () { };
window.verify = {};
args = {}, capTotal = 0, capRandomNum1 = 0, capRandomNum2 = 0;
(!$('.loadingBlock').length) ? $('body').append('<div class="loadingBlock" style="display:none"><div class="gear"></div></div>') : '';
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('<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 () {
$(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');

2
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):

2
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):

2
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;
}

4
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",

3
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):

2
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):

3
smart_service/transactions/doctype/variant_mapping/variant_mapping.py

@ -5,7 +5,8 @@ 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):

35
smart_service/www/login.html

@ -6,7 +6,7 @@
<label class="form-label sr-only" for="login_email">{{ login_label or _("Email")}}</label>
<div class="email-field">
<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>
<svg class="field-icon email-icon" width="20" height="20" viewBox="0 0 20 20" fill="none"
@ -39,11 +39,22 @@
<div class="form-group">
<label class="form-label sr-only" for="login_captcha">{{ _("Captcha") }}</label>
<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" placeholder="Enter Captcha" required>
<input type="text" id="login_captcha" class="form-control txt-input-captcha" style="width:100%; right:15%"
placeholder="Enter Captcha" required>
<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 class="form-group" style="width:100%"> <span id="capRandomNum1" alt="captcha"></span> </div>
<!-- <p class="forgot-password-message"> -->
<!-- <a href="#forgot">{{ _("Forgot Password?") }}</a></p> -->
</div>
@ -77,7 +88,9 @@
<div class="text-center my-5">
<h4>{{ _("Javascript is disabled on your browser") }}</h4>
<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>
</noscript>
<section class='for-login'>
@ -101,8 +114,7 @@
<p class="text-muted login-divider">{{ _("or") }}</p>
</div>
</div>
<a href="#email"
class="btn btn-block btn-default btn-sm btn-login-option">
<a href="#email" class="btn btn-block btn-default btn-sm btn-login-option">
{{ _("Login With Email") }}</a>
</div>
{% else %}
@ -152,8 +164,8 @@
</div>
</div>
<div class="page-card-actions">
<button class="btn btn-sm btn-primary btn-block btn-signup"
type="submit">{{ _("Sign up") }}</button>
<button class="btn btn-sm btn-primary btn-block btn-signup" type="submit">{{ _("Sign up")
}}</button>
<p class="text-center sign-up-message">
<a href="#login" class="blue">{{ _("Have an account? Login") }}</a>
@ -163,7 +175,8 @@
{%- else -%}
<div class='page-card-head mb-2'>
<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>
{%- endif -%}
@ -194,8 +207,8 @@
</div>
</div>
<div class="page-card-actions">
<button class="btn btn-sm btn-primary btn-block btn-forgot"
type="submit">{{ _("Reset Password") }}</button>
<button class="btn btn-sm btn-primary btn-block btn-forgot" type="submit">{{ _("Reset Password")
}}</button>
<p class="text-center sign-up-message">
<a href="#login">{{ _("Back to Login") }}</a>
</p>

20
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

Loading…
Cancel
Save