From 809c0deaa2da7e6148d83ca7586e36771e90e5e1 Mon Sep 17 00:00:00 2001 From: 474420502 <474420502@qq.com> Date: Thu, 11 Apr 2024 18:04:03 +0800 Subject: [PATCH] =?UTF-8?q?TODO:=20fix=20module=20name=20=E6=97=A0?= =?UTF-8?q?=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/killara_customer_device_log_logic.go | 4 + model/killara_customer_device_logic.go | 4 + server/app/internal/handlers/actions/auth.go | 126 +++++++++++++++++- .../internal/handlers/actions/types_gen.go | 23 ++-- 4 files changed, 141 insertions(+), 16 deletions(-) diff --git a/model/killara_customer_device_log_logic.go b/model/killara_customer_device_log_logic.go index 26d1c14..f5357bb 100644 --- a/model/killara_customer_device_log_logic.go +++ b/model/killara_customer_device_log_logic.go @@ -9,3 +9,7 @@ type KillaraCustomerDeviceLogModel struct { db *gorm.DB TableName string // 表名 } + +func (m *KillaraCustomerModel) InsertCustomerDeviceLog(logData *KillaraCustomerDeviceLog) error { + return m.db.Model(&KillaraCustomerDeviceLog{}).Create(logData).Error +} diff --git a/model/killara_customer_device_logic.go b/model/killara_customer_device_logic.go index 03370cb..3c5aabc 100644 --- a/model/killara_customer_device_logic.go +++ b/model/killara_customer_device_logic.go @@ -9,3 +9,7 @@ type KillaraCustomerDeviceModel struct { db *gorm.DB TableName string // 表名 } + +func (m *KillaraCustomerModel) InsertCustomerDevice(deviceData *KillaraCustomerDevice) error { + return m.db.Model(&KillaraCustomerDevice{}).Create(deviceData).Error +} diff --git a/server/app/internal/handlers/actions/auth.go b/server/app/internal/handlers/actions/auth.go index ca1d8e2..59e7101 100644 --- a/server/app/internal/handlers/actions/auth.go +++ b/server/app/internal/handlers/actions/auth.go @@ -1,7 +1,10 @@ package actions import ( + "strings" + "github.com/gin-gonic/gin" + "github.com/iapologizewhenimwrong/Vestmore_GO/model" "github.com/iapologizewhenimwrong/Vestmore_GO/utils/auth" "github.com/iapologizewhenimwrong/Vestmore_GO/utils/basic" "github.com/iapologizewhenimwrong/Vestmore_GO/utils/email" @@ -25,18 +28,127 @@ func BaseGetToken(ctx *gin.Context, param *BaseGetTokenParam, resp *basic.Respon // @Action account/loginWithTelephonePassword // AccountLoginWithTelephonePassword -// action: string; -// country_code: string; -// device?: string; -// lang: string; -// password: string; +// randstr: string; +// sign: string; // telephone: string; -// token?: string; -// version?: string; +// version: string;.0.14 +// token: string; +// country_code: string; 86 +// password: string; +// action: string; +// device: string;,12 +// app_market: uint64; +// email: string; +// timestamp: int64; func AccountLoginWithTelephonePassword(ctx *gin.Context, param *AccountLoginWithTelephonePasswordParam, resp *basic.Response) { // ctx.ShouldBind() // model.Models.KillaraCustomerModel.Find() + if param.CountryCode == "" { + resp.ErrorEx(1, "country_code 参数缺失") + return + + } + if param.Telephone == "" { + resp.ErrorEx(1, "telephone 参数缺失") + return + } + + if param.Password == "" { + resp.ErrorEx(1, "password 参数缺失") + return + } + + telephone := strings.TrimSpace(param.Telephone) + password := strings.TrimSpace(param.Password) + countryCode := strings.TrimSpace(param.CountryCode) + + // 假设 modelCustomer 和 modelCustomerToken 是对应的服务接口 + + var customer *model.KillaraCustomer + var err error + + customer, err = model.Models.KillaraCustomerModel.GetCustomerByTelephoneForBackEnd(telephone) + if err != nil { + resp.ErrorEx(1, err.Error()) + return + } + if customer == nil { + customer, err = model.Models.KillaraCustomerModel.GetCustomerByCode(telephone) + if err != nil { + resp.ErrorEx(1, err.Error()) + return + } + } + + if customer == nil { + resp.ErrorEx(1, "账号未注册") + return + } + + if *customer.CountryCode != countryCode { + resp.ErrorEx(1, "电话号码国家不正确") + return + } + + if *customer.Status != 1 { + resp.ErrorEx(1, "账号已禁用,无法登录") + return + } + + if !auth.CheckPassword(*customer.Password, *customer.Salt, *customer.RandomPassword, password) { + resp.ErrorEx(1, "账号或密码错误") + return + } + + customerID := *customer.CustomerId + + err = model.Models.KillaraCustomerTokenModel.UpdateTokenCustomerID(param.Token, customerID) + if err != nil { + resp.ErrorEx(1, err.Error()) + return + } + + var deviceCode string + if param.Device != "" { + deviceCode = param.Device + } + + var version string + if param.Version != "" { + version = param.Version + } + + var ip string + addr := strings.Split(ctx.Request.RemoteAddr, ":") + if len(addr) > 0 { + ip = addr[0] + } + + log.Println(deviceCode, version, ip) + + // data := model.KillaraCustomerDevice{ + // CustomerId: &customerID, + // Device: &deviceCode, + // Version: &version, + // Ip: &ip, + // AppMarket: ¶m., + // Date: time.Now().Format("2006-01-02 15:04:05"), + // } + + // // 假设 insertCustomerDevice 是对应的服务接口 + // insertCustomerDevice(data) + + // // 假设 clearDuplicateToken 是对应的服务接口 + // clearDuplicateToken(customerID, param.Token) + + // return map[string]interface{}{ + // "success": true, + // "error_code": 0, + // "error_text": "", + // "data": make(map[string]interface{}), + // }, nil + // log.Println(param) } diff --git a/server/app/internal/handlers/actions/types_gen.go b/server/app/internal/handlers/actions/types_gen.go index 3a1cac5..af08965 100644 --- a/server/app/internal/handlers/actions/types_gen.go +++ b/server/app/internal/handlers/actions/types_gen.go @@ -1,9 +1,10 @@ package actions import ( + "/utils/basic" + "/utils/log" + "github.com/gin-gonic/gin" - "github.com/iapologizewhenimwrong/Vestmore_GO/utils/basic" - "github.com/iapologizewhenimwrong/Vestmore_GO/utils/log" ) var HandlersFuncRoutes map[string]gin.HandlerFunc = make(map[string]gin.HandlerFunc) @@ -76,14 +77,18 @@ func AccountLoginWithEmailPasswordHandler(ctx *gin.Context) { } type AccountLoginWithTelephonePasswordParam struct { - Action string `json:"action" form:"action" binding:"-"` - CountryCode string `json:"country_code" form:"country_code" binding:"-"` - Device string `json:"device" form:"device" binding:"required"` - Lang string `json:"lang" form:"lang" binding:"-"` - Password string `json:"password" form:"password" binding:"-"` + Randstr string `json:"randstr" form:"randstr" binding:"-"` + Sign string `json:"sign" form:"sign" binding:"-"` Telephone string `json:"telephone" form:"telephone" binding:"-"` - Token string `json:"token" form:"token" binding:"required"` - Version string `json:"version" form:"version" binding:"required"` + Version string `json:"version" form:"version" binding:"-"` + Token string `json:"token" form:"token" binding:"-"` + CountryCode string `json:"country_code" form:"country_code" binding:"-"` + Password string `json:"password" form:"password" binding:"-"` + Action string `json:"action" form:"action" binding:"-"` + Device string `json:"device" form:"device" binding:"-"` + AppMarket uint64 `json:"app_market" form:"app_market" binding:"-"` + Email string `json:"email" form:"email" binding:"-"` + Timestamp int64 `json:"timestamp" form:"timestamp" binding:"-"` } func AccountLoginWithTelephonePasswordHandler(ctx *gin.Context) {