mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现HTTP服务架构
This commit is contained in:
@@ -15,8 +15,9 @@ std::shared_ptr<DaoEntity> DAO1::get(std::string tableName)
|
||||
return std::make_shared<DaoEntity>(tableName);
|
||||
}
|
||||
|
||||
Errcode DAO1::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string passwd, std::string& err)
|
||||
Errcode DAO1::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string passwd, Fields& fields)
|
||||
{
|
||||
std::string err;
|
||||
std::string t = Utils::timeStr();
|
||||
if (!dao)
|
||||
{
|
||||
@@ -29,23 +30,24 @@ Errcode DAO1::login(std::shared_ptr<DaoEntity> dao, std::string account, std::st
|
||||
return Errcode::ERR_DB_CONN;
|
||||
}
|
||||
|
||||
std::string sql = "SELECT * FROM user WHERE account='" + account + "';";
|
||||
std::string sql = "SELECT u.*, ur.role_id FROM `user` u"
|
||||
" LEFT JOIN user_role ur ON u.user_id = ur.user_id WHERE u.account=" + account + "';";
|
||||
|
||||
std::vector<Fields> res;
|
||||
bool ret = dao->exec(sql, res);
|
||||
std::vector<Fields> result;
|
||||
bool ret = dao->exec(sql, result);
|
||||
if (!ret)
|
||||
{
|
||||
err = "数据库操作错误";
|
||||
DAO1::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
return Errcode::ERR_DB_CONN;
|
||||
}
|
||||
if (res.size() <=0)
|
||||
if (result.size() <=0)
|
||||
{
|
||||
err = "用户不存在";
|
||||
DAO1::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
return Errcode::ERR_LOGIN_USER_NOTEXIST;
|
||||
}
|
||||
Fields& fields = res[0];
|
||||
fields = result[0];
|
||||
std::string userId = fields.value("user_id");
|
||||
int loginCount = fields.get<int>("login_count");
|
||||
|
||||
@@ -57,6 +59,15 @@ Errcode DAO1::login(std::shared_ptr<DaoEntity> dao, std::string account, std::st
|
||||
return Errcode::ERR_LOGIN_PASSWD;
|
||||
}
|
||||
|
||||
// 读取用户权限
|
||||
{
|
||||
result.clear();
|
||||
std::string sql = "SELECT rp.role_id, rp.permission_id, p.name FROM role_permission rp "
|
||||
"LEFT JOIN permission p ON p.permission_id = rp.permission_id"
|
||||
"WHERE rp.role_id = 1;";
|
||||
|
||||
}
|
||||
|
||||
err = "登录成功";
|
||||
|
||||
// 数据库更新用户登录信息
|
||||
|
||||
Reference in New Issue
Block a user