瀏覽代碼

Minor improvements around anonymous login.

You can now provide the JID of the server either via `converse.initialize` or
via `converse.user.login`.
JC Brand 9 年之前
父節點
當前提交
88d2142501
共有 1 個文件被更改,包括 11 次插入4 次删除
  1. 11 4
      src/converse-core.js

+ 11 - 4
src/converse-core.js

@@ -262,9 +262,10 @@
         if (this.prebind === true) { this.authentication = converse.PREBIND; }
 
         if (this.authentication === converse.ANONYMOUS) {
-            if (!this.jid) {
-                throw("Config Error: you need to provide the server's domain via the " +
-                        "'jid' option when using anonymous authentication.");
+            if (this.auto_login && !this.jid) {
+                throw new Error("Config Error: you need to provide the server's " +
+                      "domain via the 'jid' option when using anonymous " +
+                      "authentication with auto_login.");
             }
         }
 
@@ -1724,6 +1725,12 @@
                 this.password = credentials.password;
             }
             if (this.authentication === converse.ANONYMOUS) {
+                if (!this.jid) {
+                    throw new Error("Config Error: when using anonymous login " +
+                        "you need to provide the server's domain via the 'jid' option. " +
+                        "Either when calling converse.initialize, or when calling " +
+                        "converse.user.login.");
+                }
                 this.connection.connect(this.jid.toLowerCase(), null, this.onConnectStatusChanged);
             } else if (this.authentication === converse.LOGIN) {
                 if (!this.password) {
@@ -1772,7 +1779,7 @@
         };
 
         this.logIn = function (credentials) {
-            if (credentials) {
+            if (credentials || this.authentication === converse.ANONYMOUS) {
                 // When credentials are passed in, they override prebinding
                 // or credentials fetching via HTTP
                 this.autoLogin(credentials);