import React, { Component } from 'react'; import { connect as reduxConnect } from 'react-redux'; import { Button, Modal, Text, TextInput, View } from 'react-native'; import { authenticateAndUpgradeRole, cancelLogin } from '../actions'; import { connect, toJid } from '../../base/connection'; import { translate } from '../../base/i18n'; import { JitsiConnectionErrors } from '../../base/lib-jitsi-meet'; import styles from './styles'; /** * Dialog asks user for username and password. * * First authentication configuration that it will deal with is the main XMPP * domain (config.hosts.domain) with password authentication. A LoginDialog * will be opened after 'CONNECTION_FAILED' action with * 'JitsiConnectionErrors.PASSWORD_REQUIRED' error. After username and password * are entered a new 'connect' action from 'features/base/connection' will be * triggered which will result in new XMPP connection. The conference will start * if the credentials are correct. * * The second setup is the main XMPP domain with password plus guest domain with * anonymous access configured under 'config.hosts.anonymousdomain'. In such * case user connects from the anonymous domain, but if the room does not exist * yet, Jicofo will not allow to start new conference. This will trigger * 'CONFERENCE_FAILED' action with JitsiConferenceErrors.AUTHENTICATION_REQUIRED * error and 'authRequired' value of 'features/base/conference' will hold * the {@link JitsiConference} instance. If user decides to authenticate a new * {@link JitsiAuthConnection} will be created from which separate XMPP * connection is established and authentication is performed. In case it * succeeds Jicofo will assign new session ID which then can be used from * the anonymous domain connection to create and join the room. This part is * done by {@link JitsiAuthConnection} from lib-jitsi-meet. * * See https://github.com/jitsi/jicofo#secure-domain for configuration * parameters description. */ class LoginDialog extends Component { /** * LoginDialog component's property types. * * @static */ static propTypes = { /** * {@link JitsiConference} that needs authentication - will hold a valid * value in XMPP login + guest access mode. */ conference: React.PropTypes.object, /** * */ configHosts: React.PropTypes.object, /** * Indicates if the dialog should display "connecting" status message. */ connecting: React.PropTypes.bool, /** * Redux store dispatch method. */ dispatch: React.PropTypes.func, /** * The error which occurred during login/authentication. */ error: React.PropTypes.string, /** * Any extra details about the error provided by lib-jitsi-meet. */ errorDetails: React.PropTypes.string, /** * Invoked to obtain translated strings. */ t: React.PropTypes.func }; /** * Initializes a new LoginDialog instance. * * @param {Object} props - The read-only properties with which the new * instance is to be initialized. */ constructor(props) { super(props); // Bind event handlers so they are only bound once for every instance. this._onCancel = this._onCancel.bind(this); this._onLogin = this._onLogin.bind(this); this._onUsernameChange = this._onUsernameChange.bind(this); this._onPasswordChange = this._onPasswordChange.bind(this); this.state = { username: '', password: '' }; } /** * Implements React's {@link Component#render()}. * * @inheritdoc * @returns {ReactElement} */ render() { const { error, errorDetails, connecting, t } = this.props; let messageKey = ''; const messageOptions = { }; if (error === JitsiConnectionErrors.PASSWORD_REQUIRED) { messageKey = 'dialog.incorrectPassword'; } else if (error) { messageKey = 'dialog.connectErrorWithMsg'; messageOptions.msg = `${error} ${errorDetails}`; } return ( Username: Password: {error ? t(messageKey, messageOptions) : ''} {connecting && !error ? t('connection.CONNECTING') : ''}