Browse Source

添加接口 getLoginUser

storage-in-realtime
zhaohe 12 months ago
parent
commit
fc61af48e6
  1. 6
      README.md
  2. 17
      appsrc/baseservice/db/db_service.cpp
  3. 1
      appsrc/baseservice/db/db_service.hpp
  4. 0
      appsrc/service/device_state_service_ext.cpp
  5. 37
      appsrc/service/device_state_service_ext.hpp
  6. 16
      appsrc/service/user_mgr_service.cpp
  7. 1
      appsrc/service/user_mgr_service.hpp

6
README.md

@ -84,4 +84,10 @@ TODO:
```
```
TODO文档:
getLoginUser
```

17
appsrc/baseservice/db/db_service.cpp

@ -184,6 +184,23 @@ json DBService::getAllUserJson() {
return j_users;
}
json DBService::getUserJson(string uid) {
lock_guard<recursive_mutex> lock(lock_);
auto usertable = make_storage(USER_DB_STRUCT);
usertable.sync_schema();
auto user = usertable.get_all<User>(where(c(&User::uid) == uid));
if (user.size() == 0) {
return json();
}
json j_user;
j_user["id"] = user[0].id;
j_user["uid"] = user[0].uid;
j_user["passwd"] = user[0].passwd;
j_user["is_admin"] = user[0].is_admin;
return j_user;
}
shared_ptr<User> DBService::getUser(string uid) {
lock_guard<recursive_mutex> lock(lock_);

1
appsrc/baseservice/db/db_service.hpp

@ -86,6 +86,7 @@ class DBService : public enable_shared_from_this<DBService> {
*******************************************************************************/
list<shared_ptr<db::User>> getAllUser();
json getAllUserJson();
json getUserJson(string uid);
shared_ptr<db::User> getUser(string uid);
vector<string> getUserNames();
bool isUserExist(string uid);

0
appsrc/service/device_state_service_ext.cpp

37
appsrc/service/device_state_service_ext.hpp

@ -0,0 +1,37 @@
#pragma once
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
//
#include "appbase/appbase.hpp"
#include "appsetting/appsetting.hpp"
#include "baseservice/baseservice.hpp"
#include "iflytop/core/components/zcsv/zcsv.hpp"
namespace iflytop {
/**
* @brief
* getState中包含
*
*
*/
class DeviceStateServiceExt : public enable_shared_from_this<DeviceStateServiceExt> {
THISCLASS(DeviceStateServiceExt);
public:
DeviceStateServiceExt();
void initialize();
private:
void getState(shared_ptr<MsgProcessContext> cxt);
};
} // namespace iflytop

16
appsrc/service/user_mgr_service.cpp

@ -15,6 +15,7 @@ void UserMgrService::initialize() {
REGFN(UserMgrService, delUser);
REGFN(UserMgrService, updateUserUid);
REGFN(UserMgrService, getAllUser);
REGFN(UserMgrService, getLoginUser);
};
void UserMgrService::login(shared_ptr<MsgProcessContext> cxt) {
@ -79,4 +80,17 @@ void UserMgrService::getAllUser(shared_ptr<MsgProcessContext> cxt) {
auto users = m_db->getAllUserJson();
cxt->receipt["content"] = users;
return;
}
}
void UserMgrService::getLoginUser(shared_ptr<MsgProcessContext> cxt) {
string loginuid = m_deviceStateService->getLoginUid();
bool isLogin = m_deviceStateService->isLogin();
cxt->receipt["content"]["isLogin"] = isLogin;
if (isLogin) {
cxt->receipt["content"]["loginUser"] = m_db->getUserJson(loginuid);
} else {
cxt->receipt["content"]["loginUser"] = {};
}
return;
}

1
appsrc/service/user_mgr_service.hpp

@ -29,6 +29,7 @@ class UserMgrService : public enable_shared_from_this<UserMgrService> {
void delUser(shared_ptr<MsgProcessContext> cxt);
void updateUserUid(shared_ptr<MsgProcessContext> cxt);
void getAllUser(shared_ptr<MsgProcessContext> cxt);
void getLoginUser(shared_ptr<MsgProcessContext> cxt);
};
} // namespace iflytop
Loading…
Cancel
Save