@ -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 = cap tchaNumGen ( ) ;
$ ( "#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 = cap tchaNumGen ( ) ;
$ ( "#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 = cap tchaNumGen ( ) ;
$ ( "#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 = cap tchaNumGen ( ) ;
$ ( "#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' ) ;