Advertisement
Guest User

Register.js

a guest
Jul 8th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. import React from 'react';
  2. import { Checkbox, Button } from 'antd';
  3. import ReactDOM from 'react-dom';
  4. import NavBar from '../components/Navbar.jsx';
  5. import Footer from '../components/footer.jsx';
  6.  
  7.  
  8. import notify from "../services/notify.js";
  9. import remote from "../services/remote.js";
  10. import auth from "../services/authService.js";
  11.  
  12.  
  13.  
  14.  
  15.  
  16. export default class Register extends React.Component{
  17. state ={
  18. username:'',
  19. email:'',
  20. password:'',
  21. repeatPass: '',
  22. isAdmin: false,
  23. }
  24.  
  25. onChange = (e) =>{
  26.  
  27. if(e.target.name ==='isAdmin'){
  28. this.setState({
  29. [e.target.name]:e.target.checked,
  30. })
  31. }
  32. else {
  33. this.setState({
  34. [e.target.name]:e.target.value,
  35. })
  36. }
  37. }
  38.  
  39. onSubmit = () =>{
  40. let username = this.state.username;
  41. let email = this.state.email;
  42. let password = this.state.password;
  43. let repeatPassword = this.state.repeatPass
  44. let isAdmin = this.state.isAdmin;
  45.  
  46.  
  47. if(username.length<3){
  48. console.log("error user length < 3");
  49. }
  50. else if (password.length < 8) {
  51. console.log("error length should be < 8");
  52. }
  53. else if (password !== repeatPassword) {
  54. console.log("error password match");
  55. }
  56. else{
  57. auth.register(username, password).then((userData) => {
  58.  
  59. auth.saveSession(userData);
  60. console.log(userData);
  61. console.log("заявката проработи правилно")
  62. }).catch(console.log("влезна в catch'а"))
  63.  
  64. }
  65. }
  66.  
  67. render() {
  68. return(
  69. <div>
  70. <NavBar/>
  71.  
  72.  
  73. <center><form action="#/register" method="post" id="registerForm">
  74. <label>
  75. Username:<input type="text" name="username" onChange={e => this.onChange(e)}
  76. value={this.state.usernamel} />
  77. </label><br />
  78.  
  79.  
  80.  
  81. <label>
  82. Password:<input type="password" name="password" onChange={e => this.onChange(e)}
  83. value={this.state.password} />
  84. </label><br />
  85.  
  86. <label>
  87. Password:<input type="password" name="repeatPass" onChange={e => this.onChange(e)}
  88. value={this.state.repeatPass} />
  89. </label><br />
  90.  
  91.  
  92. {/*checkbox*/}
  93. <Checkbox name='isAdmin' checked={this.state.isAdmin} onChange={e => this.onChange(e)}>
  94. Admin?
  95. </Checkbox><br/>
  96.  
  97. {/*button*/}
  98. <Button id="btnRegister" onClick={() => this.onSubmit()} type="submit">Register</Button>
  99. </form></center><br />
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. <Footer/>
  108. </div>
  109. );
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement