Guest User

Untitled

a guest
Feb 13th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. <?php
  2.  
  3. Route::post('register','UserController@register');
  4. Route::post('login','UserController@login');
  5. Route::post('profile','UserController@getAuthenticatedUser');
  6.  
  7. Route::middleware('auth:api')->get('/user', function(Request $request){
  8. return $request->user();
  9. });
  10.  
  11. ?>
  12.  
  13. import React, { Component } from 'react';
  14. import { register } from './UserFunctions';
  15.  
  16. class Register extends Component {
  17. constructor() {
  18. super()
  19.  
  20. this.state = {
  21. first_name: '',
  22. last_name: '',
  23. email: '',
  24. password: '',
  25. errors: {},
  26. }
  27.  
  28. this.onChange = this.onChange.bind(this)
  29. this.onSubmit = this.onSubmit.bind(this)
  30. }
  31.  
  32. onChange(e) {
  33. this.setState({ [e.target.name]: e.target.value })
  34. }
  35.  
  36. onSubmit(e) {
  37. e.preventDefault()
  38.  
  39. const newUser = {
  40. name: this.state.first_name + ' ' + this.state.last_name,
  41. email: this.state.email,
  42. password: this.state.password
  43. }
  44.  
  45. register(newUser).then(res => {
  46. if (res) {
  47. this.props.history.push('/login')
  48. }
  49. })
  50. }
  51.  
  52. render() {
  53. return (
  54. <div className="container">
  55. <div className="row">
  56. <div className="col-md-6 mt-5 mx auto">
  57. <form noValidate onSubmit={this.onSubmit}>
  58. <h1 className="h3 mb-3 font-wieght-normal">
  59. Register
  60. </h1>
  61.  
  62. <div className="form-group">
  63.  
  64. <label htmlFor="first_name">First Name</label>
  65. <input type="text" className="form-control" name="first_name" placeholder="Enter First Name" value={this.state.first_name} onChange={this.onChange} />
  66.  
  67. <label htmlFor="last_name">Last Name</label>
  68. <input type="text" className="form-control" name="last_name" placeholder="Enter Last Name" value={this.state.last_name} onChange={this.onChange} />
  69.  
  70. <label htmlFor="email">Email Address</label><br />
  71. <input type="email" className="form-control" name="email" placeholder="Enter Email" value={this.state.email} onChange={this.onChange} />
  72. <br />
  73. <label htmlFor="password">Desired Password</label><br />
  74. <input type="password" className="form-control" name="password" placeholder="Enter Password" value={this.state.password} onChange={this.onChange} />
  75. </div>
  76. <button type="submit" className="btn btn-lg btn-primary btn-block">Register</button>
  77. </form>
  78. </div>
  79. </div>
  80. </div>
  81. )
  82. }
  83. }
  84.  
  85. export default Register
Add Comment
Please, Sign In to add comment