Fix a few bugs.
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Mon, 12 Oct 2009 17:20:19 -0700
changeset 5 d309982be1c20be1502c6a6bd8fae2772cbc979a
parent 4 d9918b4187081ec5ca7da74b4d0facd1989ca3ea
child 6 3420e80f5acbf6984aaa6625a95e067508863379
push id5
push usersdwilsh@shawnwilsher.com
push dateThu, 22 Oct 2009 23:08:43 +0000
Fix a few bugs. Hardcode my login with a weak password.
content/UntrustedHttpsRequest.js
content/reply.js
content/reply.xul
--- a/content/UntrustedHttpsRequest.js
+++ b/content/UntrustedHttpsRequest.js
@@ -7,17 +7,17 @@ Components.utils.import("resource://gre/
  *
  * This object can then be used just like an XMLHttpRequest object.
  *
  * @param aFingerprint
  *        The MD5 fingerprint of the certificate encrypting the connection.
  */
 function UntrustedHttpsRequest(aFingerprint)
 {
-  if (!aFingerPrint) {
+  if (!aFingerprint) {
     throw new Components.Exception("Must provide an MD5 fingerprint!",
                                    Components.results.NS_ERROR_INVALID_ARG,
                                    Components.stack.caller);
   }
   this.__proto__.__proto__ = new XMLHttpRequest();
   this._callback._fingerprint = aFingerprint;
 }
 
@@ -78,17 +78,17 @@ UntrustedHttpsRequest.prototype = {
   //////////////////////////////////////////////////////////////////////////////
   //// XMLHttpRequest
 
   open: function UHR_open(aMethod, aURI)
   {
     // We want to make sure that the certificate will be added, so we open up
     // another request now to the address.
     let req = new XMLHttpRequest();
-    req.open("HEAD", aURI);
+    req.open("HEAD", aURI, false);
     req.channel.notificationCallbacks = this._callback;
     try {
       req.send(null);
     }
     catch (e) {
       // Unconditionally catch the exception about the load failing.
     }
     this._wrappedOpen.apply(this, arguments);
--- a/content/reply.js
+++ b/content/reply.js
@@ -1,12 +1,15 @@
 ////////////////////////////////////////////////////////////////////////////////
 //// Constants
 
+/*
 const kDestinationURI = "https://api-dev.bugzilla.mozilla.org/0.1/";
+*/
+const kDestinationURI = "https://api-dev.bugzilla.mozilla.org/stage/0.1/";
 const kFingerprint = "75:B2:EF:89:81:51:8F:99:13:DC:BF:44:47:0E:A9:8D";
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Dialog Controller
 
 var ReplyDialog = {
   initialize: function RD_initialize()
   {
@@ -19,31 +22,45 @@ var ReplyDialog = {
     });
     comment.value = lines.join("\n") + "\n";
     comment.focus();
   },
 
   onAccept: function RD_onAccept()
   {
     // TODO handle offline!
-    // XXX login
+    let [username, password] = this.getLoginInformation();
+    const auth = "username=" + username + "&password=" + password;
     let bugID = window.arguments[0];
-    const URI = kDestinationURI + "/bug/" + bugID + "/comment";
+    const URI = kDestinationURI + "bug/" + bugID + "/comment?" + auth;
+    alert("sending comment to " + URI);
     let req = new UntrustedHttpsRequest(kFingerprint);
     req.open("POST", URI, false);
     req.overrideMimeType("application/json");
     req.send(ReplyDialog.createJSON());
+    alert(ReplyDialog.createJSON());
+    if (req.status == 200)
+      alert(req.responseText);
+    else
+      alert(req.status);
     return true;
   },
 
   createJSON: function RD_createJSON()
   {
     let comment = document.getElementById("comment").value;
     let private = document.getElementById("private").checked;
     let data = {
       is_private: private ? 1 : 0,
       text: comment,
     };
     return JSON.stringify(data);
   },
+
+  getLoginInformation: function RD_getLoginInformation()
+  {
+    // NOTE this isn't my actually password.  I changed it on the staging server
+    // to be something weak.
+    return ["sdwilsh@forerunnerdesigns.com", "datamilk"];
+  },
 };
 
 window.addEventListener("DOMContentLoaded", ReplyDialog.initialize, false);
--- a/content/reply.xul
+++ b/content/reply.xul
@@ -1,12 +1,12 @@
 <?xml version="1.0"?>
 
 <?xml-stylesheet type="text/css"
-                 href="chrome://bugzilla-reply/content/reply.css"?>
+                 href="chrome://bugzilla-helper/content/reply.css"?>
 
 <?xul-overlay href="chrome://global/content/editMenuOverlay.xul"?>
 
 <dialog id="bugzilla-reply-window"
         buttons="accept,cancel"
         buttonlabelaccept="Commit"
         buttonlabelcancel="Cancel"
         ondialogaccept="ReplyDialog.onAccept();"