ソースを参照

Detects hosts that do not allow anonymous login and asks for credentials.

master
Damian Minkov 11年前
コミット
f4ab48092a
3個のファイルの変更51行の追加5行の削除
  1. 48
    2
      app.js
  2. 2
    2
      css/main.css
  3. 1
    1
      css/modaldialog.css

+ 48
- 2
app.js ファイルの表示

@@ -66,6 +66,11 @@ function init() {
66 66
         return;
67 67
     }
68 68
 
69
+    var jid = document.getElementById('jid').value || config.hosts.domain || window.location.hostname;
70
+    connect(jid);
71
+}
72
+
73
+function connect(jid, password) {
69 74
     connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
70 75
 
71 76
     if (nickname) {
@@ -82,9 +87,11 @@ function init() {
82 87
         connection.jingle.pc_constraints.optional.push({googIPv6: true});
83 88
     }
84 89
 
85
-    var jid = document.getElementById('jid').value || config.hosts.domain || window.location.hostname;
90
+    if(!password)
91
+        password = document.getElementById('password').value;
86 92
 
87
-    connection.connect(jid, document.getElementById('password').value, function (status) {
93
+    var anonymousConnectionFailed = false;
94
+    connection.connect(jid, password, function (status, msg) {
88 95
         if (status === Strophe.Status.CONNECTED) {
89 96
             console.log('connected');
90 97
             if (config.useStunTurn) {
@@ -98,6 +105,20 @@ function init() {
98 105
             });
99 106
 
100 107
             document.getElementById('connect').disabled = true;
108
+        } else if (status === Strophe.Status.CONNFAIL) {
109
+            if(msg === 'x-strophe-bad-non-anon-jid') {
110
+                anonymousConnectionFailed = true;
111
+            }
112
+            console.log('status', status);
113
+        } else if (status === Strophe.Status.DISCONNECTED) {
114
+            if(anonymousConnectionFailed) {
115
+                // prompt user for username and password
116
+                $(document).trigger('passwordrequired.main');
117
+            }
118
+        } else if (status === Strophe.Status.AUTHFAIL) {
119
+            // wrong password or username, prompt user
120
+            $(document).trigger('passwordrequired.main');
121
+
101 122
         } else {
102 123
             console.log('status', status);
103 124
         }
@@ -825,6 +846,31 @@ $(document).bind('passwordrequired.muc', function (event, jid) {
825 846
     });
826 847
 });
827 848
 
849
+$(document).bind('passwordrequired.main', function (event) {
850
+    console.log('password is required');
851
+
852
+    $.prompt('<h2>Password required</h2>' +
853
+        '<input id="passwordrequired.username" type="text" placeholder="user@domain.net" autofocus>' +
854
+        '<input id="passwordrequired.password" type="password" placeholder="user password">', {
855
+        persistent: true,
856
+        buttons: { "Ok": true, "Cancel": false},
857
+        defaultButton: 1,
858
+        loaded: function (event) {
859
+            document.getElementById('passwordrequired.username').focus();
860
+        },
861
+        submit: function (e, v, m, f) {
862
+            if (v) {
863
+                var username = document.getElementById('passwordrequired.username');
864
+                var password = document.getElementById('passwordrequired.password');
865
+
866
+                if (username.value !== null && password.value != null) {
867
+                    connect(username.value, password.value);
868
+                }
869
+            }
870
+        }
871
+    });
872
+});
873
+
828 874
 /**
829 875
  * Checks if video identified by given src is desktop stream.
830 876
  * @param videoSrc eg.

+ 2
- 2
css/main.css ファイルの表示

@@ -195,7 +195,7 @@ a.button:hover {
195 195
     background: #676767;
196 196
 }
197 197
 
198
-input[type='text'], textarea {
198
+input[type='text'], input[type='password'], textarea {
199 199
     display: inline-block;
200 200
     font-size: 14px;
201 201
     padding: 5px;
@@ -211,7 +211,7 @@ input[type='text'], textarea {
211 211
     resize: none; /* prevents the user-resizing, adjust to taste */
212 212
 }
213 213
 
214
-input[type='text'], textarea:focus {
214
+input[type='text'], input[type='password'], textarea:focus {
215 215
     box-shadow: inset 0 0 3px 2px #ACD8F0; /* provides a more style-able
216 216
                                          replacement to the outline */
217 217
 }

+ 1
- 1
css/modaldialog.css ファイルの表示

@@ -15,7 +15,7 @@
15 15
     margin: 10px 0;
16 16
 }
17 17
 
18
-.jqistates input[type="text"] {
18
+.jqistates input[type='text'], input[type='password'] {
19 19
     width: 100%;
20 20
 }
21 21
 

読み込み中…
キャンセル
保存