Auth subsystem done
This commit is contained in:
parent
43aefada4c
commit
6fb0559ae5
3 changed files with 82 additions and 0 deletions
56
system/auth_system.cpp
Normal file
56
system/auth_system.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "auth_system.h"
|
||||
|
||||
|
||||
const user_entity& auth_system::get_user(const QString &login, bool &success) {
|
||||
user_entity *out;
|
||||
|
||||
success = false;
|
||||
for (user_entity &item : this->_users) {
|
||||
if (item.login() == login) {
|
||||
success = true;
|
||||
out = &item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *out;
|
||||
}
|
||||
|
||||
bool auth_system::remove_user(const QString &login) {
|
||||
auto vit = this->_users.begin();
|
||||
for (; vit != this->_users.end(); vit++) {
|
||||
if ((*vit).login() == login) {
|
||||
this->_users.erase(vit);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool auth_system::register_user(const QString &login, const QString &password, UserRole role) {
|
||||
bool exists = false;
|
||||
this->get_user(login, exists);
|
||||
if (!exists) {
|
||||
this->_users.push_back(user_entity(login, password, role));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void auth_system::init(QDataStream &stream) {
|
||||
int icnt;
|
||||
stream >> icnt;
|
||||
this->_users.resize(icnt);
|
||||
for (int i = 0; i < icnt; i++) {
|
||||
this->_users[i].deserialize(stream);
|
||||
}
|
||||
}
|
||||
|
||||
void auth_system::shutdown(QDataStream &stream) {
|
||||
stream << this->_users.size();
|
||||
for (auto &item : this->_users) {
|
||||
item.serialize(stream);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue