Guest User

Untitled

a guest
Mar 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import { connect } from 'react-redux';
  2. import React, { Component } from 'react';
  3. import { Card, CardSection, Input, Button } from './common';
  4. import { emailChanged, passwordChanged, loginUser } from '../actions';
  5.  
  6.  
  7. class LoginForm extends Component {
  8. onEmailChange(text) {
  9. this.props.emailChanged(text);
  10. }
  11.  
  12.  
  13. onPasswordChange(text) {
  14. this.props.passwordChanged(text);
  15. }
  16. onButtonPress() {
  17. const { email, password } = this.props;
  18.  
  19. this.props.loginUser({ email, password });
  20. }
  21.  
  22. render() {
  23. return (
  24. <Card>
  25. <CardSection>
  26. <Input
  27. label="Email"
  28. placeholder="votre email ici"
  29. onChangeText={this.onEmailChange.bind(this)}
  30. value={this.props.email}
  31. />
  32. </CardSection>
  33.  
  34. <CardSection>
  35. <Input
  36. secureTextEntry
  37. label="mot de passe"
  38. placeholder="mot de passe"
  39. onChangeText={this.onPasswordChange.bind(this)}
  40. value={this.props.password}
  41. />
  42. </CardSection>
  43.  
  44. <CardSection>
  45. <Button onPress={this.onButtonPress.bind(this)}>
  46. Login
  47. </Button>
  48. </CardSection>
  49. </Card>
  50. );
  51. }
  52. }
  53.  
  54. const mapStateToProps = (state) => {
  55. return {
  56. email: state.auth.email,
  57. password: state.auth.password
  58. };
  59. };
  60.  
  61. export default connect(mapStateToProps, { emailChanged, passwordChanged,
  62. loginUser })(LoginForm);
  63.  
  64. import firebase from 'firebase';
  65.  
  66. import {
  67. EMAIL_CHANGED,
  68. PASSWORD_CHANGED,
  69. LOGIN_USER_SUCCESS
  70. } from './types';
  71.  
  72. export const emailChanged = (text) => {
  73. return {
  74. type: EMAIL_CHANGED,
  75. paymoad: text
  76. };
  77. };
  78.  
  79. export const passwordChanged = (text) => {
  80. return {
  81. type: PASSWORD_CHANGED,
  82. payload: text
  83. };
  84. };
  85.  
  86. export const loginUser = ({ email, password }) => {
  87. return (dispatch) => {
  88. firebase.auth().signInWithEmailAndPassword(email, password)
  89. .then(user => {
  90. dispatch({ type: LOGIN_USER_SUCCESS, payload: user });
  91. });
  92. };
  93. };
Add Comment
Please, Sign In to add comment