Skip to content

Instantly share code, notes, and snippets.

@imaustink
Created February 23, 2017 16:52
Show Gist options
  • Save imaustink/3b2e4a42aa9fe81eef88b0677f6cf014 to your computer and use it in GitHub Desktop.
Save imaustink/3b2e4a42aa9fe81eef88b0677f6cf014 to your computer and use it in GitHub Desktop.
'use strict';
const Request = require('request');
const Cheerio = require('cheerio');
const fs = require('fs');
const STORE_URL = 'https://www.site-domain.com/';
const req = Request.defaults({jar: true});
require('request-debug')(Request);
req.post({
url: `${STORE_URL}account/login`,
form: {
'form_type': 'customer_login',
'utf8': '✓',
'customer[email]': '[email protected]',
'customer[password]': 'P@$$word1'
}
}, function(err, result){
if(err) throw err;
var code = result.statusCode;
var redirect = result.headers.location;
if(code === 302){
if(redirect === `${STORE_URL}account`){
console.log('Successfully authenticated!');
req.get(redirect, function(err, result, body){
if(err) throw err;
fs.writeFileSync('./log.html', body, 'utf8');
});
}
if(redirect === `${STORE_URL}account/login`) console.log('Failed to authenticate!');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment