From 082f859bbdaedf4f03eb85aea9b8f88ffda2fe6d Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 19 Nov 2012 18:11:20 +0100 Subject: further cleanup --- src/jqueryRest.js | 62 ++++++++++++++++++++++-------------------------------- src/srp_session.js | 16 ++++++++++++++ 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/jqueryRest.js b/src/jqueryRest.js index 29f737c..c439f67 100644 --- a/src/jqueryRest.js +++ b/src/jqueryRest.js @@ -1,51 +1,39 @@ -jqueryRest = function() { - - // we do not fetch the salt from the server - function register(session) - { - return sendVerifier(session); - } +srp.remote = (function(){ + var jqueryRest = (function() { - function sendVerifier(session) { - var salt = session.getSalt(); - return $.post("users.json", { user: - { login: session.getI(), - password_salt: salt, - password_verifier: session.getV(salt).toString(16) - } - }); - } + // we do not fetch the salt from the server + function register(session) { + return $.post("users.json", { user: session.signup() }); + } - function handshake(session) { - return $.post("sessions.json", { login: session.getI(), A: session.getAstr()}); - } + function handshake(session) { + return $.post("sessions.json", session.handshake()); + } - function authenticate(session) { - return $.ajax({ - url: "sessions/" + session.getI() + ".json", - type: 'PUT', - data: {client_auth: session.getM()}, - }); - } + function authenticate(session) { + return $.ajax({ + url: "sessions/" + session.getI() + ".json", + type: 'PUT', + data: {client_auth: session.getM()} + }); + } - return { - register: register, - register_send_verifier: sendVerifier, - handshake: handshake, - authenticate: authenticate - }; -}; + return { + register: register, + handshake: handshake, + authenticate: authenticate + }; + }()); -srp.remote = (function(){ function signup(){ - jqueryRest().register(srp.session) + jqueryRest.register(srp.session) .success(srp.signedUp) .error(srp.error) }; function login(){ - jqueryRest().handshake(srp.session) + jqueryRest.handshake(srp.session) .success(receiveSalts) .error(srp.error) }; @@ -62,7 +50,7 @@ srp.remote = (function(){ else { srp.session.calculations(response.salt, response.B); - jqueryRest().authenticate(srp.session) + jqueryRest.authenticate(srp.session) .success(confirmAuthentication) .error(srp.error); } diff --git a/src/srp_session.js b/src/srp_session.js index 7f1232f..b278993 100644 --- a/src/srp_session.js +++ b/src/srp_session.js @@ -35,6 +35,22 @@ srp.Session = function(login, password) { return Astr; }; + this.signup = function() { + var salt = this.getSalt(); + return { + login: this.getI(), + password_salt: salt, + password_verifier: this.getV(salt).toString(16) + }; + }; + + this.handshake = function() { + return { + login: this.getI(), + A: this.getAstr() + }; + }; + this.getAstr = function() { return Astr; } -- cgit v1.2.3