Created
February 27, 2011 22:59
-
-
Save kevzettler/846662 to your computer and use it in GitHub Desktop.
messy js
This file contains hidden or 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
function crm(req,res,cb){ | |
var post_body = "name="+encodeURIComponent(req.body.username)+"&password="+encodeURIComponent(req.body.password); | |
request({ | |
method : "GET" | |
,uri: "http://admin:[email protected]/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