Skip to content

Commit

Permalink
Remove useless code and unify the methodology
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Feb 5, 2023
1 parent ab9e20b commit 6299a34
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions website/js/PasskyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@
});
}

static createAccount(server, username, password, email){
static createAccount(server, username, token, email){
return new Promise((resolve, reject) => {
if(!Validate.url(server)) return reject(1001);
if(!Validate.email(email)) return reject(1007);
if(!Validate.username(username)) return reject(1005);
if(!Validate.password(password)) return reject(1006);
if(!Validate.token(token)) return reject(1006);

let data = new FormData();
data.append("email", email);

let headers = new Headers();
headers.append('Authorization', 'Basic ' + btoa(username + ":" + password));
headers.append('Authorization', 'Basic ' + btoa(username + ":" + token));

fetch(server + "?action=createAccount", {
method: "POST",
Expand All @@ -149,18 +149,18 @@
});
}

static getToken(server, username, password, otp = "", encrypted = true){
static getToken(server, username, token, otp = ""){
return new Promise((resolve, reject) => {
if(!Validate.url(server)) return reject(1001);
if(!Validate.username(username)) return reject(1005);
if(!Validate.password(password)) return reject(1006);
if(!Validate.token(token)) return reject(1006);
if(!Validate.otp(otp)) return reject(1002);

let data = new FormData();
data.append("otp", otp);

let headers = new Headers();
headers.append('Authorization', 'Basic ' + btoa(username + ":" + password));
headers.append('Authorization', 'Basic ' + btoa(username + ":" + token));

fetch(server + "?action=getToken", {
method: "POST",
Expand All @@ -172,14 +172,6 @@
}).then((response) => {
try{
let data = JSON.parse(response);
if(!encrypted && data.passwords != null){
for(let i = 0; i < data.passwords.length; i++){
data.passwords[i].website = XChaCha20.decrypt(data.passwords[i].website, password);
data.passwords[i].username = XChaCha20.decrypt(data.passwords[i].username, password);
data.passwords[i].password = XChaCha20.decrypt(data.passwords[i].password, password);
data.passwords[i].message = XChaCha20.decrypt(data.passwords[i].message, password);
}
}
return resolve(data);
}catch(error){
return reject(1000);
Expand Down

0 comments on commit 6299a34

Please sign in to comment.