Преглед изворни кода

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
         return;
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
     connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
74
     connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
70
 
75
 
71
     if (nickname) {
76
     if (nickname) {
82
         connection.jingle.pc_constraints.optional.push({googIPv6: true});
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
         if (status === Strophe.Status.CONNECTED) {
95
         if (status === Strophe.Status.CONNECTED) {
89
             console.log('connected');
96
             console.log('connected');
90
             if (config.useStunTurn) {
97
             if (config.useStunTurn) {
98
             });
105
             });
99
 
106
 
100
             document.getElementById('connect').disabled = true;
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
         } else {
122
         } else {
102
             console.log('status', status);
123
             console.log('status', status);
103
         }
124
         }
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
  * Checks if video identified by given src is desktop stream.
875
  * Checks if video identified by given src is desktop stream.
830
  * @param videoSrc eg.
876
  * @param videoSrc eg.

+ 2
- 2
css/main.css Прегледај датотеку

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

+ 1
- 1
css/modaldialog.css Прегледај датотеку

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

Loading…
Откажи
Сачувај