瀏覽代碼

/User/GetLoginID:GetLoginAccountByMobile2 通过手机号码查询登录账号信息(三方认证表 userauthinfo)

deng.yinping 1 年之前
父節點
當前提交
fd92134e68
共有 2 個文件被更改,包括 46 次插入7 次删除
  1. 22 7
      controllers/user/login.go
  2. 24 0
      models/account.go

+ 22 - 7
controllers/user/login.go

@@ -1,3 +1,11 @@
+/*
+ * @Author: deng.yinping deng.yinping@muchinfo.cn
+ * @Date: 2024-02-22 11:11:03
+ * @LastEditors: deng.yinping deng.yinping@muchinfo.cn
+ * @LastEditTime: 2024-04-17 14:52:08
+ * @FilePath: \MTP20_IF\controllers\user\login.go
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ */
 package user
 
 import (
@@ -42,14 +50,21 @@ func GetLoginID(c *gin.Context) {
 		return
 	}
 
-	// 通过LoginAccount表手机号码查询登录账号
-	if loginaccount, _ := models.GetLoginAccount2(req.UserName); loginaccount != nil {
-		appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
-		return
-	}
+	// // 通过LoginAccount表手机号码查询登录账号
+	// if loginaccount, _ := models.GetLoginAccount2(req.UserName); loginaccount != nil {
+	// 	appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
+	// 	return
+	// }
+
+	// // 通过UserInfo表手机号码查询登录账号
+	// if loginaccount, _ := models.GetLoginAccountByMobile(req.UserName); loginaccount != nil {
+	// 	appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
+	// 	return
+	// }
 
-	// 通过UserInfo表手机号码查询登录账号
-	if loginaccount, _ := models.GetLoginAccountByMobile(req.UserName); loginaccount != nil {
+	// 根据登录账号与手机号绑定表获取登录账号(上面两个查询不正确 20240417)
+	// GetLoginAccountByMobile2 通过手机号码查询登录账号信息(三方认证表 userauthinfo)
+	if loginaccount, _ := models.GetLoginAccountByMobile2(req.UserName); loginaccount != nil {
 		appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
 		return
 	}

+ 24 - 0
models/account.go

@@ -583,6 +583,30 @@ func GetLoginAccountByLoginCode(loginCode string) (*Loginaccount, error) {
 	return nil, nil
 }
 
+// GetLoginAccountByMobile2 通过手机号码查询登录账号信息(三方认证表 userauthinfo)
+func GetLoginAccountByMobile2(mobile string) (*Loginaccount, error) {
+	engine := db.GetEngine()
+
+	var loginaccount Loginaccount
+	var has bool
+	// 手机号码需要AES加密
+	key, _ := hex.DecodeString(utils.AESSecretKey)
+	if mobileEncrypted, err := utils.AESEncrypt([]byte(mobile), key); err == nil {
+		// 加密成功后进行查询
+		has, err = engine.Join("INNER", "USERAUTHINFO", "USERAUTHINFO.LOGINID = LOGINACCOUNT.LOGINID").
+			Where("USERAUTHINFO.AUTHID = ?", hex.EncodeToString(mobileEncrypted)).Get(&loginaccount)
+		if err != nil {
+			return nil, err
+		}
+	}
+
+	if has {
+		return &loginaccount, nil
+	}
+
+	return nil, nil
+}
+
 // GetLoginAccountByMobile 通过手机号码查询登录账号信息
 func GetLoginAccountByMobile(mobile string) (*Loginaccount, error) {
 	engine := db.GetEngine()