去除单机模式对redis中间件的依赖
This commit is contained in:
1 parent
2e665471fe
commit
3966606689
21 files changed
+433
-334
No files matched your search
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"hk4e/common/config"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -92,29 +93,35 @@ func (c *Controller) apiLogin(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
account, err := c.db.QueryAccountByField("username", username)
|
||||
account, err := c.db.QuerySdkAccountByField("username", username)
|
||||
if err != nil {
|
||||
logger.Error("query account from db error: %v", err)
|
||||
return
|
||||
}
|
||||
if account == nil {
|
||||
// 自动注册
|
||||
accountId, err := c.db.GetNextAccountId()
|
||||
if err != nil {
|
||||
logger.Error("get next account id error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-1"
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
accountId := uint32(0)
|
||||
if !config.GetConfig().Hk4e.StandaloneModeEnable {
|
||||
accountId, err = c.db.GetNextSdkAccountId()
|
||||
if err != nil {
|
||||
logger.Error("get next account id error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-1"
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.nextSdkAccountId++
|
||||
accountId = c.nextSdkAccountId
|
||||
}
|
||||
regAccount := &model.Account{
|
||||
regAccount := &model.SdkAccount{
|
||||
AccountId: accountId,
|
||||
Username: username,
|
||||
Password: endec.Md5Str(password),
|
||||
Token: "",
|
||||
ComboToken: "",
|
||||
}
|
||||
_, err = c.db.InsertAccount(regAccount)
|
||||
_, err = c.db.InsertSdkAccount(regAccount)
|
||||
if err != nil {
|
||||
logger.Error("insert account error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
@@ -132,7 +139,7 @@ func (c *Controller) apiLogin(ctx *gin.Context) {
|
||||
}
|
||||
// 生成新的token
|
||||
account.Token = base64.StdEncoding.EncodeToString(random.GetRandomByte(24))
|
||||
_, err = c.db.UpdateAccountFieldByFieldName("account_id", account.AccountId, "token", account.Token)
|
||||
_, err = c.db.UpdateSdkAccountFieldByFieldName("account_id", account.AccountId, "token", account.Token)
|
||||
if err != nil {
|
||||
logger.Error("update account token error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
@@ -140,7 +147,7 @@ func (c *Controller) apiLogin(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.db.UpdateAccountFieldByFieldName("account_id", account.AccountId, "token_create_time", time.Now().UnixMilli())
|
||||
_, err = c.db.UpdateSdkAccountFieldByFieldName("account_id", account.AccountId, "token_create_time", time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
logger.Error("update account token time error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
@@ -167,7 +174,7 @@ func (c *Controller) apiVerify(ctx *gin.Context) {
|
||||
logger.Error("parse uid error: %v", err)
|
||||
return
|
||||
}
|
||||
account, err := c.db.QueryAccountByField("account_id", uid)
|
||||
account, err := c.db.QuerySdkAccountByField("account_id", uid)
|
||||
if err != nil {
|
||||
logger.Error("query account from db error: %v", err)
|
||||
return
|
||||
@@ -216,7 +223,7 @@ func (c *Controller) v2Login(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
responseData := api.NewComboTokenRsp()
|
||||
account, err := c.db.QueryAccountByField("account_id", uid)
|
||||
account, err := c.db.QuerySdkAccountByField("account_id", uid)
|
||||
if account == nil || account.Token != loginData.Token {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "token错误"
|
||||
@@ -225,7 +232,7 @@ func (c *Controller) v2Login(ctx *gin.Context) {
|
||||
}
|
||||
// 生成新的comboToken
|
||||
account.ComboToken = random.GetRandomByteHexStr(20)
|
||||
_, err = c.db.UpdateAccountFieldByFieldName("account_id", account.AccountId, "combo_token", account.ComboToken)
|
||||
_, err = c.db.UpdateSdkAccountFieldByFieldName("account_id", account.AccountId, "combo_token", account.ComboToken)
|
||||
if err != nil {
|
||||
logger.Error("update combo token error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
@@ -233,7 +240,7 @@ func (c *Controller) v2Login(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.db.UpdateAccountFieldByFieldName("account_id", account.AccountId, "combo_token_create_time", time.Now().UnixMilli())
|
||||
_, err = c.db.UpdateSdkAccountFieldByFieldName("account_id", account.AccountId, "combo_token_create_time", time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
logger.Error("update combo token time error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
|
||||
Reference in new issue
Block a user