-
Notifications
You must be signed in to change notification settings - Fork 0
/
tddex1.dart
269 lines (242 loc) · 8.78 KB
/
tddex1.dart
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
import 'dart:io';
void main(){
MenuInit();
}
class MenuInit{
int menuIndex = 0;
List<List<String>> menuList = [];
bool loginTF = false;
String writeID = "";
String writePW = "";
String writeRole = "";
String userRole="";
late DateTime loginTime;
MenuInit(){
print("--------------------");
print("Starting...");
print("Dart TDD~. \nDart programing. Test Driven Development(TDD). Example.\nLet's make this. After Extract model, service on Flutter, app.\nI'm making it. Not complete yet.");
print("Github, https://github.com/infott2t/dartTddEx");
print("Fasting.");
initMenuList();
boot(menuIndex);
}
void boot(int menuIndex) {
String resultMenu = "";
print("--------------------");
if (menuList[menuIndex][2] == 'NumberQuestion') {
//munuList[menuIndex][1]의 값을 split해서 print하기.
//메뉴값을 저장.
List<String> menuList0 = menuList[menuIndex][1].split(',');
for (int i = 0; i < menuList[menuIndex][1]
.split(',')
.length; i++) {
print("${menuList[menuIndex][1].split(',')[i]}");
}
//값 입력받기, stdin
print("Enter a number corresponding to the menu options:");
int input = int.parse(stdin.readLineSync()!); // 숫자 입력 받기
resultMenu = menuList[menuIndex][0] + "," + menuList0[input - 1];
//menuList에서 cmdList[menuIndex][0]의 값과 resultMenu값이 일치하는 부분을 찾기.
// print(resultMenu);
int i = 0;
for (i = 0; i < menuList.length; i++) {
if (menuList[i][0] == resultMenu) {
menuIndex = i;
break;
}
}
boot(i);
}
else if (menuList[menuIndex][2] == "chkBool") {
//메뉴 출력.
print(menuList[menuIndex][1]);
//로그인 체크.
if (menuList[menuIndex][0] == "start,1.Login") {
//TODO - http, 로그인 확인 하고 값 저장하기.
// loginTF = http....
if (loginTF) {
resultMenu = menuList[menuIndex][0] + ",T";
print("TRUE");
} else {
resultMenu = menuList[menuIndex][0] + ",F";
print("FALSE");
}
} else if (menuList[menuIndex][0] ==
"start,1.Login,F,Y,writingID,writingPassword") {
//TODO - http, 로그인 확인하고 값 저장하기.
// loginTF = http....
print("---ID, $writeID");
String resultMenu = "";
if (loginTF) {
resultMenu = menuList[menuIndex][0] + ",T";
print("TRUE");
boot(0);
} else {
resultMenu = menuList[menuIndex][0] + ",F";
print("FALSE");
boot(0);
}
} else if (menuList[menuIndex][0] == "start,5.Regist,writingID,writingPassword,writingRole"){
//TODO - http, 회원가입 확인하고 값 저장하기.
// loginTF = http....
// 파일로 저장.
bool regist = saveFile(writeID, writePW, writeRole);
if(regist){
print("TRUE");
loginTF = true;
}else{
print("FALSE");
boot(0);
}
print("---ID, $writeID");
String resultMenu = "";
if (loginTF) {
resultMenu = menuList[menuIndex][0] + ",T";
print("TRUE");
boot(0);
} else {
resultMenu = menuList[menuIndex][0] + ",F";
print("FALSE");
boot(0);
}
}
//menuList에서 cmdList[menuIndex][0]의 값과 resultMenu값이 일치하는 부분을 찾기.
int i = 0;
for (i = 0; i < menuList.length; i++) {
if (menuList[i][0] == resultMenu) {
menuIndex = i;
//print(i);
break;
}
}
boot(i);
}
else if (menuList[menuIndex][2] == "YNQuestion") {
//메뉴출력.
print(menuList[menuIndex][1]);
//값 입력받기, stdin
print("Question, Y/N:");
String input = stdin.readLineSync()!; // Y/N 입력 받기.
if (input == "Y" || input == "y") {
resultMenu = menuList[menuIndex][0] + ",Y";
} else if (input == "N" || input == "n") {
resultMenu = menuList[menuIndex][0] + ",N";
} else {
boot(menuIndex);
}
//menuList에서 cmdList[menuIndex][0]의 값과 resultMenu값이 일치하는 부분을 찾기.
int i = 0;
for (i = 0; i < menuList.length; i++) {
if (menuList[i][0] == resultMenu) {
menuIndex = i;
//print(i);
break;
}
}
boot(i);
}
else if (menuList[menuIndex][2] == "StringQuestion") {
//메뉴출력.
print(menuList[menuIndex][1]);
//값 입력받기, stdin
print("String input:");
String input = stdin.readLineSync()!; // Y/N 입력 받기.
print(input);
if (input != null) {
if (menuList[menuIndex][0] == "start,1.Login,F,Y") {
writeID = input;
resultMenu = menuList[menuIndex][0] + ",writingID";
} else if (menuList[menuIndex][0] == "start,1.Login,F,Y,writingID") {
writePW = input;
resultMenu = menuList[menuIndex][0] + ",writingPassword";
}else if(menuList[menuIndex][0] == "start,5.Regist"){
writeID = input;
resultMenu = menuList[menuIndex][0] + ",writingID";
}else if(menuList[menuIndex][0] == "start,5.Regist,writingID") {
writePW = input;
resultMenu = menuList[menuIndex][0] + ",writingPassword";
}else if(menuList[menuIndex][0] == "start,5.Regist,writingID,writingPassword") {
writeRole= input;
if(writeRole == "admin") {
resultMenu = menuList[menuIndex][0] + ",writingRole";
}else if(writeRole == "user") {
resultMenu = menuList[menuIndex][0] + ",writingRole";
}else{
boot(menuIndex);
}
}
}
//menuList에서 cmdList[menuIndex][0]의 값과 resultMenu값이 일치하는 부분을 찾기.
int i = 0;
for (i = 0; i < menuList.length; i++) {
if (menuList[i][0] == resultMenu) {
menuIndex = i;
//print(i);
break;
}
}
boot(i);
} else if(menuList[menuIndex][2] =="InitMenu"){
//메뉴출력.
print(menuList[menuIndex][1]);
boot(0);
}
else if (menuList[menuIndex][0] == "start,4.Status") {
print("Status");
if (loginTF) {
print("ID : $writeID");
print("User Role : $userRole");
} else {
print("No Login.");
}
boot(0);
}
}
void initMenuList() {
menuList.add(['start','1.Login,2.Logout,3.Service,4.Status,5.Regist,6.Exit','NumberQuestion']);
menuList.add(['start,1.Login','Check login...','chkBool']);
menuList.add(['start,1.Login,T','Activated.','InitMenu']);
menuList.add(['start,1.Login,F','Not Activated. \nLogin?[Y/N]','YNQuestion']);
menuList.add(['start,1.Login,F,Y','Login..., input ID. ','StringQuestion']);
menuList.add(['start,1.Login,F,Y,writingID','Login input Password.','StringQuestion']);
menuList.add(['start,1.Login,F,Y,writingID,writingPassword','Login input Password.','chkBool']);
menuList.add(['start,1.Login,F,Y,writingID,writingPassword,chkBool','Check login...','chkBool']);
menuList.add(['start,1.Login,F,N','No login. ','InitMenu']);
menuList.add(['start,4.Status','Status...','PrintStatus']);
menuList.add(['start,5.Regist','Regist...ID:','StringQuestion']);
menuList.add(['start,5.Regist,writingID','Regist...PW:','StringQuestion']);
menuList.add(['start,5.Regist,writingID,writingPassword','Regist...Role: admin, user','StringQuestion']);
menuList.add(['start,5.Regist,writingID,writingPassword,writingRole','Regist...','chkBool']);
}
bool saveFile(String writeID, String writePW, String writeRole) {
bool resultSaveTF = false;
//ID와 암호를 파일로 저장.
//login.txt파일이 있는지 확인.
if (File('login.txt').existsSync()) {
print("login.txt file is exist.");
//login.txt파일이 있으면, 파일을 읽어서, ID가 있는지 확인.
File file = File('login.txt');
String fileContent = file.readAsStringSync();
List<String> fileContentList = fileContent.split('|');
bool existID= false;
for (int i = 0; i < fileContentList.length; i++) {
List<String> fileContentList2 = fileContentList[i].split(',');
if (fileContentList2[0] == writeID) {
print("ID is exist.");
//ID가 있으므로, resultSaveTF = false;
existID = true;
break;
}
}
if(!existID){
//ID가 없으므로, resultSaveTF = true;
print("ID is not exist.");
resultSaveTF = true;
//ID와 암호를 파일에 저장.
file.writeAsStringSync('$writeID,$writePW,$writeRole|', mode: FileMode.append);
userRole = writeRole;
}
}
return resultSaveTF;
}
}