Update user profile
authorplehegar
Fri, 26 Aug 2011 11:43:59 -0400
changeset 110 8ec4ad627381
parent 109 70322101593e
child 111 9d871d38289a
Update user profile
Added support to auth on POST
src/main/resources/scripts/tracker.js
--- a/src/main/resources/scripts/tracker.js	Fri Aug 26 11:42:27 2011 -0400
+++ b/src/main/resources/scripts/tracker.js	Fri Aug 26 11:43:59 2011 -0400
@@ -17,7 +17,8 @@
     if (n === null) {
       Util.log("Creating dummy user");
       n = {
-      	name  : "[email protected]",
+      	name  : "DummyUser",
+      	userId : "[email protected]",
       	passwd: "foobar",
         email : "[email protected]",
         weight : 73,
@@ -30,10 +31,10 @@
         }
       };
     } else {
-      Util.log("Found user " + n.name);
+      Util.log("Found user " + n.userId);
     }
-    n.getPostRunURI = function() { return "/user/" + this.name + "/workout"; }
-    n.getProfileURI = function() { return "/user/" + this.name + "/profile"; }
+    n.getPostRunURI = function() { return "/user/" + this.userId + "/workout"; }
+    n.getProfileURI = function() { return "/user/" + this.userId + "/profile"; }
  
     n.save = function() {
       if (Util.store.set("track_gps_user", this)) {
@@ -247,7 +248,9 @@
       		Util.log("[ERROR] Can't store the workout");
     	}
   	}
-  	Util.postAsJSON(user.getPostRunURI(),app.currentActivity, success, error);
+  	Util.postAsJSON(user.getPostRunURI(),
+  	                { userId : user.userId, passwd : user.passwd, data: app.currentActivity },
+  	                success, error);
   } else {
   	Util.log("[ERROR] Your workout doesn't contain enough events");
   }
@@ -324,8 +327,9 @@
 
 app.setPrefs = function () {
   var nodes = null, node = null;
-    
-  document.getElementById("user_input").value = user.name;
+
+  document.getElementById("user_name_input").value = user.name;
+  document.getElementById("user_email_input").value = user.email;
 
   nodes = document.getElementsByClassName("distance_unit");
   i = 0;
@@ -366,7 +370,8 @@
 }
 
 app.save = function () {
-  user.name = document.getElementById("user_input").value;
+  user.name = document.getElementById("user_name_input").value;
+  user.email = document.getElementById("user_email_input").value;
   user.weight = parseInt(document.getElementById("weight_input").value);
   user.height = parseInt(document.getElementById("height_input").value);
   user.save();