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 axios = require('axios');
const logger = require('winston'); 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 = { module.exports = {
getWalletList () { getWalletList () {
logger.debug('lbryApi >> getting wallet list'); logger.debug('lbryApi >> getting wallet list');
@ -10,8 +26,7 @@ module.exports = {
method: 'wallet_list', method: 'wallet_list',
}) })
.then(response => { .then(response => {
const result = response.data.result; handleResponse(response, resolve, reject);
resolve(result);
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -27,8 +42,7 @@ module.exports = {
params: publishParams, params: publishParams,
}) })
.then(response => { .then(response => {
const result = response.data.result; handleResponse(response, resolve, reject);
resolve(result);
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -43,18 +57,8 @@ module.exports = {
method: 'get', method: 'get',
params: { uri, timeout: 20 }, params: { uri, timeout: 20 },
}) })
.then(({ data }) => { .then(response => {
// check to make sure the daemon didn't just time out handleResponse(response, resolve, reject);
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);
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -69,8 +73,8 @@ module.exports = {
method: 'claim_list', method: 'claim_list',
params: { name: claimName }, params: { name: claimName },
}) })
.then(({ data }) => { .then(response => {
resolve(data.result); handleResponse(response, resolve, reject);
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -94,7 +98,6 @@ module.exports = {
} }
}) })
.catch(error => { .catch(error => {
console.log('error with resolve', error);
reject(error); reject(error);
}); });
}); });
@ -110,7 +113,6 @@ module.exports = {
if (data.result) { if (data.result) {
resolve(data.result.download_directory); resolve(data.result.download_directory);
} else { } 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.'); 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) => { return new Promise((resolve, reject) => {
resolve({ axios
tx : 'test', .post('http://localhost:5279/lbryapi', {
txid : 'test', method: 'channel_new',
nout : 'test', params: {
fee : 'test', channel_name: name,
claim_id: 'xxxxxxxxxxxxxxxxxx', 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, channelClaimId: certificate.claimId,
password : password, password : password,
address, address,
CertificateId : certificate.id,
}; };
return db.User.create(userData); return db.User.create(userData);
}).then(user => { }).then(user => {