Skip to content

Instantly share code, notes, and snippets.

@kevzettler
Created February 27, 2011 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevzettler/846662 to your computer and use it in GitHub Desktop.
Save kevzettler/846662 to your computer and use it in GitHub Desktop.
messy js
function crm(req,res,cb){
var post_body = "name="+encodeURIComponent(req.body.username)+"&password="+encodeURIComponent(req.body.password);
request({
method : "GET"
,uri: "http://admin:CREm@localhost.com/admin/login/login"
}, function(error, get_response, body){
jsdom.env(body, [
'http://code.jquery.com/jquery-1.5.min.js'
], function(errors, window) {
var $ = window.$
,authenticity_token = $('input[name="authenticity_token"]').val()
;
post_body += "&authenticity_token="+encodeURIComponent(authenticity_token);
request({
method: "POST"
,uri: "http://admin:CREm@localhost/admin/login/login"
,body : post_body
,headers :{
"Content-type": 'application/x-www-form-urlencoded; charset=UTF-8'
,"Cookie": get_response.headers['set-cookie'].split(";")[0]
}
}, function(error, post_response, body){
res.header("SET-COOKIE" , get_response.headers['set-cookie']+"; Domain=.localhost;");
res.send(200);
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment