Skip to content
Snippets Groups Projects
Commit 80641dae authored by Markin Igor's avatar Markin Igor
Browse files

Move certificates and signing logic into signingUtilities.

parent f0402666
No related branches found
No related tags found
1 merge request!21Resolve "Bug with iframe during the email signing"
This diff is collapsed.
......@@ -18,4 +18,106 @@ export const encodeResponse = (code, data, status) => {
data,
status
};
};
\ No newline at end of file
};
export function makeid(len) {
if (typeof len === 'undefined') {
len = 10
}
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < len; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
//*********************************************************************************
function getBlockFinishTimeInLocalStorage() {
return localStorage.getItem("blockFinishTime") || getCurrentTime();
}
function getCurrentTime() {
return Math.floor(new Date().getTime() / 1000);
}
export function getTimeLeftInLocalStorage() {
const blockFinishTime = getBlockFinishTimeInLocalStorage();
const timeNow = getCurrentTime();
const seconds = (blockFinishTime - timeNow) % 60;
let minutes = Math.floor((blockFinishTime - timeNow) / 60);
minutes %= 60;
const left = "Your identity has been locked. Try again in " + minutes + " minutes and " + seconds + " seconds.";
return left;
}
export function listIdentitiesFromLocalStorage() {
var serializedIdentitiesList = localStorage.getItem("identities");
var identities = JSON.parse(serializedIdentitiesList);
var identitiesResult = {};
for(var key in identities) {
var profile = JSON.parse(JSON.stringify(localStorage.getItem("profiles/" + key)));
if(profile != null && profile !== "") {
identitiesResult[key] = JSON.parse(profile)
} else {
identitiesResult[key] = {}
}
}
return identitiesResult
}
export function destroyIdentityFromLocalStorage(key) {
localStorage.removeItem(key);
localStorage.removeItem("profiles/" + key);
localStorage.removeItem("colors/" + key);
var serializedIdentitiesList = localStorage.getItem("identities");
var identities = JSON.parse(serializedIdentitiesList);
identities[key] = null;
delete identities[key];
localStorage.setItem("identities", JSON.stringify(identities))
}
export function failPincodeAttempt(password) {
let message = "Wrong pincode";
if (password !== '00000000') {
let attempt = localStorage.getItem("attempt") || 1;
attempt = parseInt(attempt);
if (attempt === 9) {
const identitiesTemp = listIdentitiesFromLocalStorage();
for (let i in identitiesTemp) {
destroyIdentityFromLocalStorage(i);
}
message = "9 failed attempts. Identity is revoked!";
localStorage.removeItem("attempt");
} else if (attempt % 3 === 0) {
const timeNow = getCurrentTime();
const blockFinishTime = timeNow + 300;
localStorage.setItem("blockFinishTime", blockFinishTime);
localStorage.setItem("attempt", attempt + 1);
message = "3 failed attempts. Identity is locked!";
} else {
localStorage.setItem("attempt", attempt + 1);
}
}
return message;
}
export function canTryPincode() {
const timeNow = getCurrentTime();
const blockFinishTime = getBlockFinishTimeInLocalStorage();
if (blockFinishTime <= timeNow) {
localStorage.removeItem("blockFinishTime");
return true;
} else {
return false;
}
}
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment