diff --git a/uappbase/service/gstate_mgr.cpp b/uappbase/service/gstate_mgr.cpp index 466fbc7..bd19f2b 100644 --- a/uappbase/service/gstate_mgr.cpp +++ b/uappbase/service/gstate_mgr.cpp @@ -12,11 +12,12 @@ void GStateMgr::initialize() { m_mutex.init(); } /*********************************************************************************************************************** * USER * ***********************************************************************************************************************/ -void GStateMgr::setLogin(const char* usrName, user_role_t role) { +void GStateMgr::setLogin(int loginUsrId, const char* usrName, user_role_t role) { zlock_guard l(m_mutex); m_loginUsrType = role; m_isLogin = true; strncpy(this->m_loginUsr, usrName, MAX_USR_NAME_SIZE); + m_loginUsrId = loginUsrId; } void GStateMgr::setUnLogin() { zlock_guard l(m_mutex); @@ -38,6 +39,11 @@ const char* GStateMgr::getLoginUsr() { return m_loginUsr; } +int GStateMgr::getUserId() { + zlock_guard l(m_mutex); + return m_loginUsrId; +} + // void GStateMgr::setAcidState(int32_t state) { diff --git a/uappbase/service/gstate_mgr.hpp b/uappbase/service/gstate_mgr.hpp index 6b30903..35103fb 100644 --- a/uappbase/service/gstate_mgr.hpp +++ b/uappbase/service/gstate_mgr.hpp @@ -15,6 +15,7 @@ class GStateMgr { private: /* data */ char m_loginUsr[MAX_USR_NAME_SIZE + 1]; + int m_loginUsrId = -1; user_role_t m_loginUsrType = kuser; bool m_isLogin = false; @@ -41,12 +42,13 @@ class GStateMgr { void initialize(); // loginUsrState - void setLogin(const char* usrName, user_role_t role); + void setLogin(int loginUsrId, const char* usrName, user_role_t role); void setUnLogin(); bool isLogin(); user_role_t getLoginUsrType(); const char* getLoginUsr(); + int getUserId(); // void setAcidState(int32_t state); diff --git a/usrc/service/app_core.cpp b/usrc/service/app_core.cpp index 8967350..78c14a7 100644 --- a/usrc/service/app_core.cpp +++ b/usrc/service/app_core.cpp @@ -97,7 +97,9 @@ void AppCore::initialize() { ZLOGI(TAG, "load zhdb end"); UIControler::ins()->initialize(); - UIControler::ins()->chpage(pg_muAcidType,true); + + GStateMgr::ins()->setLogin(0, "admin", kadmin); + UIControler::ins()->chpage(pg_muChangePasswd, true); osDelay(1000); // UIControler::ins()->popWarningWin("警告!!!!!!!"); diff --git a/usrc/uicontroler/page/login_page.cpp b/usrc/uicontroler/page/login_page.cpp index 4ea1092..2d030f9 100644 --- a/usrc/uicontroler/page/login_page.cpp +++ b/usrc/uicontroler/page/login_page.cpp @@ -25,12 +25,12 @@ class LoginPage : public IPageProcesser { virtual void onInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) override { if (bid == ob_login_uName) { UIS->setTxt(thisPage, ob_login_uName, text); // - strcpy(userName, text); // + strcpy(userName, text); // UIS->setTxt(thisPage, ob_login_pwdEMsg, ""); // UIS->setTxt(thisPage, ob_login_uNameEMsg, ""); // } else if (bid == ob_login_pwd) { UIS->setTxt(thisPage, ob_login_pwd, text); // - strcpy(passwd, text); // + strcpy(passwd, text); // UIS->setTxt(thisPage, ob_login_pwdEMsg, ""); // UIS->setTxt(thisPage, ob_login_pwdEMsg, ""); // } @@ -48,10 +48,11 @@ class LoginPage : public IPageProcesser { return; } - ZLOGI(TAG, "login %s success", userName); + ZLOGI(TAG, "login %s(%d) role:%d", userName, user->id, user->role); + GStateMgr::ins()->setLogin(user->id, userName, (user_role_t)user->role); AppEventBus::ins()->pushSimpleEvent(kAE_LoginEvent); - UIControler::ins()->chpage(pg_home,true); + UIControler::ins()->chpage(pg_home, true); resetPage(); } } diff --git a/usrc/uicontroler/page/mupage/muChangePasswd_page.cpp b/usrc/uicontroler/page/mupage/muChangePasswd_page.cpp new file mode 100644 index 0000000..5642d72 --- /dev/null +++ b/usrc/uicontroler/page/mupage/muChangePasswd_page.cpp @@ -0,0 +1,151 @@ + +#include "db/dao/user_dao.hpp" +#include "uappbase/apphal/apphal.hpp" +#include "ui/ui.h" +#include "uicontroler/base/page_processer.hpp" +// +#include "db/dao/acid_ch_cfg_dao.hpp" +#include "db/dao/device_setting_dao.hpp" +// +#include "service/pump_ctrl_service.hpp" + +namespace iflytop { +using namespace std; +#define TAG "MuChangePasswdPage" + +static char pwd[20] = {0}; +static char newPwd[20] = {0}; +static char cfirmPwd[20] = {0}; + +class MuChangePasswdPage : public IPageProcesser { + private: + public: + MuChangePasswdPage() : IPageProcesser(TAG, pg_muChangePasswd) {} + + virtual void initialize() override { + IPageProcesser::initialize(); + setText(ob_muChangePasswd_pwd, ""); + setText(ob_muChangePasswd_pwdEMsg, ""); + setText(ob_muChangePasswd_newPwd, ""); + setText(ob_muChangePasswd_newPwdMsg, ""); + setText(ob_muChangePasswd_cfirmPwd, ""); + setText(ob_muChangePasswd_cfirmPwdMsg, ""); + } + + private: + virtual void onPageLoad(OnPageLoadContext* cxt) override { return; }; + /** + * @brief 返回上一页 + */ + virtual void onBackKey() override { + setText(ob_muChangePasswd_pwd, ""); + setText(ob_muChangePasswd_pwdEMsg, ""); + setText(ob_muChangePasswd_newPwd, ""); + setText(ob_muChangePasswd_newPwdMsg, ""); + setText(ob_muChangePasswd_cfirmPwd, ""); + setText(ob_muChangePasswd_cfirmPwdMsg, ""); + + memset(pwd, 0, sizeof(pwd)); + memset(newPwd, 0, sizeof(newPwd)); + memset(cfirmPwd, 0, sizeof(cfirmPwd)); + + UIControler::ins()->chpage(pg_navi, true); + }; + + virtual void onChangePageEvent() override {}; + virtual void onInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) override { + if (bid == ob_muChangePasswd_pwd) { + setText(ob_muChangePasswd_pwd, text); + strcpy(pwd, text); + } else if (bid == ob_muChangePasswd_newPwd) { + setText(ob_muChangePasswd_newPwd, text); + strcpy(newPwd, text); + } else if (bid == ob_muChangePasswd_cfirmPwd) { + setText(ob_muChangePasswd_cfirmPwd, text); + strcpy(cfirmPwd, text); + } + + if (!GStateMgr::ins()->isLogin()) { + UIS->popWarningWin("请先登录"); + return; + } + user_t* user = UserDao::getUserById(GStateMgr::ins()->getUserId()); + if (user == nullptr) { + ZLOGW(TAG, "can not find user by id:%d", GStateMgr::ins()->getUserId()); + UIS->popWarningWin("用户不存在"); + return; + } + + setText(ob_muChangePasswd_pwdEMsg, ""); + setText(ob_muChangePasswd_newPwdMsg, ""); + setText(ob_muChangePasswd_cfirmPwdMsg, ""); + + if (strcmp(pwd, user->passwd) != 0) { + setText(ob_muChangePasswd_pwdEMsg, "密码错误"); + return; + } + + if (strlen(newPwd) != 0 && strlen(newPwd) < 6) { + setText(ob_muChangePasswd_newPwdMsg, "密码长度不能小于6"); + return; + } + + if (strlen(cfirmPwd) != 0) { + if (strcmp(newPwd, cfirmPwd) != 0) { + setText(ob_muChangePasswd_cfirmPwdMsg, "两次密码不一致"); + return; + } + } + }; + + virtual void onClickRelease(uint8_t bid, uint8_t val, const char* text) override { + if (bid == ob_muChangePasswd_pwd) { + popPasswdKeyBoard(ob_muChangePasswd_pwd, 6); + } else if (bid == ob_muChangePasswd_newPwd) { + popPasswdKeyBoard(ob_muChangePasswd_newPwd, 6); + } else if (bid == ob_muChangePasswd_cfirmPwd) { + popPasswdKeyBoard(ob_muChangePasswd_cfirmPwd, 6); + } + if (bid == ob_muChangePasswd_save) { + updateUser(); + } + } + + void updateUser() { + if (!GStateMgr::ins()->isLogin()) { + UIS->popWarningWin("请先登录"); + return; + } + + user_t* user = UserDao::getUserById(GStateMgr::ins()->getUserId()); + if (user == nullptr) { + ZLOGW(TAG, "can not find user by id:%d", GStateMgr::ins()->getUserId()); + UIS->popWarningWin("用户不存在"); + return; + } + + if (strcmp(pwd, user->passwd) != 0) { + UIS->popWarningWin("密码错误"); + return; + } + + if (strlen(newPwd) != 6) { + UIS->popWarningWin("密码长度需要等于6"); + return; + } + + if (strlen(cfirmPwd) != 0) { + if (strcmp(newPwd, cfirmPwd) != 0) { + UIS->popWarningWin("两次密码不一致"); + return; + } + } + + UserDao::updateUser(user->id, user->name, newPwd, GStateMgr::ins()->getLoginUsrType()); + UIS->popInfoWin("修改成功"); + } +}; + +// 实例化Page, 使其自动注册 +static MuChangePasswdPage instance; +} // namespace iflytop