Guest User

Untitled

a guest
Dec 5th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import fire from '../fire';
  3. import ShowProfile from './showprofile';
  4.  
  5. export default class Register extends Component{
  6.  
  7. constructor(props){
  8. super(props);
  9. this.state = {
  10. email : '',
  11. password : '',
  12. errorLogin : '',
  13. successLogin : false,
  14. }
  15. }
  16.  
  17. register = (event) => {
  18. event.preventDefault();
  19. const email = this.state.email;
  20. const password = this.state.password;
  21. fire.auth()
  22. .createUserWithEmailAndPassword(email, password)
  23. .then((result) => {
  24. var user = fire.auth().currentUser;
  25. if (user != null) {
  26. this.setState({successLogin: true})
  27. user.providerData.forEach(function (profile) {
  28. this.setState({email: profile.email})
  29. console.log(" Provider-specific UID: " + profile.uid);
  30. console.log(" Email: " + profile.email);
  31. });
  32. }
  33. })
  34. .catch((error) => {
  35. this.setState({errorLogin:error.message})
  36. });
  37. }
  38.  
  39. inputHandle = (event) => {
  40. const name = event.target.name;
  41. const value = event.target.value;
  42. this.setState({[name]: value, errorLogin: ''})
  43. }
  44.  
  45. render(){
  46. if(this.state.successLogin === true){
  47. return(
  48. <div className="container">
  49. <ShowProfile email={this.state.email}/>
  50. </div>
  51. )
  52. }
  53. return(
  54. <div className="container">
  55. <div className="col-md-5" style={{"margin": "auto"}}>
  56. <form onSubmit={this.register}>
  57. <h2 className="form-group">Register</h2>
  58. <h5 className="form-group text-danger" id="errorLogin">{ this.state.errorLogin }</h5>
  59. <div className="form-group">
  60. <input type="email"
  61. className="form-control"
  62. id="email"
  63. name="email"
  64. aria-describedby="emailHelp"
  65. placeholder="Enter email"
  66. onChange={(event) => { this.inputHandle(event) }}/>
  67. </div>
  68. <div className="form-group">
  69. <input type="password"
  70. className="form-control"
  71. id="password"
  72. name="password"
  73. placeholder="Password"
  74. onChange={(event) => { this.setState({password: event.target.value}) }}/>
  75. </div>
  76. <button type="submit" className="btn btn-primary">Submit</button>
  77. </form>
  78. </div>
  79. </div>
  80. )
  81. }
  82. }
Add Comment
Please, Sign In to add comment