|
|
@ -8,20 +8,17 @@ void UserMgrService::initialize() { |
|
|
|
GET_TO_SERVICE(m_db); |
|
|
|
GET_TO_SERVICE(m_deviceStateService); |
|
|
|
|
|
|
|
REG_EXTFN_VOID(login, void()); |
|
|
|
REG_EXTFN(login, void(string, string), uid, pwd); |
|
|
|
REG_EXTFN_VOID(unlogin, void()); |
|
|
|
REG_EXTFN_VOID(chpasswd, void()); |
|
|
|
REG_EXTFN_VOID(addUser, void()); |
|
|
|
REG_EXTFN_VOID(delUser, void()); |
|
|
|
REG_EXTFN_VOID(updateUserUid, void()); |
|
|
|
REG_EXTFN(chpasswd, void(string, string, string), uid, newpasswd, passwd); |
|
|
|
REG_EXTFN(addUser, void(string, string), uid, passwd); |
|
|
|
REG_EXTFN(delUser, void(int), id); |
|
|
|
REG_EXTFN(updateUserUid, void(int, string), id, uid); |
|
|
|
REG_EXTFN_VOID(getAllUser, void()); |
|
|
|
REG_EXTFN_VOID(getLoginUser, void()); |
|
|
|
}; |
|
|
|
|
|
|
|
void UserMgrService::login(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
string uid = cxt->cmd["params"]["uid"]; |
|
|
|
string pwd = cxt->cmd["params"]["passwd"]; |
|
|
|
|
|
|
|
void UserMgrService::login(shared_ptr<MsgProcessContext> cxt, string uid, string pwd) { |
|
|
|
// 超超级用户
|
|
|
|
if (uid == "admin" && pwd == "iflytop9973") { |
|
|
|
m_deviceStateService->setLoginState("admin", true); |
|
|
@ -46,10 +43,7 @@ void UserMgrService::unlogin(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
ADD_USER_BEHAVIOR(loginuid, kbehavior_logout, ""); |
|
|
|
return; |
|
|
|
} |
|
|
|
void UserMgrService::chpasswd(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
string uid = cxt->cmd["params"]["uid"]; |
|
|
|
string newpasswd = cxt->cmd["params"]["newpasswd"]; |
|
|
|
string passwd = cxt->cmd["params"]["passwd"]; |
|
|
|
void UserMgrService::chpasswd(shared_ptr<MsgProcessContext> cxt, string uid, string newpasswd, string passwd) { |
|
|
|
|
|
|
|
if (!m_deviceStateService->isLoginAdmin()) { |
|
|
|
APPCHECK(!m_db->ispasswdCorrect(uid, passwd), err::kappe_passwd_error, fmt::format("user {} passwd error", uid)); |
|
|
@ -58,20 +52,15 @@ void UserMgrService::chpasswd(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
logger->info("changet passwd {} {}", uid, passwd); |
|
|
|
auto user = m_db->changePasswd(uid, newpasswd); |
|
|
|
} |
|
|
|
void UserMgrService::addUser(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
string uid = cxt->cmd["params"]["uid"]; |
|
|
|
string passwd = cxt->cmd["params"]["passwd"]; |
|
|
|
void UserMgrService::addUser(shared_ptr<MsgProcessContext> cxt, string uid, string passwd) { |
|
|
|
m_db->addUser(uid, passwd); |
|
|
|
} |
|
|
|
void UserMgrService::delUser(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
int id = jsonGet<int>(cxt->cmd["params"]["id"]); |
|
|
|
void UserMgrService::delUser(shared_ptr<MsgProcessContext> cxt, int id) { |
|
|
|
auto user = m_db->delUser(id); |
|
|
|
APPCHECK(!user, err::kappe_user_not_exist, fmt::format("user {} not exist", id)); |
|
|
|
} |
|
|
|
|
|
|
|
void UserMgrService::updateUserUid(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
int id = jsonGet<int>(cxt->cmd["params"]["id"]); |
|
|
|
string uid = cxt->cmd["params"]["uid"]; |
|
|
|
void UserMgrService::updateUserUid(shared_ptr<MsgProcessContext> cxt, int id, string uid) { |
|
|
|
string olduid; |
|
|
|
auto user = m_db->updateUserUid(id, uid, olduid); |
|
|
|
APPCHECK(!user, err::kappe_user_not_exist, fmt::format("user {} not exist", id)); |
|
|
|