11import React from 'react' ;
22
3- class HomeComponent extends React . Component {
4- constructor ( props ) {
5- super ( props ) ;
3+ import iClientUser from './../../services/iClientUser' ;
4+
5+ class LoginComponent extends React . Component {
6+ constructor ( props , context ) {
7+ super ( props , context ) ;
8+ this . handleSubmit = this . handleSubmit . bind ( this ) ;
9+ }
10+
11+ handleSubmit ( e ) {
12+ e . preventDefault ( ) ;
13+
14+ iClientUser . login (
15+ this . refs . username . value ,
16+ this . refs . password . value
17+ ) . then ( ( response ) => {
18+ localStorage . token = response . data . token ;
19+ window . location . href = "/" ;
20+ } ) ;
21+ console . log ( this . refs . username . value ) ;
22+ console . log ( this . refs . password . value ) ;
623 }
724
825 render ( ) {
@@ -17,18 +34,27 @@ class HomeComponent extends React.Component{
1734 </ h1 >
1835 < form onSubmit = { this . handleSubmit } >
1936 < div className = "box" >
20- < label className = "label" > Email </ label >
37+ < label className = "label" > Username </ label >
2138 < p className = "control" >
22- < input className = "input" type = "text" placeholder = "[email protected] " /> 39+ < input
40+ ref = 'username'
41+ className = "input"
42+ type = "text"
43+ placeholder = "Ex: jsmith"
44+ />
2345 </ p >
2446 < label className = "label" > Password</ label >
2547 < p className = "control" >
26- < input className = "input" type = "password" placeholder = "●●●●●●●" />
48+ < input
49+ ref = 'password'
50+ className = "input"
51+ type = "password"
52+ placeholder = "●●●●●●●"
53+ />
2754 </ p >
2855 < hr />
2956 < p className = "control" >
3057 < button className = "button is-primary" > Login</ button >
31- < button className = "button is-default" > Cancel</ button >
3258 </ p >
3359 < p className = "has-text-centered" >
3460 < a href = "register.html" > Register an Account</ a >
@@ -46,4 +72,4 @@ class HomeComponent extends React.Component{
4672 }
4773}
4874
49- export default HomeComponent ;
75+ export default LoginComponent ;
0 commit comments