PhoneCheck_Cert.js
5.59 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
import React, { Component } from 'react';
import { View, Text, StyleSheet,TouchableOpacity } from 'react-native';
import CheckBox from '@react-native-community/checkbox'
import { TextInput } from 'react-native-gesture-handler';
export default class AddTab extends Component {
static navigationOptions = {
headerShown: false
}
state= {
all:false,
expired:false,
time:180,
intervalId:null,
data:null,
input:"",
phone_num:""
}
constructor(props) {
super(props)
}
componentDidMount() {
const phone_num = this.props.navigation.state.params.phone_num
if(this.props.navigation.state.params.data) {
this.setState({
data:this.props.navigation.state.params.data,
phone_num:phone_num
},() => console.log(this.state.data))
}
this.setState({
intervalId:setInterval(() => {
this.setState({
time:this.state.time-1
})
if(this.state.time ===0) {
this.setState({
expired:true
})
}
}, 1000)
})
}
componentWillUnmount() {
clearInterval(this.state.intervalId)
}
onHandlecheckBox= (type) => {
if(type == "SNS") {
if(this.state.SNS == true) {
this.setState({
SNS:false,
all:false,
})
}
else {
this.setState({
SNS:true
})
}
}
else if(type == "private_info") {
if(this.state.private_info == true) {
this.setState({
private_info:false,
all:false,
})
}
else {
this.setState({
private_info:true
})
}
}
else if(type == "profile_info") {
if(this.state.profile_info == true) {
this.setState({
profile_info:false,
all:false,
})
}
else {
this.setState({
profile_info:true
})
}
}
}
HandlePhoneNum = (e) => {
this.setState({
phone_num:e
})
}
HandleNavigate = () => {
if(this.state.expired === true) return alert("인증 시간이 만료되었습니다.")
if(this.state.data === parseInt(this.state.input)) {
this.props.navigation.replace("Signup",{phone:this.state.phone_num})
}
else {
alert("인증번호를 확인해주세요.")
}
}
GoFirst = () => {
this.props.navigation.goBack(null)
}
RequestAuthKey = () => {
post(`http://${SERVER}/auth/phone`,{phone_number:this.state.phone_num}).then(res => {
if(res.data.success) {
this.setState({
time:180,
expired:false,
data:res.data.data,
})
}
})
}
render() {
return (
<View style={{width:"100%",height:"100%",paddingLeft:"10%",paddingRight:"10%",paddingTop:"10%"}}>
<View>
<Text style={{color:"#615F5F",fontSize:15,textAlign:"center"}}>
{this.state.phone_num}로 전송받은 4자리
</Text>
<Text style={{color:"#615F5F",fontSize:15,textAlign:"center"}}>
인증번호를 입력해주세요.
</Text>
</View>
<View style={{flexDirection:"row",paddingTop:9,paddingBottom:9,marginTop:16,marginBottom:14}}>
<TextInput value={this.state.input} onChangeText={(e) => this.setState({input:e})} keyboardType="number-pad" placeholder={`${Math.floor(this.state.time/60)}:${this.state.time%60<10? "0"+this.state.time%60 :this.state.time%60}`}
style={{paddingTop:7,paddingBottom:11,width:"80%",paddingRight:16,textAlign:"right",fontSize:15,borderColor:"#FFD63A",borderWidth:1}}/>
<TouchableOpacity onPress={() => this.HandleNavigate()} style={{width:"20%",backgroundColor:"#FFD63A"}}>
<View style={{flex:1,justifyContent:"center"}}>
<Text style={{alignSelf:"center",fontSize:14,textAlign:"center"}}>
다음
</Text>
</View>
</TouchableOpacity>
</View>
<TouchableOpacity onPress={() => this.RequestAuthKey()} style={{alignSelf:"center"}}>
<Text style={{color:"#615F5F",paddingBottom:3,marginBottom:29,borderBottomColor:"#FFD63A",borderBottomWidth:1}}>
인증번호 다시 받기
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.GoFirst()} style={{alignSelf:"center"}}>
<Text style={{color:"#615F5F",paddingBottom:3,marginBottom:29,borderColor:"#615F5F",borderWidth:2,paddingBottom:6,paddingTop:7,paddingLeft:17,paddingRight:17}}>
처음으로 돌아가기
</Text>
</TouchableOpacity>
</View>
);
}
}
const style = StyleSheet.create({
container: {
}
});