-
-
Save ThiefMaster/6c86cf4dea122d267418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var request = require('request'), | |
cheerio = require('cheerio'); | |
function loginSEOpenID(email, password, callback) { | |
console.log('SE OpenID: Loading login form'); | |
request.get({ | |
url: 'https://openid.stackexchange.com/account/login' | |
}, function(error, response, body) { | |
var $ = cheerio.load(body); | |
var fkey = $('input[name="fkey"]').attr('value'); | |
console.log('SE OpenID: Logging in'); | |
request.post({ | |
url: 'https://openid.stackexchange.com/account/login/submit', | |
form: { | |
email: email, | |
password: password, | |
fkey: fkey | |
} | |
}, function(error, response, body) { | |
console.log('SE OpenID: Logged in (hopefully)'); | |
callback(); | |
}); | |
}); | |
} | |
function loginSO(callback) { | |
console.log('SO: Loading login form'); | |
request.get({ | |
url: 'http://stackoverflow.com/users/login' | |
}, function(error, response, body) { | |
var $ = cheerio.load(body); | |
var fkey = $('input[name="fkey"]').attr('value'); | |
console.log('SO: Logging in via SE OpenID'); | |
request.post({ | |
followAllRedirects: true, | |
url: 'http://stackoverflow.com/users/authenticate', | |
form: { | |
openid_identifier: 'https://openid.stackexchange.com', | |
fkey: fkey | |
} | |
}, function(error, response, body) { | |
var $ = cheerio.load(body); | |
console.log('SO: Logged in as ' + $('.profile-link').text()); | |
callback(); | |
}); | |
}); | |
} | |
loginSEOpenID('email@address', 'password', function() { | |
loginSO(function() { | |
console.log('Chat: Retrieving form key'); | |
request.get({ | |
url: 'http://chat.stackoverflow.com' | |
}, function(error, response, body) { | |
var $ = cheerio.load(body); | |
var fkey = $('input[name="fkey"]').attr('value'); | |
console.log('Chat: Current username: ' + $('#top-menu > a[href^="/users/"]').text()); | |
console.log('Chat: Sending message'); | |
request.post({ | |
url: 'http://chat.stackoverflow.com/chats/17/messages/new', | |
form: { | |
text: '*the python-less node chat client says hello*', | |
fkey: fkey | |
} | |
}, function(error, response, body) { | |
console.log('Chat: Sent message', body); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment