Created
February 27, 2011 23:00
-
-
Save kevzettler/846663 to your computer and use it in GitHub Desktop.
manageable 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); | |
| function getRequestParams(){ | |
| return { | |
| method : "GET" | |
| ,uri: "http://admin:[email protected]/admin/login/login" | |
| }; | |
| } | |
| function getDomHandler(errors, window) { | |
| var $ = window.$ | |
| ,authenticity_token = $('input[name="authenticity_token"]').val() | |
| ; | |
| post_body += "&authenticity_token="+encodeURIComponent(authenticity_token); | |
| request(postRequestParams(), postRequestCB); | |
| } | |
| function getRequestCB(error, get_response, body){ | |
| jsdom.env(body, ['http://code.jquery.com/jquery-1.5.min.js'], getDomHandler); | |
| } | |
| } | |
| function postRequestParams(){ | |
| return { | |
| 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 postRequestCB(error, post_response, body){ | |
| res.header("SET-COOKIE" , get_response.headers['set-cookie']+"; Domain=.localhost;"); | |
| res.send(200); | |
| } | |
| request(getRequestParams(), getRequestCB); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment