upd: write userdatabase

This commit is contained in:
2023-12-13 09:30:38 +00:00
parent d117759d38
commit fe1a1ceece
2 changed files with 47 additions and 1 deletions

View File

@ -30,7 +30,7 @@ class BookDataBase {
void QueryBook(const std::string &ISBN, const std::string &name,
const std::string &author, const std::string &keyword,
std::vector<BookItemClass> &ret);
void ModifyInfo(const std::string &ISBN, const std::string &name,
void ModifyInfo(const std::string &ISBN,const std::string &new_ISBN, const std::string &name,
const std::string &author, const std::string &keyword,
double price);
};

View File

@ -13,4 +13,50 @@ void BookDataBase::Open(std::string file_name) {
void LogDataBase::Open(std::string file_name) {
finance_data.OpenFile(file_name + ".finance");
operation_log_data.OpenFile(file_name + ".log");
}
bool UserDataBase::PAM(const std::string &user_id,
const std::string &password) {
auto ret = user_name2index.Find(user_id);
if (ret.size() != 1) return false;
UserItemClass tmp;
full_user_data.read(tmp, ret[0]);
return tmp.password == password;
}
int UserDataBase::GetPrevilege(const std::string &user_id) {
auto ret = user_name2index.Find(user_id);
if (ret.size() != 1) return -1;
UserItemClass tmp;
full_user_data.read(tmp, ret[0]);
return tmp.privilege;
}
void UserDataBase::AddUser(const std::string &user_id,
const std::string &password,
const std::string &user_name, int privilege) {
UserItemClass tmp;
strcpy(tmp.user_id, user_id.c_str());
strcpy(tmp.password, password.c_str());
strcpy(tmp.user_name, user_name.c_str());
tmp.privilege = privilege;
int idx = full_user_data.write(tmp);
user_name2index.Insert(user_id, idx);
}
void UserDataBase::DeleteUser(const std::string &user_id) {
auto ret = user_name2index.Find(user_id);
if (ret.size() != 1) return;
full_user_data.Delete(ret[0]);
user_name2index.Delete(user_id, ret[0]);
}
void UserDataBase::ChangePassword(const std::string &user_id,
const std::string &password) {
auto ret = user_name2index.Find(user_id);
if (ret.size() != 1) return;
UserItemClass tmp;
full_user_data.read(tmp, ret[0]);
strcpy(tmp.password, password.c_str());
full_user_data.update(tmp, ret[0]);
}