Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { connect } from 'react-redux';
- import React, { Component } from 'react';
- import { Card, CardSection, Input, Button } from './common';
- import { emailChanged, passwordChanged, loginUser } from '../actions';
- class LoginForm extends Component {
- onEmailChange(text) {
- this.props.emailChanged(text);
- }
- onPasswordChange(text) {
- this.props.passwordChanged(text);
- }
- onButtonPress() {
- const { email, password } = this.props;
- this.props.loginUser({ email, password });
- }
- render() {
- return (
- <Card>
- <CardSection>
- <Input
- label="Email"
- placeholder="votre email ici"
- onChangeText={this.onEmailChange.bind(this)}
- value={this.props.email}
- />
- </CardSection>
- <CardSection>
- <Input
- secureTextEntry
- label="mot de passe"
- placeholder="mot de passe"
- onChangeText={this.onPasswordChange.bind(this)}
- value={this.props.password}
- />
- </CardSection>
- <CardSection>
- <Button onPress={this.onButtonPress.bind(this)}>
- Login
- </Button>
- </CardSection>
- </Card>
- );
- }
- }
- const mapStateToProps = (state) => {
- return {
- email: state.auth.email,
- password: state.auth.password
- };
- };
- export default connect(mapStateToProps, { emailChanged, passwordChanged,
- loginUser })(LoginForm);
- import firebase from 'firebase';
- import {
- EMAIL_CHANGED,
- PASSWORD_CHANGED,
- LOGIN_USER_SUCCESS
- } from './types';
- export const emailChanged = (text) => {
- return {
- type: EMAIL_CHANGED,
- paymoad: text
- };
- };
- export const passwordChanged = (text) => {
- return {
- type: PASSWORD_CHANGED,
- payload: text
- };
- };
- export const loginUser = ({ email, password }) => {
- return (dispatch) => {
- firebase.auth().signInWithEmailAndPassword(email, password)
- .then(user => {
- dispatch({ type: LOGIN_USER_SUCCESS, payload: user });
- });
- };
- };
Add Comment
Please, Sign In to add comment