From 49bfe6ab74229ba4da5342382b87dcd6fca239fa Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 19 Nov 2012 15:58:46 +0100 Subject: works - but not quite what i want. Exposing jqXHR to error function --- src/srp.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/srp.js') diff --git a/src/srp.js b/src/srp.js index 6d1e8c1..6a377ce 100644 --- a/src/srp.js +++ b/src/srp.js @@ -2,8 +2,6 @@ function SRP(remote, session) { var srp = this; session = session || new this.Session(); - remote = remote || new this.Remote(); - remote.onError = remote.onError || this.error; session.onError = session.onError || this.error; this.remote = remote; this.session = session; @@ -12,7 +10,9 @@ function SRP(remote, session) this.identify = function(success, error) { store_callbacks(success, error); - remote.handshake(session, receive_salts); + remote.handshake(session) + .success(receive_salts) + .error(srp.error); // Receive login salts from the server, start calculations function receive_salts(response) @@ -28,7 +28,9 @@ function SRP(remote, session) else { session.calculations(response.salt, response.B); - remote.authenticate(session, confirm_authentication); + remote.authenticate(session) + .success(confirm_authentication) + .error(srp.error); } } @@ -47,12 +49,15 @@ function SRP(remote, session) this.register = function(success, error) { store_callbacks(success, error); - remote.register(session, srp.registered_user); + remote.register(session) + .success(srp.registered_user) + .error(srp.error); }; // The user has been registered successfully, now login this.registered_user = function(response) { + // TODO: This can go if response has an error code if(response.errors) { srp.error(response.errors) } @@ -61,12 +66,6 @@ function SRP(remote, session) } }; - // Minimal error handling - set remote.onError to sth better to overwrite. - this.error = function(text) - { - alert(text); - }; - // This function is called when authentication is successful. // It's a dummy. Please hand the real thing to the call to identify. this.success = function() @@ -74,6 +73,12 @@ function SRP(remote, session) alert("Login successful."); }; + // Minimal error handling - set remote.onError to sth better to overwrite. + this.error = function(text) + { + alert(text); + }; + function store_callbacks(success, error) { if (typeof success == "function") { srp.success = success; -- cgit v1.2.3 From 2e365cba5263ec50f10fb074c054ef19adb8f7b0 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 19 Nov 2012 17:36:49 +0100 Subject: first step at cleaning up the srp --- src/srp.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/srp.js') diff --git a/src/srp.js b/src/srp.js index 6a377ce..5b76a88 100644 --- a/src/srp.js +++ b/src/srp.js @@ -1,3 +1,22 @@ +var srp = (function(){ + + function signup() + { + this.remote.signup(); + }; + + function login() + { + this.remote.login(); + }; + + return { + signup: signup, + login: login + } +}()); + + function SRP(remote, session) { var srp = this; -- cgit v1.2.3 From a41d7f306aa1dbcae17643cc9c3b457632ee8909 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 19 Nov 2012 17:49:18 +0100 Subject: removed the SRP class - using just a plain srp object now --- src/srp.js | 92 -------------------------------------------------------------- 1 file changed, 92 deletions(-) (limited to 'src/srp.js') diff --git a/src/srp.js b/src/srp.js index 5b76a88..e57b7e9 100644 --- a/src/srp.js +++ b/src/srp.js @@ -16,95 +16,3 @@ var srp = (function(){ } }()); - -function SRP(remote, session) -{ - var srp = this; - session = session || new this.Session(); - session.onError = session.onError || this.error; - this.remote = remote; - this.session = session; - - // Start the login process by identifying the user - this.identify = function(success, error) - { - store_callbacks(success, error); - remote.handshake(session) - .success(receive_salts) - .error(srp.error); - - // Receive login salts from the server, start calculations - function receive_salts(response) - { - // B = 0 will make the algorithm always succeed - // -> refuse such a server answer - if(response.B === 0) { - srp.error("Server send random number 0 - could not login."); - } - else if(! response.salt || response.salt === 0) { - srp.error("Server failed to send salt - could not login."); - } - else - { - session.calculations(response.salt, response.B); - remote.authenticate(session) - .success(confirm_authentication) - .error(srp.error); - } - } - - // Receive M2 from the server and verify it - // If an error occurs, raise it as an alert. - function confirm_authentication(response) - { - if (session.validate(response.M2)) - srp.success(); - else - srp.error("Server key does not match"); - }; - }; - - // Initiate the registration process - this.register = function(success, error) - { - store_callbacks(success, error); - remote.register(session) - .success(srp.registered_user) - .error(srp.error); - }; - - // The user has been registered successfully, now login - this.registered_user = function(response) - { - // TODO: This can go if response has an error code - if(response.errors) { - srp.error(response.errors) - } - else { - srp.identify(); - } - }; - - // This function is called when authentication is successful. - // It's a dummy. Please hand the real thing to the call to identify. - this.success = function() - { - alert("Login successful."); - }; - - // Minimal error handling - set remote.onError to sth better to overwrite. - this.error = function(text) - { - alert(text); - }; - - function store_callbacks(success, error) { - if (typeof success == "function") { - srp.success = success; - } - if (typeof error == "function") { - srp.error = error; - } - } -}; - -- cgit v1.2.3