Newer
Older
import { Text, TextInput, StyleSheet } from 'react-native';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
// import * as actions from '../actions';
import * as loginActions from '../actions/login';
import KeyboardView from '../components/KeyboardView';
const styles = StyleSheet.create({
view: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'stretch',
backgroundColor: '#fff'
},
input: {
height: 40,
borderColor: '#aaa',
marginLeft: 20,
marginRight: 20,
marginTop: 10,
padding: 5,
borderWidth: 0,
backgroundColor: '#f6f6f6'
},
error: {
textAlign: 'center',
color: 'red',
paddingTop: 5
server: PropTypes.string.isRequired,
Accounts_EmailOrUsernamePlaceholder: PropTypes.string,
Accounts_PasswordPlaceholder: PropTypes.string
});
constructor(props) {
super(props);
this.state = {
this.props.navigator.setTitle({
title: 'Login'
});
this.props.navigator.setSubTitle({
const { username, password, code } = this.state;
this.props.loginRequest({ username, password, code });
//
//
// this.setState({
// error: undefined
// });
//
//
// RocketChat.loginWithPassword(credentials, (error) => {
// if (error) {
// if (error.error === 'totp-required') {
// this.setState({ totp: true });
// this.codeInput.focus();
// } else {
// this.setState({
// error: error.reason
// });
// }
// } else {
// this.props.navigator.dismissModal();
// }
// });
renderTOTP = () => {
if (this.state.totp) {
return (
<TextInput
ref={ref => this.codeInput = ref}
style={styles.input}
onChangeText={code => this.setState({ code })}
keyboardType='numeric'
autoCorrect={false}
returnKeyType='done'
autoCapitalize='none'
onSubmitEditing={this.submit}
placeholder='Code'
/>
);
}
}
<KeyboardView style={styles.view} keyboardVerticalOffset={64}>
{this.props.login.isFetching && <Text> LOGANDO</Text>}
onChangeText={username => this.setState({ username })}
keyboardType='email-address'
autoCorrect={false}
returnKeyType='done'
autoCapitalize='none'
placeholder={this.props.Accounts_EmailOrUsernamePlaceholder || 'Email or username'}
onChangeText={password => this.setState({ password })}
secureTextEntry
autoCorrect={false}
returnKeyType='done'
autoCapitalize='none'
onSubmitEditing={this.submit}
placeholder={this.props.Accounts_PasswordPlaceholder || 'Password'}
{this.renderTOTP()}
<Text style={styles.error}>{this.state.error}</Text>
function mapStateToProps(state) {
return {
server: state.server,
Accounts_EmailOrUsernamePlaceholder: state.settings.Accounts_EmailOrUsernamePlaceholder,
Accounts_PasswordPlaceholder: state.settings.Accounts_PasswordPlaceholder,
login: state.default
};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(loginActions, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(LoginView);