diff --git a/README.md b/README.md index 095d336..4b4170d 100644 --- a/README.md +++ b/README.md @@ -84,4 +84,10 @@ TODO: +``` +``` +TODO文档: + getLoginUser + + ``` \ No newline at end of file diff --git a/appsrc/baseservice/db/db_service.cpp b/appsrc/baseservice/db/db_service.cpp index 60898b1..609c5ab 100644 --- a/appsrc/baseservice/db/db_service.cpp +++ b/appsrc/baseservice/db/db_service.cpp @@ -184,6 +184,23 @@ json DBService::getAllUserJson() { return j_users; } +json DBService::getUserJson(string uid) { + lock_guard lock(lock_); + + auto usertable = make_storage(USER_DB_STRUCT); + usertable.sync_schema(); + auto user = usertable.get_all(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 DBService::getUser(string uid) { lock_guard lock(lock_); diff --git a/appsrc/baseservice/db/db_service.hpp b/appsrc/baseservice/db/db_service.hpp index 0bd9052..8beeaae 100644 --- a/appsrc/baseservice/db/db_service.hpp +++ b/appsrc/baseservice/db/db_service.hpp @@ -86,6 +86,7 @@ class DBService : public enable_shared_from_this { *******************************************************************************/ list> getAllUser(); json getAllUserJson(); + json getUserJson(string uid); shared_ptr getUser(string uid); vector getUserNames(); bool isUserExist(string uid); diff --git a/appsrc/service/device_state_service_ext.cpp b/appsrc/service/device_state_service_ext.cpp new file mode 100644 index 0000000..e69de29 diff --git a/appsrc/service/device_state_service_ext.hpp b/appsrc/service/device_state_service_ext.hpp new file mode 100644 index 0000000..eb83820 --- /dev/null +++ b/appsrc/service/device_state_service_ext.hpp @@ -0,0 +1,37 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#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 { + THISCLASS(DeviceStateServiceExt); + + public: + DeviceStateServiceExt(); + void initialize(); + + private: + void getState(shared_ptr cxt); +}; +} // namespace iflytop diff --git a/appsrc/service/user_mgr_service.cpp b/appsrc/service/user_mgr_service.cpp index a57dc70..85f279e 100644 --- a/appsrc/service/user_mgr_service.cpp +++ b/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 cxt) { @@ -79,4 +80,17 @@ void UserMgrService::getAllUser(shared_ptr cxt) { auto users = m_db->getAllUserJson(); cxt->receipt["content"] = users; return; -} \ No newline at end of file +} + +void UserMgrService::getLoginUser(shared_ptr 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; +} diff --git a/appsrc/service/user_mgr_service.hpp b/appsrc/service/user_mgr_service.hpp index 1747b12..8f0dd7e 100644 --- a/appsrc/service/user_mgr_service.hpp +++ b/appsrc/service/user_mgr_service.hpp @@ -29,6 +29,7 @@ class UserMgrService : public enable_shared_from_this { void delUser(shared_ptr cxt); void updateUserUid(shared_ptr cxt); void getAllUser(shared_ptr cxt); + void getLoginUser(shared_ptr cxt); }; } // namespace iflytop