summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-11-19 15:58:46 +0100
committerAzul <azul@riseup.net>2012-11-19 15:58:46 +0100
commit49bfe6ab74229ba4da5342382b87dcd6fca239fa (patch)
tree05c70ca228e28a3a5fa3d35b9ffd441aac0a8ede /src
parent2859af0287d7672df0a8965be43fb9859fca8bf8 (diff)
works - but not quite what i want. Exposing jqXHR to error function
Diffstat (limited to 'src')
-rw-r--r--src/jqueryRest.js23
-rw-r--r--src/srp.js27
2 files changed, 27 insertions, 23 deletions
diff --git a/src/jqueryRest.js b/src/jqueryRest.js
index 54a0908..a7928d5 100644
--- a/src/jqueryRest.js
+++ b/src/jqueryRest.js
@@ -1,31 +1,30 @@
jqueryRest = function() {
// we do not fetch the salt from the server
- function register(session, callback)
+ function register(session)
{
- sendVerifier(session, callback);
+ return sendVerifier(session);
}
- function sendVerifier(session, callback) {
+ function sendVerifier(session) {
var salt = session.getSalt();
- $.post("users.json", { user:
+ return $.post("users.json", { user:
{ login: session.getI(),
password_salt: salt,
- password_verifier: session.getV(salt).toString(16)}
- }, callback);
+ password_verifier: session.getV(salt).toString(16)
+ }
+ });
}
- function handshake(session, callback) {
- $.post("sessions.json", { login: session.getI(),
- A: session.getAstr()}, callback);
+ function handshake(session) {
+ return $.post("sessions.json", { login: session.getI(), A: session.getAstr()});
}
- function authenticate(session, success) {
- $.ajax({
+ function authenticate(session) {
+ return $.ajax({
url: "sessions/" + session.getI() + ".json",
type: 'PUT',
data: {client_auth: session.getM()},
- success: success
});
}
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;