Authentication #170

Merged
bones7242 merged 43 commits from authentication into master 2017-09-29 02:29:22 +02:00
2 changed files with 38 additions and 28 deletions
Showing only changes of commit 9041d4d4dc - Show all commits

View file

@ -1,6 +1,22 @@
const axios = require('axios');
const logger = require('winston');
function handleResponse ({ data }, resolve, reject) {
logger.debug('handling lbry api response');
if (data.result) {
// check for an error
if (data.result.error) {
reject(data.result.error);
return;
};
logger.debug('data.result', data.result);
resolve(data.result);
return;
}
// fallback in case the just timed out
reject(JSON.stringify(data));
}
module.exports = {
getWalletList () {
logger.debug('lbryApi >> getting wallet list');
@ -10,8 +26,7 @@ module.exports = {
method: 'wallet_list',
})
.then(response => {
const result = response.data.result;
resolve(result);
handleResponse(response, resolve, reject);
})
.catch(error => {
reject(error);
@ -27,8 +42,7 @@ module.exports = {
params: publishParams,
})
.then(response => {
const result = response.data.result;
resolve(result);
handleResponse(response, resolve, reject);
})
.catch(error => {
reject(error);
@ -43,18 +57,8 @@ module.exports = {
method: 'get',
params: { uri, timeout: 20 },
})
.then(({ data }) => {
// check to make sure the daemon didn't just time out
if (!data.result) {
reject(JSON.stringify(data));
}
if (data.result.error) {
reject(data.result.error);
}
/*
note: put in a check to make sure we do not resolve until the download is actually complete (response.data.completed === true)?
*/
resolve(data.result);
.then(response => {
handleResponse(response, resolve, reject);
})
.catch(error => {
reject(error);
@ -69,8 +73,8 @@ module.exports = {
method: 'claim_list',
params: { name: claimName },
})
.then(({ data }) => {
resolve(data.result);
.then(response => {
handleResponse(response, resolve, reject);
})
.catch(error => {
reject(error);
@ -94,7 +98,6 @@ module.exports = {
}
})
.catch(error => {
console.log('error with resolve', error);
reject(error);
});
});
@ -110,7 +113,6 @@ module.exports = {
if (data.result) {
resolve(data.result.download_directory);
} else {
// reject(new Error('Successfully connected to lbry daemon, but unable to retrieve the download directory.'));
return new Error('Successfully connected to lbry daemon, but unable to retrieve the download directory.');
}
})
@ -120,15 +122,22 @@ module.exports = {
});
});
},
createChannel (channelName) {
createChannel (name) {
return new Promise((resolve, reject) => {
resolve({
tx : 'test',
txid : 'test',
nout : 'test',
fee : 'test',
claim_id: 'xxxxxxxxxxxxxxxxxx',
});
axios
.post('http://localhost:5279/lbryapi', {
method: 'channel_new',
params: {
channel_name: name,
amount : 0.1,
},
})
.then(response => {
handleResponse(response, resolve, reject);
})
.catch(error => {
reject(error);
});
});
},
};

View file

@ -37,6 +37,7 @@ module.exports = new PassportLocalStrategy(
channelClaimId: certificate.claimId,
password : password,
address,
CertificateId : certificate.id,
};
return db.User.create(userData);
}).then(user => {