-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
166 lines (160 loc) · 4.27 KB
/
App.tsx
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
import {
View,
Text,
StyleSheet,
TextInput,
TouchableOpacity,
ScrollView,
} from "react-native";
import { DarkModeButton } from "./components/Buttons";
import { useEffect, useState } from "react";
import { login, logout } from "./utils/puwifi";
export default function App() {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [darkMode, setDarkMode] = useState(true);
const [output, setOutput] = useState([]);
const [creds, setCreds] = useState([
{ username: "200303124278", password: "bf@44" },
{ username: "200303124264", password: "bf@66" },
{ username: "200303124199", password: "cf@52" },
]);
const toggleDarkMode = () => {
setDarkMode((prevDarkMode) => !prevDarkMode);
};
const handleOutput = (text: string) => {
setOutput((prevOutput) => [...prevOutput, text]);
};
function loginWithRandomCreds() {
const credsOf = Math.floor(Math.random() * creds.length);
const username = creds[credsOf].username;
const password = creds[credsOf].password;
login(username, password, handleOutput);
}
// useEffect(() => {
// username && password && login(username, password, handleOutput);
// });
useEffect(() => {
let timerId;
if (username && password) {
// Clear any existing timer
if (timerId) {
clearTimeout(timerId);
}
// Set a new timer to execute the login after 4 seconds
timerId = setTimeout(() => {
login(username, password, handleOutput);
}, 4000); // 4 seconds in milliseconds
}
// Cleanup the timer when the component unmounts or when dependencies change
return () => {
if (timerId) {
clearTimeout(timerId);
}
};
});
return (
<View
style={[
styles.container,
{ backgroundColor: darkMode ? "black" : "white" },
]}>
<Text style={{ color: "#aada99", fontSize: 40 }}>PuReLogger</Text>
<DarkModeButton toggleDarkMode={toggleDarkMode} />
<TextInput
placeholder="Username:"
value={username}
inputMode="text"
style={styles.textInput}
onChangeText={(e) => setUsername(e)}
/>
<TextInput
placeholder="Password:"
inputMode="text"
value={password}
style={styles.textInput}
onChangeText={(e) => setPassword(e)}
/>
<TouchableOpacity
style={[styles.button]}
onPress={() => {
login(username, password, handleOutput);
}}>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
logout(username, handleOutput);
}}>
<Text style={styles.buttonText}>Logout</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.button, { width: 250 }]}
onPress={loginWithRandomCreds}>
<Text style={[styles.buttonText, { fontSize: 15 }]}>
Login Using Random Credentials
</Text>
</TouchableOpacity>
<View style={styles.container}>
<ScrollView
ref={(ref) => {
this.scrollView = ref;
}}
onContentSizeChange={() =>
this.scrollView.scrollToEnd({ animated: true })
}>
{output.map((value, index) => {
return (
<Text style={styles.output} key={index}>
{value}
</Text>
);
})}
</ScrollView>
</View>
</View>
);
}
const styles = StyleSheet.create({
authButtons: {
flexDirection: "row",
},
button: {
justifyContent: "center",
backgroundColor: "#aada99",
alignContent: "center",
marginVertical: 10,
marginHorizontal: 10,
height: 50,
width: 120,
borderRadius: 5,
},
container: {
paddingTop: 100,
flex: 1,
alignItems: "center",
justifyContent: "center",
},
textInput: {
color: "black",
borderRadius: 10,
marginVertical: 10,
backgroundColor: "#aada99",
height: 50,
textAlign: "left",
paddingHorizontal: 20,
width: 200,
},
buttonText: {
color: "black",
fontSize: 20,
textAlign: "center",
paddingHorizontal: 5,
paddingVertical: 3,
},
output: {
color: "#aada99",
fontWeight: "bold",
},
});