@ -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 = cap tchaNumGen ( ) ;
$ ( "#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 = cap tchaNumGen ( ) ;
$ ( "#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 = cap tchaNumGen ( ) ;
$ ( "#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 = cap tchaNumGen ( ) ;
$ ( "#login_captcha" ) . val ( '' ) ;
$ ( '.login-captcha-refresh' ) . css ( 'z-index' , '2' ) ;
$ ( '.toggle-password' ) . css ( 'z-index' , '2' ) ;