-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin.cpp
More file actions
86 lines (79 loc) · 1.59 KB
/
Admin.cpp
File metadata and controls
86 lines (79 loc) · 1.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
#include "Admin.h"
using namespace std;
Admin::Admin(Init_Admin& admin_list)
{
ID = admin_list.id;
Password = admin_list.password;
Name = admin_list.name;
Group = admin_list.group;
}
Admin::~Admin()
{
}
bool Admin::login(int ID)
{
extern Admin* present_admin;
string temp_password;
// 如果是当前ID,就判断密码并返回true
if (ID == this->ID)
{
cout << "请输入密码:"<<endl;
temp_password = get_password('*');
cout << endl;
if (temp_password == this->Password)
{
cout << "欢迎" << Name << "进入系统" << endl;
present_admin = this;
return true;
}
else
{
cout << "密码错误,请重试" << endl;
return false;
}
}
else
{
return false;
}
}
void Admin::save_file()
{
extern vector<Admin>Admins;
ofstream admin_file("Admin.txt");
if (admin_file.is_open())
{
for (User temp_admin : Admins)
{
temp_admin.save(admin_file);
}
}
else
{
cout << "打开文件失败" << endl;
}
admin_file.close();
}
void Admin::load_file()
{
extern vector<Admin>Admins;
ifstream user_file("Admin.txt");
if (user_file.is_open())
{
while (!user_file.eof())
{
Admin temp_user;
temp_user.read(user_file);
if (temp_user.ID<0)
{
continue;
}
Admins.push_back(temp_user);
}
user_file.close();
}
else
{
cout << "打开文件失败" << endl;
}
}