Skip to content
Snippets Groups Projects
login.js 1.63 KiB
Newer Older
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
import React from 'react';
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
import PropTypes from 'prop-types';
import { TextInput, StyleSheet } from 'react-native';
import RocketChat from '../lib/rocketchat';
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed

import KeyboardView from '../components/KeyboardView';

Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
const styles = StyleSheet.create({
	view: {
		flex: 1,
		flexDirection: 'column',
		justifyContent: 'center',
		alignItems: 'stretch'
	},
	input: {
		height: 40,
		borderColor: '#aaa',
		marginLeft: 20,
		marginRight: 20,
		marginTop: 10,
		padding: 5,
		borderWidth: 0,
		backgroundColor: '#f6f6f6'
	}
});

Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
export default class LoginView extends React.Component {
	static propTypes = {
		navigation: PropTypes.object.isRequired
	}

Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
	static navigationOptions = () => ({
		title: 'Login'
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
	});

	constructor(props) {
		super(props);

		this.state = {
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
			username: '',
			password: ''
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
		this.submit = () => {
			RocketChat.loginWithPassword({ username: this.state.username }, this.state.password, () => {
				this.props.navigation.dispatch({ type: 'Navigation/BACK' });
			});
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
		};
	}

	render() {
		return (
			<KeyboardView style={styles.view}>
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
				<TextInput
					style={styles.input}
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
					onChangeText={username => this.setState({ username })}
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
					keyboardType='email-address'
					autoCorrect={false}
					returnKeyType='done'
					autoCapitalize='none'
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
					autoFocus
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
					onSubmitEditing={this.submit}
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
					placeholder='Email or username'
				/>
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
				<TextInput
					style={styles.input}
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
					onChangeText={password => this.setState({ password })}
					secureTextEntry
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
					autoCorrect={false}
					returnKeyType='done'
					autoCapitalize='none'
					onSubmitEditing={this.submit}
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
					placeholder='Password'
				/>
			</KeyboardView>