Skip to content
Snippets Groups Projects
login.js 1.76 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',
		backgroundColor: '#fff'
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
	},
	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 = {
		navigator: 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: ''
		this.props.navigator.setTitle({
			title: 'Login'
		});

		this.props.navigator.setSubTitle({
			subtitle: RocketChat.currentServer
		});
	}

	submit = () => {
		RocketChat.loginWithPassword({ username: this.state.username }, this.state.password, () => {
			this.props.navigator.dismissModal();
		});
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>