This repository was archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathSignIn.js
More file actions
138 lines (134 loc) · 3.5 KB
/
SignIn.js
File metadata and controls
138 lines (134 loc) · 3.5 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
import React from 'react'
import { css } from 'glamor'
import { Auth } from 'aws-amplify'
import UserContext from './UserContext'
class SignIn extends React.Component {
state = {
username: '',
password: '',
showConfirmation: false,
user: {},
authCode: ''
}
static contextType = UserContext
onChange = (key, value) => {
this.props.updateErrorMessage(null)
this.setState({
[key]: value
})
}
signIn = () => {
const { history } = this.props
const { updateCurrentUser } = this.context
Auth.signIn(this.state.username, this.state.password)
.then(user => {
if (!user.signInUserSession) {
this.setState({ user, showConfirmation: true })
} else {
updateCurrentUser(user)
history.push('/profile')
}
})
.catch(err => {
console.log('error signing in...: ', err)
this.props.updateErrorMessage(err.message)
})
}
confirmSignIn = () => {
const { history } = this.props
Auth.confirmSignIn(this.state.user, this.state.authCode, this.state.user.challengeName)
.then(user => {
history.push('/')
})
.catch(err => console.log('error confirming signing in...: ', err))
}
render() {
return (
<div {...css(styles.container)}>
{
!this.state.showConfirmation && (
<div {...css(styles.formContainer)}>
<input
onChange={evt => this.onChange('username', evt.target.value)}
{...css(styles.input)}
placeholder='ユーザー名'
/>
<input
type='password'
onChange={evt => this.onChange('password', evt.target.value)}
{...css(styles.input)}
placeholder='パスワード'
/>
<div {...css(styles.button)} onClick={this.signIn}>
<p {...css(styles.buttonText)}>ログイン</p>
</div>
</div>
)
}
{
this.state.showConfirmation && (
<div {...css(styles.formContainer)}>
<h2 {...css(styles.signInHeader)}>Sign In</h2>
<input
onChange={evt => this.onChange('authCode', evt.target.value)}
{...css(styles.input)}
placeholder='認証コード'
/>
<div {...css(styles.button)} onClick={this.confirmSignIn.bind(this)}>
<p {...css(styles.buttonText)}>ログイン</p>
</div>
</div>
)
}
</div>
)
}
}
const styles = {
signInHeader: {
textAlign: 'left',
margin: '0px 0px 20px'
},
button: {
padding: '10px 60px',
backgroundColor: '#ffb102',
marginTop: 10,
marginBottom: 10,
cursor: 'pointer',
borderRadius: '30px',
':hover': {
backgroundColor: '#ffbb22'
}
},
buttonText: {
margin: 0,
color: 'white'
},
input: {
height: 40,
marginBottom: '10px',
border: 'none',
outline: 'none',
borderBottom: '2px solid #ffb102',
fontSize: '16px',
'::placeholder': {
color: 'rgba(0, 0, 0, .3)'
}
},
container: {
flex: 1,
paddingTop: '15px',
display: 'flex',
flexDirection: 'column',
alignItems: 'center'
},
formContainer: {
padding: 20,
width: 400,
display: 'flex',
flexDirection: 'column',
boxShadow: "0px 0px 2px rgba(0, 0, 0, .2)",
borderRadius: 20
}
}
export default SignIn