i will not understand

This commit is contained in:
Shihaam Abdul Rahman 2024-10-22 00:37:58 +05:00
parent 3e8dbb5931
commit 121dc00125
Signed by: shihaam
GPG Key ID: 6DA2E87EBC227636

316
auth.js
View File

@ -1,316 +0,0 @@
let displayError = function (msg) {
$("#error-display").text(msg).show('slow');
};
let hideError = function (msg) {
$("#error-display").hide('slow');
};
window.location.hash = '';
let hideProgress = function () {
$("#login-submit").removeClass('button-loader');
};
let showProgress = function () {
$("#login-submit").addClass('button-loader');
};
let pushDashboardToHistory = function () {
let defaultLandingPage = "https://faisanet.mib.com.mv/dashboard";
window.history.pushState({}, '', defaultLandingPage)
};
let getLandingPage = function (landingPageOption) {
let landingPage = "https://faisanet.mib.com.mv/profiles";
switch (landingPageOption) {
case "0":
{
//individual account login
landingPage = "https://faisanet.mib.com.mv/dashboard";
break;
}
case "1":
{
//profiles
landingPage = "https://faisanet.mib.com.mv/accounts";
break;
}
case "2":
{
//quick
landingPage = "https://faisanet.mib.com.mv/transfer/quick";
break;
}
case "3":
{
//local
landingPage = "https://faisanet.mib.com.mv/transfer/local";
break;
}
default:
{
//profiles
landingPage = "https://faisanet.mib.com.mv/profiles";
}
}
return landingPage;
}
let requestAuthType = function () {
showProgress();
hideError();
actionBlocker.blockActions();
let formData = $('#login-submit-form').serializeArray().reduce(function (obj, item) {
obj[item.name] = item.value;
return obj;
}, {});
delete formData['pgf02'];
$.ajax({
type: 'POST',
url: "https://faisanet.mib.com.mv/aAuth/getAuthType",
data: formData,
success: function (data, textStatus, request) {
actionBlocker.unblockActions();
//hideProgress();
let responseData = (JSON.parse(request.responseText));
let loginTypeParams = responseData['data'][0];
console.log(data, textStatus, request);
console.log(loginTypeParams);
if (loginTypeParams['loginType'] == 0) {
requestSimpleAuth();
} else {
requestXAuth(loginTypeParams);
}
},
error: function (request, textStatus, errorThrown) {
actionBlocker.unblockActions();
hideProgress();
let responseData = (JSON.parse(request.responseText));
displayError(responseData.reasonText);
}
});
};
let get256Hash = function (text) {
const shaObj = new jsSHA("SHA-256", "TEXT", {encoding: "UTF8"});
/* .update() can be chained */
//shaObj.update("This is").update(" a ");
shaObj.update(text);
const hash = shaObj.getHash("HEX");
return hash.toUpperCase();
};
function getSalt(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
}
let getHashedLoginParams = function (userSalt) {
let formData = $('#login-submit-form').serializeArray().reduce(function (obj, item) {
obj[item.name] = item.value;
return obj;
}, {});
let clientSalt = getSalt(32);
let hashedpw = get256Hash (clientSalt + get256Hash(get256Hash(formData['pgf02']) + userSalt));
delete formData['pgf02'];
formData['pgf03']= hashedpw;
formData['clientSalt'] = clientSalt;
return formData;
};
let requestXAuth = function (loginTypeParams) {
showProgress();
hideError();
actionBlocker.blockActions();
let hashedLoginParams = getHashedLoginParams(loginTypeParams['userSalt']);
$.ajax({
type: 'POST',
url: "https://faisanet.mib.com.mv/aAuth/xAuth",
data: hashedLoginParams,
success: function (data, textStatus, request) {
actionBlocker.unblockActions();
//hideProgress();
let responseData = (JSON.parse(request.responseText));
console.log(data, textStatus, request);
console.log(responseData);
hideProgress();
if (responseData.otpVerified == 0) {
window.location = 'https://faisanet.mib.com.mv/auth2FA';
return;
}
let landingPageOption = responseData.landingPage;
let landingPage = getLandingPage(landingPageOption);
switch (responseData.reasonCode) {
case "101":
{
//individual account login
window.location = landingPage;
break;
}
case "102":
{
//profiles
window.location = "https://faisanet.mib.com.mv/profiles";
break;
}
default:
{
//profiles
window.location = "https://faisanet.mib.com.mv/profiles";
}
}
},
error: function (request, textStatus, errorThrown) {
actionBlocker.unblockActions();
hideProgress();
let responseData = (JSON.parse(request.responseText));
displayError(responseData.reasonText);
}
});
};
let requestSimpleAuth = function () {
showProgress();
hideError();
actionBlocker.blockActions();
let formData = $('#login-submit-form').serializeArray().reduce(function (obj, item) {
obj[item.name] = item.value;
return obj;
}, {});
$.ajax({
type: 'POST',
url: "https://faisanet.mib.com.mv/aAuth",
data: formData,
success: function (data, textStatus, request) {
actionBlocker.unblockActions();
//hideProgress();
let responseData = (JSON.parse(request.responseText));
console.log(data, textStatus, request);
console.log(responseData);
hideProgress();
if (responseData.otpVerified == 0) {
window.location = 'https://faisanet.mib.com.mv/auth2FA';
return;
}
let landingPageOption = responseData.landingPage;
let landingPage = getLandingPage(landingPageOption);
switch (responseData.reasonCode) {
case "101":
{
//individual account login
window.location = landingPage;
break;
}
case "102":
{
//profiles
window.location = "https://faisanet.mib.com.mv/profiles";
break;
}
default:
{
//profiles
window.location = "https://faisanet.mib.com.mv/profiles";
}
}
},
error: function (request, textStatus, errorThrown) {
actionBlocker.unblockActions();
hideProgress();
let responseData = (JSON.parse(request.responseText));
displayError(responseData.reasonText);
}
});
};
$("#login-submit").click(function (e) {
$('#error-info').hide('slow');
e.preventDefault();
requestAuthType();
//hashPassword();
//requestSimpleAuth();
});