]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Add a much better QuakeNet login system.
authorChris Porter <redacted>
Mon, 16 Aug 2010 01:17:04 +0000 (02:17 +0100)
committerChris Porter <redacted>
Mon, 16 Aug 2010 01:17:04 +0000 (02:17 +0100)
css/dialogs.css
js/auth.js
js/ui/panes/connect.js
js/ui/panes/options.js
qwebirc/engines/authgateengine.py
static/panes/connect.html

index a40d0ec671e55ecf6ae363844982dfbb0d3f29dd..35c4b652d6b9637c033aad81c54c0417385f0dc1 100644 (file)
   text-align: left;
 }
 
+.qwebirc-loginbox input#loginnickname, .qwebirc-loginbox input#loginchannels {
+  width: 200px;
+}
+
 /**************** CONFIRM LOGIN BOX *******************/
 .qwebirc-confirmbox {
   width: 100%;
index d0e1be406043c7ac9328544b5f6b89008e449199..9f738ce11cd780d7d70fde0d836588458d5319ef 100644 (file)
@@ -5,15 +5,15 @@ qwebirc.auth.loggedin = function() {
 }
 
 qwebirc.auth.enabled = function() {
-  return false;
+  return true;
 }
 
 qwebirc.auth.quakeNetAuth = function() {
-  return false;
+  return true;
 }
 
 qwebirc.auth.passAuth = function() {
-  return true;
+  return false;
 }
 
 qwebirc.auth.bouncerAuth = function() {
index b496714ad95d92d337f8daa88591bd8feb29a5fe..7affa3fe0c2ca1252e92ca7cbc1d270fb036fee5 100644 (file)
@@ -3,6 +3,7 @@ qwebirc.ui.ConnectPane = new Class({
   initialize: function(parent, options) {
     var callback = options.callback, initialNickname = options.initialNickname, initialChannels = options.initialChannels, networkName = options.networkName, autoConnect = options.autoConnect, autoNick = options.autoNick;
     this.options = options;
+    this.__windowName = "authgate_" + Math.floor(Math.random() * 100000);
 
     var delayfn = function() { parent.set("html", "<div class=\"loading\">Loading. . .</div>"); };
     var cb = delayfn.delay(500);
@@ -40,13 +41,31 @@ qwebirc.ui.ConnectPane = new Class({
         this.__validate = this.__validateLoginData;
       }
 
+      if(qwebirc.auth.loggedin()) {
+        exec("[name=authname]", util.setText(qwebirc.auth.loggedin()));
+        exec("[name=connectbutton]", util.makeVisible);
+        exec("[name=loginstatus]", util.makeVisible);
+      } else {
+        if(qwebirc.ui.isAuthRequired()) {
+          exec("[name=loginconnectbutton]", util.makeVisible);
+          if(focus == "connect")
+            focus = "loginconnect";
+        } else {
+          exec("[name=connectbutton]", util.makeVisible);
+          exec("[name=loginbutton]", util.makeVisible);
+        }
+      }
+
       exec("[name=" + focus + "]", util.focus);
       exec("[name=connect]", util.attachClick(this.__connect.bind(this)));
+      exec("[name=loginconnect]", util.attachClick(this.__loginConnect.bind(this)));
+      exec("[name=login]", util.attachClick(this.__login.bind(this)));
     }.bind(this)});
     r.get();
   },
   util: {
     makeVisible: function(x) { x.setStyle("display", ""); },
+    setVisible: function(y) { return function(x) { x.setStyle("display", y ? "" : "none"); }; },
     focus: function(x) { x.focus(); },
     attachClick: function(fn) { return function(x) { x.addListener("click", fn); } },
     setText: function(x) { return function(y) {
@@ -66,9 +85,97 @@ qwebirc.ui.ConnectPane = new Class({
     if(data === false)
       return;
 
+    this.__cancelLogin();
     this.fireEvent("close");
     this.options.callback(data);
   },
+  __cancelLogin: function(noUIModifications) {
+    if(this.__cancelLoginCallback)
+      this.__cancelLoginCallback(noUIModifications);
+  },
+  __loginConnect: function(e) {
+    new Event(e).stop();
+    if(this.validate() === false)
+      return;
+
+    this.__performLogin(function() {
+      var data = this.validate();
+      if(data === false) {
+        /* we're logged in -- show the normal join button */
+        this.util.exec("[name=connectbutton]", this.util.setVisible(true));
+        return;
+      }
+
+      this.fireEvent("close");
+      this.options.callback(data);
+    }.bind(this), "loginconnectbutton");
+  },
+  __login: function(e) {
+    new Event(e).stop();
+
+    this.__cancelLogin(true);
+
+    this.__performLogin(function() {
+      var focus = "connect";
+      if(!this.options.autoConnect) {
+        var nick = this.rootElement.getElement("input[name=nickname]").value, chan = this.rootElement.getElement("input[name=channels]").value;
+        if(!nick) {
+          focus = "nickname";
+        } else if(!chan) {
+          focus = "channels";
+        }
+      }
+      this.util.exec("[name=" + focus + "]", this.util.focus);        
+    }.bind(this), "login");
+  },
+  __performLogin: function(callback, calleename) {
+    Cookie.write("jslogin", "1");
+
+    var handle = window.open("/auth", this.__windowName, "status=0,toolbar=0,location=1,menubar=0,directories=0,resizable=0,scrollbars=1,height=280,width=550");
+
+    if(handle === null || handle === undefined) {
+      Cookie.dispose("jslogin");
+//      Cookie.write("redirect", document.location);
+//      window.location = "auth?";
+      return;
+    }        
+
+    var closeDetector = function() {
+      if(handle.closed)
+        this.__cancelLoginCallback();
+    }.bind(this);
+    var closeCallback = closeDetector.periodical(100);
+
+    this.__cancelLoginCallback = function(noUIModifications) {
+      $clear(closeCallback);
+
+      Cookie.dispose("jslogin");
+
+      try {
+        handle.close();
+      } catch(e) {
+      }
+
+      if(!noUIModifications) {
+        this.util.exec("[name=loggingin]", this.util.setVisible(false));
+        this.util.exec("[name=" + calleename + "]", this.util.setVisible(true));
+      }
+      this.__cancelLoginCallback = null;
+    }.bind(this);
+
+    this.util.exec("[name=loggingin]", this.util.setVisible(true));
+    this.util.exec("[name=" + calleename + "]", this.util.setVisible(false));
+
+    __qwebircAuthCallback = function(username) {
+      this.__cancelLoginCallback(true);
+
+      this.util.exec("[name=loggingin]", this.util.setVisible(false));
+      this.util.exec("[name=loginstatus]", this.util.setVisible(true));
+      this.util.exec("[name=authname]", this.util.setText(username));
+      callback();
+    }.bind(this);
+
+  },
   __validateConfirmData: function() {
     return {nickname: this.options.initialNickname, autojoin: this.options.initialChannels};
   },
@@ -178,3 +285,12 @@ qwebirc.ui.authShowHide = function(checkbox, authRow, usernameBox, usernameRow,
     usernameBox.focus();
   }
 }
+
+qwebirc.ui.isAuthRequired = (function() {
+  var args = qwebirc.util.parseURI(String(document.location));
+  var value = $defined(args) && args["authrequired"];
+  return function() {
+    return value && qwebirc.auth.enabled();
+  };
+})();
+
index da3d7ca1ff8f85587e0444b441563fe0dc59a594..2571c33c758a7dfcc403355a3656506cca2ba0ee 100644 (file)
@@ -31,7 +31,7 @@ qwebirc.config.DEFAULT_OPTIONS = [
   [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
   [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
   [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true],
-  [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true, {
+  [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", false, {
     settableByURL: false
   }],
   [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true, {
index bd097b6838ee3c7869bbfbde6fd0cdc9c01653cb..f4f29df7060bf1011b1314f21fe6270a00245349 100644 (file)
@@ -2,6 +2,7 @@ from twisted.web import resource, server, static
 import config, urlparse, urllib, hashlib, re
 import qwebirc.util.rijndael, qwebirc.util.ciphers
 import qwebirc.util
+import qwebirc.util.qjson as json
 
 authgate = config.AUTHGATEPROVIDER.twisted
 BLOCK_SIZE = 128/8
@@ -35,6 +36,10 @@ class AuthgateEngine(resource.Resource):
         getSessionData(request)["qticket"] = decodeQTicket(qt)
       
       self.__hit()
+      if request.getCookie("jslogin"):
+        self.deleteCookie(request, "jslogin")
+        return """<html><head><script>window.opener.__qwebircAuthCallback(%s);</script></head></html>""" % json.dumps(ticket.username)
+
       location = request.getCookie("redirect")
       if location is None:
         location = "/"
@@ -77,4 +82,4 @@ def getSessionData(request):
   
 def login_optional(request):
   return authgate(request, config.AUTHGATEDOMAIN).login_optional()
\ No newline at end of file
index 493262b8ed1a502357b440b86c3e37a056e8297f..8ba69b0bd7aba451ba5455330dfaa5facfb26c41 100644 (file)
                   <td><label for="loginchannels">Channels:</label></td>
                   <td><input type="text" name="channels" id="loginchannels" /></td>
                 </tr>
-                <tr>
+                <tr name="connectbutton" style="display: none">
+                  <td></td>
+                  <td>
+                    <input type="submit" value="Join chat" name="connect" />
+                  </td>
+                </tr>
+                <tr name="loginbutton" style="display: none">
+                  <td></td>
+                  <td><input type="submit" value="Log in to Q" name="login" /></td>
+                </tr>
+                <tr name="loginconnectbutton" style="display: none">
+                  <td></td>
+                  <td><input type="submit" value="Join chat (Q account required)" name="loginconnect" /></td>
+                </tr>
+                <tr name="loginstatus" style="display: none">
                   <td></td>
-                  <td><input type="submit" value="Connect" name="connect" /></td>
+                  <td><small>(logged in as <b name="authname"></b>)</small></td>
+                </tr>
+                <tr name="loggingin" style="display: none">
+                  <td></td>
+                  <td><small>(waiting for you to log in...)</td>
                 </tr>
               </table>
             </form>
       <table class="qwebirc-confirmbox" style="display: none" name="confirmbox">
         <tr class="tr1">
           <td>
-            To connect to <span name="networkname"></span> IRC and join <span name="prettychannels"></span><span name="nickselected" style="display: none"> as <b name="nickname"></b></span> click 'Connect'.
+            To connect to <span name="networkname"></span> IRC and join <span name="prettychannels"></span><span name="nickselected" style="display: none"> as <b name="nickname"></b></span> click 'Join chat'.
           </td>
         </tr>
-        <tr class="tr2">
-          <td><input type="submit" value="Connect" name="connect" /></td>
+        <tr class="tr2" name="connectbutton" style="display: none">
+          <td><input type="submit" value="Join chat" name="connect" /></td>
+        </tr>
+        <tr class="tr2" name="loginbutton" style="display: none">
+          <td><input type="submit" value="Log in to Q" name="login" /></td>
+        </tr>
+        <tr class="tr2" name="loginconnectbutton" style="display: none;">
+          <td><input type="submit" value="Join chat (Q account required)" name="loginconnect" /></td>
+        </tr>
+        <tr class="tr2" name="loginstatus" style="display: none">
+          <td><small>(logged in as <b name="authname"></b>)</small></td>
+        </tr>
+        <tr class="tr2" name="loggingin" style="display: none">
+          <td><small>(waiting for you to log in...)</small></td>
         </tr>
       </table>
     </td>