mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
完成系统管理web端功能,实现系统管理服务端接口,实现登录功能
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include "common/Utils.h"
|
||||
#include "common/Snowflake.h"
|
||||
|
||||
|
||||
|
||||
enum class EnDatabaseErr
|
||||
{
|
||||
SUCCESS = 0,
|
||||
@@ -13,7 +15,7 @@ std::shared_ptr<DaoEntity> DAO::get(std::string tableName)
|
||||
return std::make_shared<DaoEntity>(tableName);
|
||||
}
|
||||
|
||||
bool DAO::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string passwd, std::string& err)
|
||||
Errcode DAO::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string passwd, std::string& err)
|
||||
{
|
||||
std::string t = Utils::timeNowStr();
|
||||
if (!dao)
|
||||
@@ -24,7 +26,7 @@ bool DAO::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string
|
||||
{
|
||||
err = "数据库连接错误";
|
||||
DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
return false;
|
||||
return Errcode::ERR_DB_CONN;
|
||||
}
|
||||
|
||||
std::string sql = "SELECT * FROM user WHERE account='" + account + "';";
|
||||
@@ -35,24 +37,24 @@ bool DAO::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string
|
||||
{
|
||||
err = "数据库操作错误";
|
||||
DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
return false;
|
||||
return Errcode::ERR_DB_CONN;
|
||||
}
|
||||
if (res.size() <=0)
|
||||
{
|
||||
err = "用户不存在";
|
||||
DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
return false;
|
||||
return Errcode::ERR_LOGIN_USER_NOTEXIST;
|
||||
}
|
||||
DataFields& fields = res[0];
|
||||
std::string userId = fields.get_str("user_id");
|
||||
int loginCount = fields.get_int("login_count");
|
||||
std::string userId = fields.getStr("user_id");
|
||||
int loginCount = fields.getInt("login_count");
|
||||
|
||||
// 判断密码
|
||||
if (passwd != fields.get_str("passwd"))
|
||||
if (passwd != fields.getStr("passwd"))
|
||||
{
|
||||
err = "密码错误";
|
||||
DAO::writeSystemLog(dao, 2, userId, account, "用户登录失败:" + err);
|
||||
return false;
|
||||
return Errcode::ERR_LOGIN_PASSWD;
|
||||
}
|
||||
|
||||
err = "登录成功";
|
||||
@@ -66,7 +68,7 @@ bool DAO::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string
|
||||
}
|
||||
|
||||
DAO::writeSystemLog(dao, 2, userId, account, "用户登录成功");
|
||||
return true;
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
bool DAO::writeSystemLog(std::shared_ptr<DaoEntity> dao, int type, std::string userId, std::string account, std::string text)
|
||||
@@ -83,12 +85,12 @@ bool DAO::writeSystemLog(std::shared_ptr<DaoEntity> dao, int type, std::string u
|
||||
// 数据库写入登录日志
|
||||
dao->setTableName("system_log");
|
||||
DataFields fieldsLog;
|
||||
fieldsLog.set("id", Snowflake::instance().nextIdStr());
|
||||
fieldsLog.set("log_id", Snowflake::instance().getIdStr());
|
||||
fieldsLog.set("type", 2);
|
||||
fieldsLog.set("user_id", userId);
|
||||
fieldsLog.set("user_account", account);
|
||||
fieldsLog.set("content", text);
|
||||
fieldsLog.set("log_time", Utils::timeNowStr());
|
||||
fieldsLog.set("create_time", Utils::timeNowStr());
|
||||
bool ret = dao->insertFields({fieldsLog});
|
||||
return ret;
|
||||
}
|
||||
@@ -114,7 +116,7 @@ int DAO::insertUser(DataFields& fields)
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string account = fields.get_str("account");
|
||||
std::string account = fields.getStr("account");
|
||||
|
||||
// step1: 查询
|
||||
std::vector<DataFields> res;
|
||||
@@ -128,7 +130,7 @@ int DAO::insertUser(DataFields& fields)
|
||||
return 1;
|
||||
}
|
||||
|
||||
fields.set("user_id", Snowflake::instance().nextIdStr());
|
||||
fields.set("user_id", Snowflake::instance().getIdStr());
|
||||
fields.set("create_time", Utils::timeNowStr());
|
||||
ret = dao->insertFields(fields);
|
||||
return (ret) ? 0 : 1;
|
||||
|
||||
Reference in New Issue
Block a user