Advertisement
Guest User

Untitled

a guest
Mar 6th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. import React, { Component } from "react"
  2. import _omit from "lodash/omit"
  3. import { AvForm, AvField, AvInput } from "availity-reactstrap-validation"
  4. import axios from "axios"
  5.  
  6. class LoginForm extends Component {
  7. constructor(props) {
  8. super(props)
  9. this.state = {
  10. username: "",
  11. password: ""
  12. }
  13. ;["handleChange", "handleValidSubmit"].forEach(v => {
  14. this[v] = this[v].bind(this)
  15. })
  16. }
  17.  
  18. handleValidSubmit(event, values) {
  19. var data = [
  20. {
  21. username: this.state.username,
  22. password: this.state.password
  23. }
  24. ]
  25. this.setState(_omit(values, "loginSubmit"))
  26. axios({
  27. method: "post",
  28. url: "http://wp-cart.warungpintar.co:5001/login",
  29. headers: {
  30. "Content-Type": "application/json",
  31. key: "TUMYmAEXi22OkOnHx8fzoa3F3nR5traDRdcuBy31",
  32. "Access-Control-Allow-Origin": true
  33. },
  34. data: JSON.stringify(data)
  35. })
  36. .then(response => {
  37. if (response.status === "error") {
  38. this.setState({
  39. validataionMessage: response.message
  40. })
  41. return
  42. }
  43. this.setState({
  44. data: response
  45. })
  46. })
  47. .catch(error => {
  48. console.log(error)
  49. console.log(error.message)
  50. })
  51. }
  52.  
  53. handleChange(event) {
  54. const { target } = event
  55. const value = target.type === "checkbox" ? target.checked : target.value
  56. const { name } = target
  57.  
  58. this.setState({
  59. [name]: value
  60. })
  61. }
  62.  
  63. render() {
  64. return (
  65. <AvForm id="AvLoginForm" onValidSubmit={this.handleValidSubmit}>
  66. <div className="form-group form-group-with-icon">
  67. <AvField
  68. name="username"
  69. type="text"
  70. className="form-control"
  71. placeholder="Username"
  72. value={this.state.username}
  73. onChange={this.handleChange}
  74. validate={{
  75. required: { errorMessage: "Field ini harus diisi." }
  76. }}
  77. />
  78. <i className="icon ion-ios-person-outline" />
  79. </div>
  80.  
  81. <div className="form-group form-group-with-icon">
  82. <AvField
  83. name="password"
  84. type="password"
  85. className="form-control"
  86. placeholder="Password"
  87. value={this.state.password}
  88. onChange={this.handleChange}
  89. validate={{
  90. required: { errorMessage: "Password harus di isi." }
  91. }}
  92. />
  93. <i className="icon ion-ios-unlocked-outline" />
  94. </div>
  95.  
  96. <AvInput
  97. type="submit"
  98. name="loginSubmit"
  99. className="btn btn-block btn-outline-primary btn-outline-submit mt-4"
  100. value="MASUK"
  101. />
  102. </AvForm>
  103. )
  104. }
  105. }
  106.  
  107. export default LoginForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement