|
@@ -1,35 +1,19 @@
|
1
|
1
|
/* global $, APP, config*/
|
2
|
2
|
|
3
|
|
-var XMPP = require('../../xmpp/xmpp');
|
4
|
|
-var Moderator = require('../../xmpp/moderator');
|
|
3
|
+var messageHandler = require('../util/MessageHandler');
|
5
|
4
|
|
6
|
5
|
//FIXME: use LoginDialog to add retries to XMPP.connect method used when
|
7
|
6
|
// anonymous domain is not enabled
|
8
|
7
|
|
9
|
|
-/**
|
10
|
|
- * Creates new <tt>Dialog</tt> instance.
|
11
|
|
- * @param callback <tt>function(Strophe.Connection, Strophe.Status)</tt> called
|
12
|
|
- * when we either fail to connect or succeed(check Strophe.Status).
|
13
|
|
- * @param obtainSession <tt>true</tt> if we want to send ConferenceIQ to Jicofo
|
14
|
|
- * in order to create session-id after the connection is established.
|
15
|
|
- * @constructor
|
16
|
|
- */
|
17
|
|
-function Dialog(callback, obtainSession) {
|
18
|
|
-
|
19
|
|
- var self = this;
|
20
|
|
-
|
21
|
|
- var stop = false;
|
22
|
|
-
|
23
|
|
- var connection = APP.xmpp.createConnection();
|
24
|
|
-
|
|
8
|
+function Dialog(successCallback, cancelCallback) {
|
25
|
9
|
var message = '<h2 data-i18n="dialog.passwordRequired">';
|
26
|
10
|
message += APP.translation.translateString("dialog.passwordRequired");
|
27
|
11
|
message += '</h2>' +
|
28
|
12
|
'<input name="username" type="text" ';
|
29
|
13
|
if (config.hosts.authdomain) {
|
30
|
|
- message += 'placeholder="user identity" autofocus>';
|
|
14
|
+ message += 'placeholder="user identity" autofocus>';
|
31
|
15
|
} else {
|
32
|
|
- message += 'placeholder="user@domain.net" autofocus>';
|
|
16
|
+ message += 'placeholder="user@domain.net" autofocus>';
|
33
|
17
|
}
|
34
|
18
|
message += '<input name="password" ' +
|
35
|
19
|
'type="password" data-i18n="[placeholder]dialog.userPassword"' +
|
|
@@ -53,23 +37,12 @@ function Dialog(callback, obtainSession) {
|
53
|
37
|
var jid = f.username;
|
54
|
38
|
var password = f.password;
|
55
|
39
|
if (jid && password) {
|
56
|
|
- stop = false;
|
57
|
|
- if (jid.indexOf("@") < 0) {
|
58
|
|
- jid = jid.concat('@');
|
59
|
|
- if (config.hosts.authdomain) {
|
60
|
|
- jid += config.hosts.authdomain;
|
61
|
|
- } else {
|
62
|
|
- jid += config.hosts.domain;
|
63
|
|
- }
|
64
|
|
- }
|
65
|
|
- connection.reset();
|
66
|
40
|
connDialog.goToState('connecting');
|
67
|
|
- connection.connect(jid, password, stateHandler);
|
|
41
|
+ successCallback(jid, password);
|
68
|
42
|
}
|
69
|
43
|
} else {
|
70
|
44
|
// User cancelled
|
71
|
|
- stop = true;
|
72
|
|
- callback();
|
|
45
|
+ cancelCallback();
|
73
|
46
|
}
|
74
|
47
|
}
|
75
|
48
|
},
|
|
@@ -95,102 +68,18 @@ function Dialog(callback, obtainSession) {
|
95
|
68
|
defaultButton: 0,
|
96
|
69
|
submit: function (e, v, m, f) {
|
97
|
70
|
e.preventDefault();
|
98
|
|
- if (v === 'retry')
|
|
71
|
+ if (v === 'retry') {
|
99
|
72
|
connDialog.goToState('login');
|
100
|
|
- else
|
101
|
|
- callback();
|
|
73
|
+ } else {
|
|
74
|
+ cancelCallback();
|
|
75
|
+ }
|
102
|
76
|
}
|
103
|
77
|
}
|
104
|
78
|
};
|
105
|
79
|
|
106
|
|
- var connDialog
|
107
|
|
- = APP.UI.messageHandler.openDialogWithStates(states,
|
108
|
|
- { persistent: true, closeText: '' }, null);
|
109
|
|
-
|
110
|
|
- var stateHandler = function (status, message) {
|
111
|
|
- if (stop) {
|
112
|
|
- return;
|
113
|
|
- }
|
114
|
|
-
|
115
|
|
- var translateKey = "connection." + XMPP.getStatusString(status);
|
116
|
|
- var statusStr = APP.translation.translateString(translateKey);
|
117
|
|
-
|
118
|
|
- // Display current state
|
119
|
|
- var connectionStatus =
|
120
|
|
- connDialog.getState('connecting').find('#connectionStatus');
|
121
|
|
-
|
122
|
|
- connectionStatus.text(statusStr);
|
123
|
|
-
|
124
|
|
- switch (status) {
|
125
|
|
- case XMPP.Status.CONNECTED:
|
126
|
|
-
|
127
|
|
- stop = true;
|
128
|
|
- if (!obtainSession) {
|
129
|
|
- callback(connection, status);
|
130
|
|
- return;
|
131
|
|
- }
|
132
|
|
- // Obtaining session-id status
|
133
|
|
- connectionStatus.text(
|
134
|
|
- APP.translation.translateString(
|
135
|
|
- 'connection.FETCH_SESSION_ID'));
|
136
|
|
-
|
137
|
|
- // Authenticate with Jicofo and obtain session-id
|
138
|
|
- var roomName = APP.conference.roomName;
|
139
|
|
-
|
140
|
|
- // Jicofo will return new session-id when connected
|
141
|
|
- // from authenticated domain
|
142
|
|
- connection.sendIQ(
|
143
|
|
- Moderator.createConferenceIq(roomName),
|
144
|
|
- function (result) {
|
145
|
|
-
|
146
|
|
- connectionStatus.text(
|
147
|
|
- APP.translation.translateString(
|
148
|
|
- 'connection.GOT_SESSION_ID'));
|
149
|
|
-
|
150
|
|
- stop = true;
|
151
|
|
-
|
152
|
|
- // Parse session-id
|
153
|
|
- Moderator.parseSessionId(result);
|
154
|
|
-
|
155
|
|
- callback(connection, status);
|
156
|
|
- },
|
157
|
|
- function (error) {
|
158
|
|
- console.error("Auth on the fly failed", error);
|
159
|
|
-
|
160
|
|
- stop = true;
|
161
|
|
-
|
162
|
|
- var errorMsg =
|
163
|
|
- APP.translation.translateString(
|
164
|
|
- 'connection.GET_SESSION_ID_ERROR') +
|
165
|
|
- $(error).find('>error').attr('code');
|
166
|
|
-
|
167
|
|
- self.displayError(errorMsg);
|
168
|
|
-
|
169
|
|
- connection.disconnect();
|
170
|
|
- });
|
171
|
|
-
|
172
|
|
- break;
|
173
|
|
- case XMPP.Status.AUTHFAIL:
|
174
|
|
- case XMPP.Status.CONNFAIL:
|
175
|
|
- case XMPP.Status.DISCONNECTED:
|
176
|
|
-
|
177
|
|
- stop = true;
|
178
|
|
-
|
179
|
|
- callback(connection, status);
|
180
|
|
-
|
181
|
|
- var errorMessage = statusStr;
|
182
|
|
-
|
183
|
|
- if (message)
|
184
|
|
- {
|
185
|
|
- errorMessage += ': ' + message;
|
186
|
|
- }
|
187
|
|
- self.displayError(errorMessage);
|
188
|
|
-
|
189
|
|
- break;
|
190
|
|
- default:
|
191
|
|
- break;
|
192
|
|
- }
|
193
|
|
- };
|
|
80
|
+ var connDialog = messageHandler.openDialogWithStates(
|
|
81
|
+ states, { persistent: true, closeText: '' }, null
|
|
82
|
+ );
|
194
|
83
|
|
195
|
84
|
/**
|
196
|
85
|
* Displays error message in 'finished' state which allows either to cancel
|
|
@@ -211,7 +100,6 @@ function Dialog(callback, obtainSession) {
|
211
|
100
|
* Closes LoginDialog.
|
212
|
101
|
*/
|
213
|
102
|
this.close = function () {
|
214
|
|
- stop = true;
|
215
|
103
|
connDialog.close();
|
216
|
104
|
};
|
217
|
105
|
}
|
|
@@ -232,8 +120,22 @@ var LoginDialog = {
|
232
|
120
|
* established.
|
233
|
121
|
* @returns {Dialog}
|
234
|
122
|
*/
|
235
|
|
- show: function (callback, obtainSession) {
|
236
|
|
- return new Dialog(callback, obtainSession);
|
|
123
|
+ show: function (successCallback, cancelCallback) {
|
|
124
|
+ return new Dialog(successCallback, cancelCallback);
|
|
125
|
+ },
|
|
126
|
+
|
|
127
|
+ showExternalAuthDialog: function (url, callback) {
|
|
128
|
+ var dialog = messageHandler.openCenteredPopup(
|
|
129
|
+ url, 910, 660,
|
|
130
|
+ // On closed
|
|
131
|
+ callback
|
|
132
|
+ );
|
|
133
|
+
|
|
134
|
+ if (!dialog) {
|
|
135
|
+ messageHandler.openMessageDialog(null, "dialog.popupError");
|
|
136
|
+ }
|
|
137
|
+
|
|
138
|
+ return dialog;
|
237
|
139
|
}
|
238
|
140
|
};
|
239
|
141
|
|