summaryrefslogtreecommitdiff
path: root/src/jqueryRest.js
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-10-02 14:29:47 +0200
committerAzul <azul@riseup.net>2012-10-02 14:29:47 +0200
commitbd48744cd1da75ddfcfeb8572eed55368711e9e2 (patch)
tree90c661d3465fb5ae449e7e04d172df94797268a6 /src/jqueryRest.js
parent7791caac4f3dc8f9b2fcca394ad9ce0cd12b6996 (diff)
using jquery for signup post now. login still pending
Diffstat (limited to 'src/jqueryRest.js')
-rw-r--r--src/jqueryRest.js57
1 files changed, 10 insertions, 47 deletions
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,