123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- /* global $, APP, config */
-
- import { toJid } from '../../../react/features/base/connection/functions';
- import {
- JitsiConnectionErrors
- } from '../../../react/features/base/lib-jitsi-meet';
-
- /**
- * Build html for "password required" dialog.
- * @returns {string} html string
- */
- function getPasswordInputHtml() {
- const placeholder = config.hosts.authdomain
- ? 'user identity'
- : 'user@domain.net';
-
- return `
- <input name="username" type="text"
- class="input-control"
- data-i18n="[placeholder]dialog.user"
- placeholder=${placeholder} autofocus>
- <input name="password" type="password"
- class="input-control"
- data-i18n="[placeholder]dialog.userPassword">`;
- }
-
- /**
- * Generate cancel button config for the dialog.
- * @returns {Object}
- */
- function cancelButton() {
- return {
- title: APP.translation.generateTranslationHTML('dialog.Cancel'),
- value: false
- };
- }
-
- /**
- * Auth dialog for JitsiConnection which supports retries.
- * If no cancelCallback provided then there will be
- * no cancel button on the dialog.
- *
- * @class LoginDialog
- * @constructor
- *
- * @param {function(jid, password)} successCallback
- * @param {function} [cancelCallback] callback to invoke if user canceled.
- */
- function LoginDialog(successCallback, cancelCallback) {
- const loginButtons = [ {
- title: APP.translation.generateTranslationHTML('dialog.Ok'),
- value: true
- } ];
- const finishedButtons = [ {
- title: APP.translation.generateTranslationHTML('dialog.retry'),
- value: 'retry'
- } ];
-
- // show "cancel" button only if cancelCallback provided
- if (cancelCallback) {
- loginButtons.push(cancelButton());
- finishedButtons.push(cancelButton());
- }
-
- const states = {
- login: {
- buttons: loginButtons,
- focus: ':input:first',
- html: getPasswordInputHtml(),
- titleKey: 'dialog.passwordRequired',
-
- submit(e, v, m, f) { // eslint-disable-line max-params
- e.preventDefault();
- if (v) {
- const jid = f.username;
- const password = f.password;
-
- if (jid && password) {
- // eslint-disable-next-line no-use-before-define
- connDialog.goToState('connecting');
- successCallback(toJid(jid, config.hosts), password);
- }
- } else {
- // User cancelled
- cancelCallback();
- }
- }
- },
- connecting: {
- buttons: [],
- defaultButton: 0,
- html: '<div id="connectionStatus"></div>',
- titleKey: 'dialog.connecting'
- },
- finished: {
- buttons: finishedButtons,
- defaultButton: 0,
- html: '<div id="errorMessage"></div>',
- titleKey: 'dialog.error',
-
- submit(e, v) {
- e.preventDefault();
- if (v === 'retry') {
- // eslint-disable-next-line no-use-before-define
- connDialog.goToState('login');
- } else {
- // User cancelled
- cancelCallback();
- }
- }
- }
- };
- const connDialog = APP.UI.messageHandler.openDialogWithStates(
- states,
- {
- closeText: '',
- persistent: true,
- zIndex: 1020
- },
- null
- );
-
- /**
- * Displays error message in 'finished' state which allows either to cancel
- * or retry.
- * @param error the key to the error to be displayed.
- * @param options the options to the error message (optional)
- */
- this.displayError = function(error, options) {
-
- const finishedState = connDialog.getState('finished');
-
- const errorMessageElem = finishedState.find('#errorMessage');
-
- let messageKey;
-
- if (error === JitsiConnectionErrors.PASSWORD_REQUIRED) {
- // this is a password required error, as login window was already
- // open once, this means username or password is wrong
- messageKey = 'dialog.incorrectPassword';
- } else {
- messageKey = 'dialog.connectErrorWithMsg';
-
- if (!options) {
- options = {};// eslint-disable-line no-param-reassign
- }
-
- options.msg = error;
- }
-
- errorMessageElem.attr('data-i18n', messageKey);
-
- APP.translation.translateElement($(errorMessageElem), options);
-
- connDialog.goToState('finished');
- };
-
- /**
- * Show message as connection status.
- * @param {string} messageKey the key to the message
- */
- this.displayConnectionStatus = function(messageKey) {
- const connectingState = connDialog.getState('connecting');
-
- const connectionStatus = connectingState.find('#connectionStatus');
-
- connectionStatus.attr('data-i18n', messageKey);
- APP.translation.translateElement($(connectionStatus));
- };
-
- /**
- * Closes LoginDialog.
- */
- this.close = function() {
- connDialog.close();
- };
- }
-
- export default {
-
- /**
- * Show new auth dialog for JitsiConnection.
- *
- * @param {function(jid, password)} successCallback
- * @param {function} [cancelCallback] callback to invoke if user canceled.
- *
- * @returns {LoginDialog}
- */
- showAuthDialog(successCallback, cancelCallback) {
- return new LoginDialog(successCallback, cancelCallback);
- },
-
- /**
- * Show notification that external auth is required (using provided url).
- * @param {string} url URL to use for external auth.
- * @param {function} callback callback to invoke when auth popup is closed.
- * @returns auth dialog
- */
- showExternalAuthDialog(url, callback) {
- const dialog = APP.UI.messageHandler.openCenteredPopup(
- url, 910, 660,
-
- // On closed
- callback
- );
-
- if (!dialog) {
- APP.UI.messageHandler.showWarning({
- descriptionKey: 'dialog.popupError',
- titleKey: 'dialog.popupErrorTitle'
- });
- }
-
- return dialog;
- }
- };
|