Browse Source

captcha issue update

master
administrator 2 years ago
parent
commit
6edb38dd6c
  1. 24
      smart_service/overrides/overrides/override_file.py
  2. 129
      smart_service/templates/includes/login/_login.js

24
smart_service/overrides/overrides/override_file.py

@ -1,7 +1,7 @@
from __future__ import unicode_literals
import frappe, json
import json
from frappe.utils import cstr, flt, cint
from frappe.utils import cstr, flt, cint, random_string
def validate(doc=None,method=None):
data = ['.jpg', '.png','.mp4', '.docx','.xls', '.pdf','.tiff','.ppt','.m4v','.doc','.pps','.pptx']
file_name = doc.file_name
@ -17,12 +17,26 @@ def check_captcha(captcha_input, uid1):
validate_captcha = frappe.get_doc('Captcha Validation', {'uid': uid1})
except:
return 'Not Found'
if captcha_input == validate_captcha.captcha_text:
return True
if validate_captcha.captcha_text:
return generate_hash(validate_captcha.captcha_text)
else:
return False
@frappe.whitelist(allow_guest=True)
def delete_captcha(uid_prev):
frappe.delete_doc('Captcha Validation', {'uid': uid_prev})
frappe.delete_doc('Captcha Validation', {'uid': uid_prev})
@frappe.whitelist(allow_guest=True)
def generate_hash(txt = None, length = 15):
"""Generates random hash for given text + current timestamp + random string."""
import hashlib
import time
# from .utils import random_string
digest = hashlib.sha224(
(txt or "").encode()
).hexdigest()
if length:
digest = digest[:length]
return digest

129
smart_service/templates/includes/login/_login.js

@ -4,7 +4,7 @@
var http = new XMLHttpRequest();
var uid = ''
var uid_prev = ''
var logged_in= false
var logged_in = false
window.disable_signup = {{disable_signup and "true" or "false" }};
function makeid(length) {
@ -34,7 +34,7 @@ args = {}, capTrue = '';
// return result;
// }
var captchaNumGen = () => {
uid_prev=uid
uid_prev = uid
uid = makeid(16)
success = false
success = frappe.call({
@ -49,7 +49,7 @@ var captchaNumGen = () => {
$("#capRandomNum1").append('<img id="captcha-img" style="border-radius:10px;" src="data:image/png;base64, ' + r.message + '">');
}
})
try{
try {
frappe.call({
async: true,
freeze: true,
@ -59,7 +59,7 @@ var captchaNumGen = () => {
}
})
}
catch{
catch {
}
// alpha_num = randomAlphaNum();
@ -72,12 +72,12 @@ var captchaNumGen = () => {
}
}
function set_status_as_invalid(){
if (logged_in===false){
login.set_status('{{ _("Login") }}', 'red');
function set_status_as_invalid() {
if (logged_in === false) {
login.set_status('{{ _("Login") }}', 'red');
}
}
var capTrue = captchaNumGen();
login.bind_events = function () {
@ -101,74 +101,31 @@ login.bind_events = function () {
let getPass = $("#login_password").val();
let getCaptcha = $("#login_captcha").val();
frappe.call({
async: true,
freeze: true,
method: "smart_service.overrides.overrides.override_file.check_captcha",
args: {
'captcha_input': getCaptcha,
'uid1': uid
},
success: function (r) {
capTrue = false
if (r.message === false) {
$("button").css("cursor", "pointer");
$("body").css("cursor", "default");
$('.login-captcha-refresh').css('z-index', '2');
$('.toggle-password').css('z-index', '2');
capTrue = captchaNumGen();
$("#login_captcha").val('');
login.set_status('{{ _("Invalid Captcha. Try Again.") }}', 'red');
return false;
} else if (r.message === true){
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";
if(login.call(args)){
}
capTrue = captchaNumGen();
}
})
} else {
args.usr = args.usr
args.pwd = getPass;
args.device = "desktop";
login.call(args)
capTrue = captchaNumGen();
const myTimeout = setTimeout(set_status_as_invalid, 2000);
capTrue = captchaNumGen();
// if(){
// }s
// else{
// }
}
} else {
window.location.reload();
args.captcha=getCaptcha
args.uid=uid
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)
// capTrue = captchaNumGen();
}
},
error: function (e) {
console.log(e)
}
})
})
} else {
args.usr = args.usr
args.pwd = getPass;
args.device = "desktop";
login.call(args)
// capTrue = captchaNumGen();
// const myTimeout = setTimeout(set_status_as_invalid, 2000);
}
// if (capTrue === true) {
// $("button").css("cursor", "pointer");
// $("body").css("cursor", "default");
@ -291,7 +248,7 @@ login.bind_events = function () {
return false;
})();*/
})
};
$(".form-signup").on("submit", function (event) {
@ -406,9 +363,9 @@ login.signup = function () {
// Login
login.call = function (args, callback) {
frappe.call({
frappe.call({
type: "POST",
args: args,
callback: callback,
@ -418,7 +375,7 @@ login.call = function (args, callback) {
login.set_status('{{ _("Verifying... ") }}', 'blue');
return true
}
login.set_status = function (message, color) {
@ -466,17 +423,17 @@ login.login_handlers = (function () {
}
var login_handlers = {
200: function (data) {
if (data.message == 'Logged In') {
login.set_status('{{ _("Success") }}', 'green');
logged_in=true
logged_in = true
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);
} else if (data.message == "No App") {
login.set_status("{{ _('Success') }}", 'green');
logged_in=true
logged_in = true
if (localStorage) {
var last_visited =
@ -510,16 +467,16 @@ login.login_handlers = (function () {
login.set_status(data.message[1], 'red');
} else {
login.set_status('{{ _("Success") }}', 'green');
logged_in=true
logged_in = true
frappe.msgprint(data.message[1])
}
//login.set_status(__(data.message), 'green');
}
}
//OTP verification
if (data.verification && data.message != 'Logged In') {
login.set_status('{{ _("Success") }}', 'green');
logged_in=true
logged_in = true
document.cookie = "tmp_id=" + data.tmp_id;

Loading…
Cancel
Save