-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathAuthForm.js
More file actions
351 lines (312 loc) · 9.79 KB
/
AuthForm.js
File metadata and controls
351 lines (312 loc) · 9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
import logo200Image from 'assets/img/logo/hive-logo.png';
import PropTypes from 'prop-types';
import React from 'react';
import { Button, Form, FormGroup, Input, Label, UncontrolledAlert } from 'reactstrap';
class AuthForm extends React.Component {
constructor(props){
super(props);
this.state={
username:'',
password:'',
validateLoginStatus: '',
validateLoginResponse:{},
fullname:'',
doctorname:'',
doctorid: '',
patientid:'',
deviceid:''
}
}
get isLogin() {
return this.props.authState === STATE_LOGIN;
}
get isSignup() {
return this.props.authState === STATE_SIGNUP;
}
changeAuthState = authState => event => {
event.preventDefault();
// {console.log("uerma",this.state.username)}
this.props.onChangeAuthState(authState);
};
handleSubmit = event => {
event.preventDefault();
if(this.props.authState=='LOGIN'){
console.log("The username:", this.props.username);
console.log("Inside login function");
fetch('https://spc89vwj89.execute-api.us-west-1.amazonaws.com/Production', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
pathParameters:{
username: this.state.username,
password: this.state.password,
}
})
})
.then(response => response.json())
.then(response => {
this.setState({
validateLoginResponse: response
})
this.state.validateLoginStatus = this.state.validateLoginResponse.statusCode;
if(this.state.validateLoginStatus==200){
console.log("inside 200");
this.props.history.push('/');
}
else{
// alert(this.state.username + 'is not a valid username!');
}
})
.catch(err => { console.log(err);
});
}else if(this.props.authState=='SIGNUP'){
console.log("Inside Registration function");
fetch('https://j982ampfu3.execute-api.us-west-1.amazonaws.com/Production/insert', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
User_Id : `USERNAME#${this.state.username}`,
Device_Id: `DEVICE#${this.state.deviceid}`,
User_Password: this.state.password,
User_Fullname: this.state.fullname,
Doctor_Name: this.state.doctorname,
Doctor_Id: this.state.doctorid,
Patient_Id: this.state.patientid
})
})
.then(response => response.json())
.then(response => {
this.setState({
validateLoginResponse: response
})
this.state.validateLoginStatus = this.state.validateLoginResponse.statusCode;
if(this.state.validateLoginStatus==200){
console.log("inside 200");
this.props.history.push('/');
}
else{
// alert(this.state.username + 'is not a valid username!');
}
})
.catch(err => { console.log(err);
});
}
};
renderButtonText() {
const { buttonText } = this.props;
if (!buttonText && this.isLogin) {
return 'Login';
}
if (!buttonText && this.isSignup) {
return 'Signup';
}
return buttonText;
}
render() {
const {
showLogo,
usernameLabel,
usernameInputProps,
passwordLabel,
passwordInputProps,
confirmPasswordLabel,
confirmPasswordInputProps,
children,
onLogoClick,
FullNameLabel,
FullNameInputProps,
DoctorNameLabel,
DoctorNameInputProps,
DoctorIdLabel,
DoctorIdInputProps,
PatientIdLabel,
PatienIdInputProps,
DeviceIdLabel,
DeviceIdInputProps
} = this.props;
console.log("The props:", this.props)
console.log("121The username:", this.props.username);
return (
<Form onSubmit={this.handleSubmit}>
{showLogo && (
<div className="text-center pb-4">
<img
src={logo200Image}
className="rounded"
style={{ width: 60, height: 60, cursor: 'pointer' }}
alt="logo"
onClick={onLogoClick}
/>
</div>
)}
<FormGroup>
<Label for={usernameLabel}>{usernameLabel}</Label>
<Input onChange={e => {
usernameInputProps.inputvalue = e.target.value
this.setState({ username: e.target.value })}} {...usernameInputProps} />
</FormGroup>
<FormGroup>
<Label for={passwordLabel}>{passwordLabel}</Label>
<Input onChange={e =>{
passwordInputProps.inputvalue = e.target.value
this.setState({ password: e.target.value })}} {...passwordInputProps } />
</FormGroup>
{this.isSignup && (
<>
<FormGroup>
<Label for={confirmPasswordLabel}>{confirmPasswordLabel}</Label>
<Input {...confirmPasswordInputProps} />
</FormGroup>
<FormGroup>
<Label for={FullNameLabel}>{FullNameLabel}</Label>
<Input onChange={e => {
FullNameInputProps.inputvalue = e.target.value
this.setState({ fullname: e.target.value })}} {...FullNameInputProps} />
</FormGroup>
<FormGroup>
<Label for={DoctorNameLabel}>{DoctorNameLabel}</Label>
<Input onChange={e => {
DoctorNameInputProps.inputvalue = e.target.value
this.setState({ doctorname: e.target.value })}} {...DoctorNameInputProps} />
</FormGroup>
<FormGroup>
<Label for={DoctorIdLabel}>{DoctorIdLabel}</Label>
<Input onChange={e => {
DoctorIdInputProps.inputvalue = e.target.value
this.setState({ doctorid: e.target.value })}} {...DoctorIdInputProps} />
</FormGroup>
<FormGroup>
<Label for={PatientIdLabel}>{PatientIdLabel}</Label>
<Input onChange={e => {
PatienIdInputProps.inputvalue = e.target.value
this.setState({ patientid: e.target.value })}}
{...PatienIdInputProps} />
</FormGroup>
<FormGroup>
<Label for={DeviceIdLabel}>{DeviceIdLabel}</Label>
<Input onChange={e => {
DeviceIdInputProps.inputvalue = e.target.value
this.setState({ deviceid: e.target.value })}} {...DeviceIdInputProps} />
</FormGroup>
</>
)}
<FormGroup check>
<Label check>
<Input type="checkbox" />{' '}
{this.isSignup ? 'Agree the terms and policy' : 'Remember me'}
</Label>
</FormGroup>
{this.state.validateLoginStatus==500 ? (
<UncontrolledAlert color="secondary">Invalid Login! User is not registered! </UncontrolledAlert>
) : null }
<hr />
<Button
size="lg"
className="bg-gradient-theme-left border-0"
block
onClick={this.handleSubmit}>
{this.renderButtonText()}
</Button>
<div className="text-center pt-1">
<h6>or</h6>
<h6>
{this.isSignup ? (
<a href="#login" onClick={this.changeAuthState(STATE_LOGIN)}>
Login
</a>
) : (
<a href="#signup" onClick={this.changeAuthState(STATE_SIGNUP)}>
Signup
</a>
)}
</h6>
</div>
{children}
</Form>
);
}
}
// export const validationStatus = this.props.validateLoginStatus;
export const STATE_LOGIN = 'LOGIN';
export const STATE_SIGNUP = 'SIGNUP';
AuthForm.propTypes = {
authState: PropTypes.oneOf([STATE_LOGIN, STATE_SIGNUP]).isRequired,
showLogo: PropTypes.bool,
usernameLabel: PropTypes.string,
usernameInputProps: PropTypes.object,
passwordLabel: PropTypes.string,
passwordInputProps: PropTypes.object,
confirmPasswordLabel: PropTypes.string,
confirmPasswordInputProps: PropTypes.object,
onLogoClick: PropTypes.func,
FullNameLabel: PropTypes.string,
FullNameInputProps: PropTypes.object,
DoctorNameLabel: PropTypes.string,
DoctorNameInputProps: PropTypes.object,
DoctorIdLabel: PropTypes.string,
DoctorIdInputProps: PropTypes.object,
PatientIdLabel: PropTypes.string,
PatienIdInputProps: PropTypes.object,
DeviceIdLabel: PropTypes.string,
DeviceIdInputProps: PropTypes.object,
};
AuthForm.defaultProps = {
authState: 'LOGIN',
showLogo: true,
usernameLabel: 'Username',
usernameInputProps: {
type: 'string',
placeholder: 'your username',
inputvalue: ''
},
passwordLabel: 'Password',
passwordInputProps: {
type: 'password',
placeholder: 'your password',
inputvalue: ''
},
confirmPasswordLabel: 'Confirm Password',
confirmPasswordInputProps: {
type: 'password',
placeholder: 'confirm your password',
inputvalue: ''
},
FullNameLabel: 'Patient Full Name',
FullNameInputProps: {
type: 'string',
placeholder: 'Your full name',
inputvalue: ''
},
DoctorNameLabel: 'Doctor Name',
DoctorNameInputProps: {
type: 'string',
placeholder: 'Doctors name',
inputvalue: ''
},
DoctorIdLabel: 'Doctor ID',
DoctorIdInputProps: {
type: 'string',
placeholder: 'Doctors ID',
inputvalue: ''
},
PatientIdLabel: 'Patient ID',
PatienIdInputProps: {
type: 'string',
placeholder: 'Patient ID',
inputvalue: ''
},
DeviceIdLabel: 'HIVE Device ID',
DeviceIdInputProps: {
type: 'string',
placeholder: 'HIVE device ID',
inputvalue: ''
},
onLogoClick: () => {},
};
export default AuthForm;