From bd48744cd1da75ddfcfeb8572eed55368711e9e2 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 2 Oct 2012 14:29:47 +0200 Subject: using jquery for signup post now. login still pending --- src/jqueryRest.js | 57 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 47 deletions(-) (limited to 'src/jqueryRest.js') diff --git a/src/jqueryRest.js b/src/jqueryRest.js index 9e7f72b..a618e87 100644 --- a/src/jqueryRest.js +++ b/src/jqueryRest.js @@ -1,48 +1,10 @@ jqueryRest = function() { - function getUrl() - { - return ""; - } - - function paths(path) - { - return path; - } - // Perform ajax requests at the specified path, with the specified parameters // Calling back the specified function. function ajaxRequest(relative_path, params, callback) { - var full_url = this.geturl() + this.paths(relative_path); - if( window.XMLHttpRequest) { - xhr = new XMLHttpRequest(); - } - else if (window.ActiveXObject){ - try { - xhr = new ActiveXObject("Microsoft.XMLHTTP"); - } catch (e){} - } - else - { - session.error_message("Ajax not supported."); - return; - } - if(xhr){ - xhr.onreadystatechange = function() { - if(xhr.readyState == 4 && xhr.status == 200) { - callback(parseResponse()); - } - }; - xhr.open("POST", full_url, true); - xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhr.setRequestHeader("Content-length", params.length); - xhr.send(params); - } - else - { - session.error_message("Ajax failed."); - } + $.post(relative_path, params, callback) } function parseResponse() { @@ -98,26 +60,27 @@ jqueryRest = function() { } function sendVerifier(session, callback) { - this.ajaxRequest("users", "user[login]=" + session.getI() + - "&user[password_salt]=" + session.getSalt() + - "&user[password_verifier]=" + session.getV().toString(16), callback); + var salt = session.getSalt(); + ajaxRequest("users", { user: + { login: session.getI(), + password_salt: salt, + password_verifier: session.getV(salt).toString(16)} + }, callback); } function handshake(I, Astr, callback) { - this.ajaxRequest("handshake/", "I="+I+"&A="+Astr, callback); + ajaxRequest("handshake/", "I="+I+"&A="+Astr, callback); } function authenticate(M, callback) { - this.ajaxRequest("authenticate/", "M="+M, callback); + ajaxRequest("authenticate/", "M="+M, callback); } function upgrade(M, callback) { - this.ajaxRequest("upgrade/authenticate/", "M="+M, callback); + ajaxRequest("upgrade/authenticate/", "M="+M, callback); } return { - geturl: getUrl, - paths: paths, ajaxRequest: ajaxRequest, register: register, register_send_verifier: sendVerifier, -- cgit v1.2.3 From 6caf581e26c989ec5e2154aa60d6526ff956e381 Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 14 Oct 2012 15:30:51 +0200 Subject: got SRP v6a test setup and basic rest flow to work * still need to fix the algo for auth * Also need to get the http verbs right --- src/jqueryRest.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/jqueryRest.js') diff --git a/src/jqueryRest.js b/src/jqueryRest.js index a618e87..64c8080 100644 --- a/src/jqueryRest.js +++ b/src/jqueryRest.js @@ -68,16 +68,13 @@ jqueryRest = function() { }, callback); } - function handshake(I, Astr, callback) { - ajaxRequest("handshake/", "I="+I+"&A="+Astr, callback); + function handshake(session, callback) { + ajaxRequest("sessions", { login: session.getI(), + A: session.getAstr()}, callback); } - function authenticate(M, callback) { - ajaxRequest("authenticate/", "M="+M, callback); - } - - function upgrade(M, callback) { - ajaxRequest("upgrade/authenticate/", "M="+M, callback); + function authenticate(session, callback) { + ajaxRequest("sessions/" + session.getI(), {client_auth: session.getM()}, callback); } return { @@ -85,7 +82,6 @@ jqueryRest = function() { register: register, register_send_verifier: sendVerifier, handshake: handshake, - authenticate: authenticate, - upgrade: upgrade + authenticate: authenticate }; }; -- cgit v1.2.3 From 09a6d9eb8d0467f311bbae3d6fe2d923244edb21 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 15 Oct 2012 11:10:35 +0200 Subject: all rest tests passing, using proper verbs --- src/jqueryRest.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/jqueryRest.js') diff --git a/src/jqueryRest.js b/src/jqueryRest.js index 64c8080..f50080b 100644 --- a/src/jqueryRest.js +++ b/src/jqueryRest.js @@ -1,12 +1,5 @@ jqueryRest = function() { - // Perform ajax requests at the specified path, with the specified parameters - // Calling back the specified function. - function ajaxRequest(relative_path, params, callback) - { - $.post(relative_path, params, callback) - } - function parseResponse() { if (responseIsXML()) { return parseXML(xhr.responseXML); @@ -61,7 +54,7 @@ jqueryRest = function() { function sendVerifier(session, callback) { var salt = session.getSalt(); - ajaxRequest("users", { user: + $.post("users", { user: { login: session.getI(), password_salt: salt, password_verifier: session.getV(salt).toString(16)} @@ -69,16 +62,20 @@ jqueryRest = function() { } function handshake(session, callback) { - ajaxRequest("sessions", { login: session.getI(), + $.post("sessions", { login: session.getI(), A: session.getAstr()}, callback); } - function authenticate(session, callback) { - ajaxRequest("sessions/" + session.getI(), {client_auth: session.getM()}, callback); + function authenticate(session, success) { + $.ajax({ + url: "sessions/" + session.getI(), + type: 'PUT', + data: {client_auth: session.getM()}, + success: success + }); } return { - ajaxRequest: ajaxRequest, register: register, register_send_verifier: sendVerifier, handshake: handshake, -- cgit v1.2.3