const got = require('got');
const {PassThrough} = require('stream');
const tough = require('tough-cookie');
const FormData = require('form-data');
const loginWithGot = async (username, password) => {
const jar = new tough.CookieJar();
await got('https://www.unlimitedhorizon.co.uk', {cookieJar: jar});
const form = new FormData();
form.append('username', username);
form.append('password', password);
const s = new PassThrough();
form.pipe(s);
const response = await got.post('https://www.unlimitedhorizon.co.uk/webapp/signin?wicket:interface=:0:wrap:inner:signInPanel:signInForm::IFormSubmitListener::', {
cookieJar: jar,
body: s,
retry: {
limit: 0
},
followRedirect: false,
timeout: 1000
});
return (response.headers.location == 'dashboard/admin');
};
(async () => {
console.log('Got', await loginWithGot('asdf', 'asdf'))
})();