* Update screens * Update login tests * Remove done * Fix failing tests * Update screens and components * Check styles fix * Update tests * Prevent setState call after component unmounts * Add empty setButtons func to dummy navigator * Remove platform check * Remove Platform import * Update react-native-navigation version * Add separate showModalOverCurrentContext function * check-style fixes * Remove overriding of AppDelegate's window * Fix modal over current context animation * Add showSearchModal navigation action * Check-style fix * Address review comments * Update SettingsSidebar and children * Update EditProfile screen * Update SettingsSidebar * Keep track of latest componentId to appear * Track componentId in state to use in navigation actions * Update FlaggedPosts and children * Update RecentMentions * Update Settings * Store componentIds in ephemeral store * Update AttachmentButton * Remove unnecessary dismissModal * Fix typo * Check-style fix * Address review comments
179 lines
5.7 KiB
JavaScript
179 lines
5.7 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {PureComponent} from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import {
|
|
ActivityIndicator,
|
|
Image,
|
|
Keyboard,
|
|
KeyboardAvoidingView,
|
|
Platform,
|
|
StyleSheet,
|
|
TouchableWithoutFeedback,
|
|
View,
|
|
} from 'react-native';
|
|
import Button from 'react-native-button';
|
|
|
|
import {RequestStatus} from 'mattermost-redux/constants';
|
|
|
|
import ErrorText from 'app/components/error_text';
|
|
import FormattedText from 'app/components/formatted_text';
|
|
import StatusBar from 'app/components/status_bar';
|
|
import TextInputWithLocalizedPlaceholder from 'app/components/text_input_with_localized_placeholder';
|
|
import {GlobalStyles} from 'app/styles';
|
|
import {preventDoubleTap} from 'app/utils/tap';
|
|
import {t} from 'app/utils/i18n';
|
|
import {setMfaPreflightDone} from 'app/utils/security';
|
|
|
|
export default class Mfa extends PureComponent {
|
|
static propTypes = {
|
|
actions: PropTypes.shape({
|
|
login: PropTypes.func.isRequired,
|
|
popTopScreen: PropTypes.func.isRequired,
|
|
}).isRequired,
|
|
loginId: PropTypes.string.isRequired,
|
|
password: PropTypes.string.isRequired,
|
|
loginRequest: PropTypes.object.isRequired,
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
token: '',
|
|
error: null,
|
|
};
|
|
}
|
|
|
|
componentDidMount() {
|
|
if (Platform.OS === 'android') {
|
|
Keyboard.addListener('keyboardDidHide', this.handleAndroidKeyboard);
|
|
}
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
// In case the login is successful the previous scene (login) will take care of the transition
|
|
if (this.props.loginRequest.status === RequestStatus.STARTED &&
|
|
nextProps.loginRequest.status === RequestStatus.FAILURE) {
|
|
this.props.actions.popTopScreen();
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
if (Platform.OS === 'android') {
|
|
Keyboard.removeListener('keyboardDidHide', this.handleAndroidKeyboard);
|
|
}
|
|
}
|
|
|
|
handleAndroidKeyboard = () => {
|
|
this.blur();
|
|
};
|
|
|
|
handleInput = (token) => {
|
|
this.setState({
|
|
token,
|
|
error: null,
|
|
});
|
|
};
|
|
|
|
inputRef = (ref) => {
|
|
this.textInput = ref;
|
|
};
|
|
|
|
blur = () => {
|
|
this.textInput.blur();
|
|
};
|
|
|
|
submit = preventDoubleTap(() => {
|
|
Keyboard.dismiss();
|
|
if (!this.state.token) {
|
|
this.setState({
|
|
error: {
|
|
intl: {
|
|
id: t('login_mfa.tokenReq'),
|
|
defaultMessage: 'Please enter an MFA token',
|
|
},
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
setMfaPreflightDone(true);
|
|
this.props.actions.login(this.props.loginId, this.props.password, this.state.token);
|
|
});
|
|
|
|
render() {
|
|
const isLoading = this.props.loginRequest.status === RequestStatus.STARTED;
|
|
|
|
let proceed;
|
|
if (isLoading) {
|
|
proceed = (
|
|
<ActivityIndicator
|
|
animating={true}
|
|
size='small'
|
|
/>
|
|
);
|
|
} else {
|
|
proceed = (
|
|
<Button
|
|
onPress={this.submit}
|
|
loading={false}
|
|
containerStyle={GlobalStyles.signupButton}
|
|
>
|
|
<FormattedText
|
|
style={GlobalStyles.signupButtonText}
|
|
id='mobile.components.select_server_view.proceed'
|
|
defaultMessage='Proceed'
|
|
/>
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<KeyboardAvoidingView
|
|
behavior='padding'
|
|
style={style.flex}
|
|
keyboardVerticalOffset={5}
|
|
enabled={Platform.OS === 'ios'}
|
|
>
|
|
<StatusBar/>
|
|
<TouchableWithoutFeedback onPress={this.blur}>
|
|
<View style={[GlobalStyles.container, GlobalStyles.signupContainer]}>
|
|
<Image
|
|
source={require('assets/images/logo.png')}
|
|
/>
|
|
<View>
|
|
<FormattedText
|
|
style={[GlobalStyles.header, GlobalStyles.label]}
|
|
id='login_mfa.enterToken'
|
|
defaultMessage="To complete the sign in process, please enter a token from your smartphone's authenticator"
|
|
/>
|
|
</View>
|
|
<ErrorText error={this.state.error}/>
|
|
<TextInputWithLocalizedPlaceholder
|
|
ref={this.inputRef}
|
|
value={this.state.token}
|
|
onChangeText={this.handleInput}
|
|
onSubmitEditing={this.submit}
|
|
style={GlobalStyles.inputBox}
|
|
autoCapitalize='none'
|
|
autoCorrect={false}
|
|
keyboardType='numeric'
|
|
placeholder={{id: t('login_mfa.token'), defaultMessage: 'MFA Token'}}
|
|
returnKeyType='go'
|
|
underlineColorAndroid='transparent'
|
|
disableFullscreenUI={true}
|
|
/>
|
|
{proceed}
|
|
</View>
|
|
</TouchableWithoutFeedback>
|
|
</KeyboardAvoidingView>
|
|
);
|
|
}
|
|
}
|
|
|
|
const style = StyleSheet.create({
|
|
flex: {
|
|
flex: 1,
|
|
},
|
|
});
|