@@ -19,18 +19,19 @@ import Checkbox from '@material-ui/core/Checkbox';
19
19
import Link from '@material-ui/core/Link' ;
20
20
import Grid from '@material-ui/core/Grid' ;
21
21
import Box from '@material-ui/core/Box' ;
22
- import LockOutlinedIcon from '@material-ui/icons/LockOutlined' ;
23
22
import Typography from '@material-ui/core/Typography' ;
24
23
import { makeStyles , withStyles } from '@material-ui/core/styles' ;
25
24
import Container from '@material-ui/core/Container' ;
25
+ import GitHubIcon from '@material-ui/icons/GitHub' ;
26
+ import LockOutlinedIcon from '@material-ui/icons/LockOutlined' ;
26
27
27
28
function Copyright ( ) {
28
29
return (
29
30
< Typography variant = "body2" color = "textSecondary" align = "center" >
30
- { 'Copyright © ' }
31
- < Link color = "inherit" href = "https://material-ui.com/ " >
31
+ { 'Copyright © ReacType ' }
32
+ { /* <Link color="inherit" href="https://reactype.io/#fullCarousel ">
32
33
ReacType
33
- </ Link > { ' ' }
34
+ </Link>{' '} */ }
34
35
{ new Date ( ) . getFullYear ( ) }
35
36
{ '.' }
36
37
</ Typography >
@@ -42,20 +43,31 @@ const useStyles = makeStyles(theme => ({
42
43
marginTop : theme . spacing ( 8 ) ,
43
44
display : 'flex' ,
44
45
flexDirection : 'column' ,
45
- alignItems : 'center'
46
+ alignItems : 'center' ,
46
47
} ,
47
48
avatar : {
48
49
margin : theme . spacing ( 1 ) ,
49
- backgroundColor : theme . palette . secondary . main
50
+ backgroundColor : '#3EC1AC'
50
51
} ,
51
52
form : {
52
53
width : '100%' , // Fix IE 11 issue.
53
54
marginTop : theme . spacing ( 1 )
54
55
} ,
55
56
submit : {
56
- margin : theme . spacing ( 3 , 0 , 2 ) ,
57
- width : '240px' ,
58
- height : '60px'
57
+ margin : theme . spacing ( 1 , 0 , 2 ) ,
58
+ // width: '240px',
59
+ // height: '60px'
60
+ } ,
61
+ root : {
62
+ // "& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
63
+ // borderColor: "green"
64
+ // },
65
+ // "&:hover .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
66
+ // borderColor: "red"
67
+ // },
68
+ "& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline" : {
69
+ borderColor : "#3EC1AC"
70
+ }
59
71
}
60
72
} ) ) ;
61
73
@@ -67,6 +79,11 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
67
79
const [ username , setUsername ] = useState ( '' ) ;
68
80
const [ password , setPassword ] = useState ( '' ) ;
69
81
82
+ const [ invalidUserMsg , setInvalidUserMsg ] = useState ( '' ) ;
83
+ const [ invalidPassMsg , setInvalidPassMsg ] = useState ( '' ) ;
84
+ const [ invalidUser , setInvalidUser ] = useState ( false ) ;
85
+ const [ invalidPass , setInvalidPass ] = useState ( false ) ;
86
+
70
87
const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
71
88
let inputVal = e . target . value ;
72
89
switch ( e . target . name ) {
@@ -79,16 +96,47 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
79
96
}
80
97
} ;
81
98
99
+ /*
100
+ Response Options:
101
+ Success
102
+ Error
103
+ No Username Input
104
+ No Password Input
105
+ Incorrect Password
106
+ Invalid Username
107
+ */
82
108
const handleLogin = ( e : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => {
83
109
e . preventDefault ( ) ;
84
110
console . log ( 'click fired on handleLogin' ) ;
85
- sessionIsCreated ( username , password ) . then ( isLoggedIn => {
86
- if ( isLoggedIn ) {
87
- console . log ( 'session created' ) ;
111
+
112
+ setInvalidUser ( false ) ;
113
+ setInvalidUserMsg ( '' ) ;
114
+ setInvalidPass ( false ) ;
115
+ setInvalidPassMsg ( '' ) ;
116
+ sessionIsCreated ( username , password ) . then ( loginStatus => {
117
+ console . log ( 'login fetch' , loginStatus )
118
+ if ( loginStatus === 'Success' ) {
88
119
dispatch ( setLoginState ( ) ) ; // changes login state to true
89
120
props . history . push ( '/' ) ;
90
121
} else {
91
- console . log ( 'invalid login' ) ;
122
+ switch ( loginStatus ) {
123
+ case 'No Username Input' :
124
+ setInvalidUser ( true ) ;
125
+ setInvalidUserMsg ( loginStatus ) ;
126
+ break ;
127
+ case 'No Password Input' :
128
+ setInvalidPass ( true ) ;
129
+ setInvalidPassMsg ( loginStatus ) ;
130
+ break ;
131
+ case 'Invalid Username' :
132
+ setInvalidUser ( true ) ;
133
+ setInvalidUserMsg ( loginStatus ) ;
134
+ break ;
135
+ case 'Incorrect Password' :
136
+ setInvalidPass ( true ) ;
137
+ setInvalidPassMsg ( loginStatus ) ;
138
+ break ;
139
+ }
92
140
}
93
141
} ) ;
94
142
} ;
@@ -98,12 +146,13 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
98
146
< CssBaseline />
99
147
< div className = { classes . paper } >
100
148
< Avatar className = { classes . avatar } >
101
- < LockOutlinedIcon />
149
+ < LockOutlinedIcon />
102
150
</ Avatar >
103
- < Typography component = "h1" variant = "h5" >
151
+ < Typography component = "h1" variant = "h5" color = "textPrimary" >
104
152
Sign in
105
153
</ Typography >
106
154
< TextField
155
+ className = { classes . root }
107
156
variant = "outlined"
108
157
margin = "normal"
109
158
required
@@ -115,8 +164,11 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
115
164
autoFocus
116
165
value = { username }
117
166
onChange = { handleChange }
167
+ helperText = { invalidUserMsg }
168
+ error = { invalidUser }
118
169
/>
119
170
< TextField
171
+ className = { classes . root }
120
172
variant = "outlined"
121
173
margin = "normal"
122
174
required
@@ -128,6 +180,8 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
128
180
autoComplete = "current-password"
129
181
value = { password }
130
182
onChange = { handleChange }
183
+ helperText = { invalidPassMsg }
184
+ error = { invalidPass }
131
185
/>
132
186
< FormControlLabel
133
187
control = { < Checkbox value = "remember" color = "primary" /> }
@@ -137,22 +191,33 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
137
191
< Button
138
192
fullWidth
139
193
variant = "contained"
140
- color = "primary "
194
+ color = "default "
141
195
className = { classes . submit }
142
196
onClick = { e => handleLogin ( e ) }
143
197
>
144
198
Sign In
145
199
</ Button >
146
200
147
- < a href = "https://localhost:8080/github" >
201
+ < Button
202
+ fullWidth
203
+ variant = "contained"
204
+ color = "default"
205
+ className = { classes . submit }
206
+ href = "https://localhost:8080/github"
207
+ >
208
+ < GitHubIcon />
209
+ </ Button >
210
+
211
+ { /* <a href="https://localhost:8080/github">
148
212
<img src="/images/githublogin.png" />
149
213
</a>
150
- < br > </ br >
214
+ <br></br> */ }
151
215
< Grid container >
152
216
< Grid item xs >
153
- < Link href = "#" variant = "body2" >
217
+ { /* <Link href="#" variant="body2">
154
218
Forgot password?
155
- </ Link >
219
+ </Link> */ }
220
+ < RouteLink to = { `/signup` } className = "nav_link" > Forgot password?</ RouteLink >
156
221
</ Grid >
157
222
< Grid item >
158
223
< RouteLink to = { `/signup` } className = "nav_link" >
0 commit comments