-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
188 lines (144 loc) · 4.65 KB
/
Main.java
File metadata and controls
188 lines (144 loc) · 4.65 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
import java.io.*;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import javax.swing.JOptionPane;
public class Main implements Serializable {
static transient Scanner scan = new Scanner(System.in);
HashMap<String, String> userMap = new HashMap<String, String>();
HashMap<String, PersonManager> pmMap = new HashMap<String, PersonManager>();
private String loginId = "";
User user;
PersonManager pm;
String filePath = "C:\\Project";
String userFilesPath = "C:\\Project\\User";
Main() {
user = new User();
loadUserList();
loadPersonEventList();
}
void signIn() { // 회원가입시 아이디와 패스워드를 받는다
System.out.println("아이디와 패스워드를 입력하세요.");
while (true) {
String userId = JOptionPane.showInputDialog("본인 이메일로 가입하세요 \n아이디: ");
user = new User();
user.setId(userId);
String passWord = JOptionPane.showInputDialog("8자리 이상 영문자와 숫자로 만드세요. \n패스워드 : ");
user.setPassword(passWord);
if (!user.valID(user.getId())) {
System.out.println("형식에 맞지 않는 아이디입니다. 다시 입력하세요.");
} else if (userMap.containsKey(user.getId())) {
System.out.println("이미 존재하는 아이디입니다.");
} else if (!user.valPassword(user.getPassword())) {
System.out.println("형식에 맞지 않는 패스 워드입니다. 다시 입력하세요.");
} else {
userMap.put(user.getId(), user.getPassword());
pmMap.put(userId, new PersonManager());
loginId = userId;
saveUserList(); // 리스트 저장
savePersonEventList(); // User Path에 파일 생성
System.out.println("회원가입이 완료되었습니다.");
break;
}
}
}
String logIn() {
System.out.println("아이디와 패스워드를 입력하세요.");
while (true) {
System.out.print("아이디 : ");
String inputId = scan.nextLine();
System.out.print("패스워드 : ");
String inputPassword = scan.nextLine();
if (!userMap.containsKey(inputId)) {
System.out.println("존재하지 않는 회원입니다.");
} else if (!userMap.get(inputId).equals(inputPassword)) {
System.out.println("비밀번호가 일치하지 않습니다.");
} else {
System.out.println("로그인 되었습니다.");
loginId = inputId;
loadPersonEventList();
return loginId;
}
}
}
void logOut() {
saveUserList(); // 리스트 저장
savePersonEventList();
// 로그 아웃 할 시 유저, 퍼슨 매니져 해쉬맵 파일 저장...
}
void setPassword() {
System.out.println("변경할 비밀번호를 입력하세요");
String password = scan.nextLine();
if (!user.valPassword(password)) {
System.out.println("형식에 맞지 않는 비밀번호입니다. 비밀번호를 다시 설정하세요!");
} else {
userMap.put(loginId, password);
//saveUserList();
System.out.println("변경되었습니다");
}
}
public String getLoginId() {
return loginId;
}
void saveUserList() { // 회원 리스트만 출력 하면서~ 저장
File file = new File("User.ser");
File dir = new File(userFilesPath);
try {
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream fos = new FileOutputStream(filePath + "\\" + file, false);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(userMap);
oos.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("회원 정보가 저장되었습니다.");
}
}
void loadUserList() {
File file = new File("User.ser");
try {
userMap = new HashMap<String, String>();
FileInputStream fis = new FileInputStream(filePath + "\\" + file);
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
userMap = (HashMap) ois.readObject();
ois.close();
fis.close();
} catch (Exception e) {
}
Set set = userMap.entrySet();
Iterator iterator = set.iterator();
}
void savePersonEventList() {
File file = new File(loginId + ".ser");
try {
FileOutputStream fos = new FileOutputStream(userFilesPath + "\\" + file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(pmMap);
oos.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("저장되었습니다.");
}
}
void loadPersonEventList() {
File file = new File(loginId + ".ser");
try {
FileInputStream fis = new FileInputStream(userFilesPath + "\\" + file);
ObjectInputStream ois = new ObjectInputStream(fis);
pmMap = (HashMap) ois.readObject();
ois.close();
fis.close();
} catch (Exception e) {
}
}
}